Friday, May 08, 2015

Ubuntu - new setup of nginx, mysql, and php5 - permission denied when trying to view info.php

I followed the very helpful guide here:
https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-12-04


I actually did the setup on Ubuntu 15.04 and they worked.  There is one part where you have to change the codename used.


The last step is to create a info.php file that displays all of the php5 information.
When attempting to view this file I would get error 404.  I googled and started trying to find the issue.  The log stated the file was not found.  Since this is new to me I wanted to make sure the correct location was being used for my files and that the permissions were set correctly.


I checked the permissions on the files in the html directory and they were correct.
So I created a test html file in the
/usr/share/nginx/html
directory.  A simple hello.html.  I tested and the page displayed.


So it appeared that my info.php file was both in the correct location and permissions were correct.


Next I checked what accounts the nginx server process was using, and the php5-fpm process.  I found that the server worker process was running as user nginx and the php5-fpm worker process was running as www-data.  It was my intention that both be running as www-data.


I check to see if nginx was a member of www-data:
$ id nginx
-output: uid=121(nginx) gid=133(nginx) groups=133(nginx)
No, nginx is not a member of www-data.


To resovle this issue I need to give the nginx account access to the php5-fpm.  To do this I needed to add the user nginx to the www-data group (www-data is the user and is a member of the group www-data).


To do this I ran usermod -a -G <groupname> username
$ sudo usermod -a -G www-data nginx


Next, confirm the user is in the group:
$ id nginx
-output: uid=121(nginx) gid=133(nginx) groups=133(nginx),33(www-data)


As another way to confirm one can run:
$ awk -F':' '/www-data/{print $4}' /etc/group
nginx
www-data


Now nginx is a member of www-data.  Next I restarted nginx server and php5-fpm
$ sudo service nginx restart
$ sudo service php5-fpm restart


This time browsing to http://localhost/info.php displayed my php info properly.


I hope this possibly helps someone.

No comments:

New beginner's guide to PowerShell on my GitHub page

 I created a beginner's guide to PowerShell here: https://github.com/aamjohns/Powershell_Guide/blob/main/README.md I hope it helps someo...