I found a similar question here: Nginx serves .php files as downloads, instead of executing them But unfortunately the answer there doesn't help me. So here goes my story.
What Works
When I navigate to myipaddress/index.html, the welcome to nginx page renders correctly. When I navigate to myipaddress/widgets/index.html, the welcome to nginx page renders correctly. NB: I have slightly altered this index.html from the one above so the welcome message is different. This way, I prove to myself it really is finding the two different index.html files / folder structure.
What Doesn't Works
When i navigate to myipaddress/widgets/info.php, instead of showing the details of phpinfo() command, it downloads the php file.
Installed Packages
I am running alpinelinux. Installed the following packages:
lab-1:/var/www/localhost/htdocs# cat /etc/apk/world
curl
nginx
php7-common
php7-fpm
Nginx Version
lab-1:/etc/php7# nginx -v
nginx version: nginx/1.14.0
rc-status
lab-1:/var/www/localhost/htdocs# rc-status
Dynamic Runlevel: manual
nginx [ started ]
php-fpm7 [ started ]
Folder Structure
lab-1:/var/www/localhost/htdocs# ls -lah
total 16
drwxr-xr-x 3 www www 4.0K Sep 13 14:22 .
drwxr-xr-x 3 www www 4.0K Sep 13 13:17 ..
-rw-r--r-- 1 www www 624 Sep 12 20:35 index.html
drwxr-xr-x 2 www www 4.0K Sep 13 17:40 widgets
lab-1:/var/www/localhost/htdocs# ls -lah widgets/
total 16
drwxr-xr-x 2 www www 4.0K Sep 13 17:40 .
drwxr-xr-x 3 www www 4.0K Sep 13 14:22 ..
-rw-r--r-- 1 root root 632 Sep 13 14:23 index.html
-rwxr-xr-x 1 www www 27 Sep 13 15:45 info.php
Configuration Files
- /etc/nginx/conf.d/default.conf => https://pastebin.com/QWspV6DF
- /etc/nginx/conf.d/widgets.conf => https://pastebin.com/9XR5mRUJ
- /etc/php7/php-fpm.d/www.conf => https://pastebin.com/c8HKj50W
netstat to prove php fpm is running
lab-1:/etc/php7# netstat -lnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 4268/php-fpm.conf)
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4323/nginx.conf
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 346/sshd
tcp 0 0 :::80 :::* LISTEN 4323/nginx.conf
tcp 0 0 :::22 :::* LISTEN 346/sshd
ps -A
4268 root 0:00 {php-fpm7} php-fpm: master process (/etc/php7/php-fpm.conf)
4275 nginx 0:00 {php-fpm7} php-fpm: pool www
4276 nginx 0:00 {php-fpm7} php-fpm: pool www
4323 root 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
4324 nginx 0:00 nginx: worker process
4325 nginx 0:00 nginx: worker process
4326 nginx 0:00 nginx: worker process
4328 nginx 0:00 nginx: worker process
4329 nginx 0:00 nginx: worker process
4330 nginx 0:00 nginx: worker process
4331 nginx 0:00 nginx: worker process
4332 nginx 0:00 nginx: worker process
Comments
I tried to make sure the listen owner and listen group is the same user that nginx runs as - which is "nginx". Also I know that using "127.0.0.1:9000" is not as good as using a unix socket. But I'm trying to use the default install settings for now for php7-fpm. (Truth be told, I also don't know how to change it)
Questions
- can you see where I've gone wrong?
- Does the fact that it's downloading the php file prove it's finding the "location" directive in the right conf file? so is the problem limited to content of my location{} directive within the widgets.conf file?
- once I've fixed the php problem, if there are really huge gaffs in my set up that you can see, can you point them out? Thanks.
EDIT 1
I installed curl on my machine and tried to do this:
lab-1:/etc/php7# curl http://10.11.11.1111/widgets/info.php
<?php
phpinfo();
?>
vs this:
lab-1:/etc/php7# curl http://widgets/index.html
curl: (6) Could not resolve host: widgets
But I don't quite know how to fix this. I want the system to always require that an IP address be specified and then the foldername / app name.