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:

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

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:

Windows 10 with Ubuntu: Install error CanonicalGroupLimited.UbuntuonWindows cannot be found or cannot be accessed

On Windows 10 Enterprise build 1709 I installed the Windows Subsystem for Linux. Next I open the Microsoft Store and did a search for Ub...