Nginx Web Server with PHP Support through Optware-NG

1 - Install Optware-NG from here

2 - Install nginx and php

ipkg install nano nginx php php-fcgi

3 - Backup default configuration file

mv /opt/etc/nginx/nginx.conf /opt/etc/nginx/nginx.conf-orig

4 - Create nginx configuration file, copy/paste in terminal:

cat >> /opt/etc/nginx/nginx.conf << 'EOF'
user nobody;
worker_processes 1;
events {
worker_connections 64;
}
http {
include mime.types;
default_type application/octet-stream;
server {
listen 82;
server_name localhost;
location / {
root /opt/share/nginx/html;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /opt/share/nginx/50x.html {
root html;
}
location ~ \.php$ {
root /opt/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
EOF

Press Enter

5 - Create php-fcgi startup script

cat >> /opt/etc/init.d/S80php-fcgi << 'EOF'
#!/bin/sh
ENABLED=yes
PROCS=php-fcgi
ARGS="-b 127.0.0.1:9000"
PREARGS="/usr/bin/env PHP_FCGI_CHILDREN=2 PHP_FCGI_MAX_REQUESTS=1000"
DESC=$PROCS
PATH=/opt/sbin:/opt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
. /opt/etc/init.d/rc.func
EOF

Press Enter

6 - Make script executable

chmod +x /opt/etc/init.d/S80php-fcgi

7 - Start server

/opt/etc/init.d/S80nginx start
/opt/etc/init.d/S80php-fcgi start

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

 

9 - Create php info page:

cat >> /opt/share/nginx/html/info.php << 'EOF'
<?php
phpinfo();
?>
EOF

Press Enter

10 - Go to 192.168.1.1:82/info.php and if you see this page, php is configured correctly

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.


Enjoy...

Thanks @mercury for source

  • Alexos

    after restarting fcgi it worked now. Don't ask me what was wrong there....
    Thanks!

  • Alexos

    Hi, I was able to install the same via entware. Welcome page works fine but I can't get the phpinfo to work! Always get
    "No input file specified." but also nothing in the logs. Did not change any path or something. Permissions look ok all the way to /opt/share/nginx/html/info.php, all have execute permissions.
    Any idea?

    • TeHashX

      Clear browser cache or try another browser

      • Alexos

        Hi, ok I could figure out that the doc root is also set in /opt/etc/php.ini at setting "doc_root". after change fast cgi need a restart.

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