Nginx Web Server with PHP Support through Entware

1 - Install Entware from here

2 - Update entware

opkg update
opkg upgrade

3 - Install nginx and php

opkg install nginx php7-cgi

4 - Backup default configuration file

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

5 - 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;
include /opt/etc/nginx/sites-enabled/*;
include /opt/etc/nginx/conf.d/*.conf;
default_type application/octet-stream;
server {
listen 82;
server_name localhost;
location / {
root /opt/share/nginx/html;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /opt/share/nginx/html/50x.html {
root html;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+\.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

6 - Create php-cgi startup script

cat >> /opt/etc/init.d/S80php-cgi << 'EOF'
#!/bin/sh
ENABLED=yes
PROCS=php-cgi
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

7 - Make script executable

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

8 - Fix php doc_root for nginx

sed -i 's|doc_root = "/opt/share/www"|doc_root = "/opt/share/www"\
doc_root = "/opt/share/nginx/html"|g' "/opt/etc/php.ini"

- Start server

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

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

11 - Create php info page:

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

Press Enter

12 - 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 https://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

REVIEW (CLICK ON THE STARS TO RATE!)
4
Sending
User Review
5 (2 votes)