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...

  • Incognito Psytrancer

    Super - puper!

  • Incognito Psytrancer

    Thank You! It's better than lighttpd. Tell me, do you plan to write a manual installation mysql + phpmyadmin on the router under Debian? Or it does not differ from the standard procedure to install on any Debian?

    • Use any tutorial related to debian, you only need to add services name from /opt/debian/etc/init.d/* to /opt/etc/chroot-services-list to start with S99debian script

SoftEther VPN Running on AsusWRT Routers
Minidlna UPnP Media Server through Debian Jessie Arm
How to Mount Samba Shares inside Chrooted Debian
Nginx Web Server with PHP Support through Optware-NG
Minidlna UPnP Media Server through Debian Jessie Arm
How to Mount Samba Shares inside Chrooted Debian
Spreed WebRTC server and web client
Asterisk VoIP Server running on AsusWRT Routers
SoftEther VPN Running on AsusWRT Routers
NZBGet through Entware
Minidlna UPnP Media Server through Debian Jessie Arm
NetData System Monitor Entware

SUBSCRIBE

To be notified by email when a new tutorial is posted :)

Thanks for Subscribing! I'll keeping you up-to-date with latest tutorials!

Something went wrong, try again...