Nginx Web Server with PHP Support through Debian

1a - For Arm devices setup Debian from here

1b - For Mipsel devices setup Debian from here

2 - Enter Chrooted Debian

debian enter

3 - Update Debian

apt-get update
apt-get upgrade

4 - Install necessary packages

apt-get install bzip2 nginx php5 php5-fpm

- Replace default configuration file

rm /etc/nginx/sites-available/default
nano /etc/nginx/sites-available/default

Paste this lines

 server {
        listen 82; ## listen for ipv4; this line is default and implied
        listen [::]:82 default_server ipv6only=on; ## listen for ipv6

        root /usr/share/nginx/html;
        index index.html index.htm;

        # Make site accessible from http://localhost/
        server_name localhost;
        # pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
        location ~ .php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        }

        location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        allow ::1;
        deny all;
        } 
}

Save with CTRL-O, press ENTER and exit nano with CTRL-X

6 - Reduce memory limit

sed -i 's/memory_limit = 128M/memory_limit = 16M/g' "/etc/php5/fpm/php.ini"

7 - Restart server

service php5-fpm restart
service nginx restart

8 - Go to 192.168.1.1:82 and if you see this page, the nginx web server is configured correctly

 

nginx-homepage

9 - Create php info page

nano /usr/share/nginx/html/info.php

Paste this lines

<?php
phpinfo();
?>

Save with CTRL-O, press ENTER and exit nano with CTRL-X
10 - Go to 192.168.1.1:82/info.php and if you see this page, php is configured correctly

nginx-php
11 - To create startup script we need to exit debian

exit

12- Add nginx to chrooted services list

echo "nginx" >>/opt/etc/chroot-services.list
echo "php5-fpm" >>/opt/etc/chroot-services.list

13 - Start nginx from outside debian together with mounted external folder

debian restart

ACCESS THE WEBSITE FROM WAN

nano /jffs/scripts/firewall-start

Paste this lines

#!/bin/sh
iptables -I INPUT -p tcp --destination-port 82 -j ACCEPT

Save with CTRL-O / Enter / and exit with CTRL-X
Make script executable and apply rule
chmod a+rx /jffs/scripts/firewall-start
sh /jffs/scripts/firewall-start

Go to Port Forwarding page http://192.168.1.1/Advanced_VirtualServer_Content.asp and redirect port 80 to 82, now you should have access from wan.

nginx-pf
Enjoy...

REVIEW (CLICK ON THE STARS TO RATE!)
4.5
Sending
User Review
5 (1 vote)