Ubuntu 16.04, PHP 7 FCGI running as www-data

13 posts / 0 new
Last post
#1 Mon, 04/17/2017 - 23:31

Ubuntu 16.04, PHP 7 FCGI running as www-data

I'm running a new server on Ubuntu 16.04 with PHP 7. All of my virtual servers are running as www-data, giving me errors on each of them for permissions (for example, can't update wordpress plugins).

I'm not really sure where to troubleshoot any further. I've tried commenting out SetHandler in a few apache config files and restarting, but it's still not working as I would expect it to.

Can anyone help me troubleshoot? I'm not sure where to go from here.

Tue, 04/18/2017 - 03:35
unborn's picture

hi, all servers should run under owner (domain) as 'user:user' not an www-data.. perhaps your problem is in that. You could try to change user and group of one server and see if that works correctly afterwords

Configuring/troubleshooting Debian servers is always great fun

Tue, 04/18/2017 - 11:24 (Reply to #2)

Hi unborn, thanks for replying. I understand what you're saying - that's actually my problem. I'm running into issues with permissions because they are not running as their own domain like you mentioned.

What do you mean by change user and group of one server? Can you elaborate?

I feel as if something is misconfigured, because all of my virtual servers are running php as www-data and I can't figure out how to fix it.

Thanks again for your help!

Wed, 04/19/2017 - 06:16 (Reply to #3)
unborn's picture

hi mfive,

try as root chown -R username:group directory like: sudo chown -R user-domain:user-domain /home/user-domain where user-domain is your domain user... try it just for one server to see if it works. If it will then you can have look on other things, but first try that command.

Configuring/troubleshooting Debian servers is always great fun

Wed, 04/19/2017 - 08:28 (Reply to #4)

I have the ability to change the directory ownership. All of the directories are owned by their own user:user - which, I believe, is what's causing issues with Apache running as www-data. There is a conflict in the user PHP/apache are running as (www-data) vs who owns the files (virtual-host).

How can I force Apache/PHP to run as the virtual server user? I am using FCGI which should work, but it's not :(

Thu, 04/20/2017 - 15:43 (Reply to #5)
unborn's picture

...in short or longer - I would ask it again - did it worked for you or - not???? I am sorry but too many issues are tested on my virtual thing.. so - did it work or????

Configuring/troubleshooting Debian servers is always great fun

Thu, 04/20/2017 - 22:43 (Reply to #6)

It works - but any time the app creates a file (via php), the file is saved with the owner/group as www-data:www-data - this doesn't resolve the root of the issue, though... which is the user that apache is running on. :(

Wed, 04/19/2017 - 20:54
Joe's picture

It sounds like mod_php or similar is running your PHP scripts. Are you sure you don't have handlers for mod_php happening in your Apache config that are taking precedence over the per-virtualhost fcgid config?


Check out the forum guidelines!

Wed, 04/19/2017 - 23:11 (Reply to #8)

Hi Joe, thanks for taking the time to reply. No, I'm not sure. Can you help me understand what to look for and which Apache config file(s)?

Thu, 04/20/2017 - 15:41 (Reply to #9)
unborn's picture

Hi, well - joe just did explained it... sorry to say you that...

Configuring/troubleshooting Debian servers is always great fun

Thu, 04/20/2017 - 22:47 (Reply to #10)

Okay - so a quick update. I found a SetHandler command in the apache2.conf file that looked like the following: sethandler application/x-httpd-php

I commented this out and I believe it's working now!!!! New files seem to be running as the correct owner.

Joe - you are a lifesaver! Thank you for pointing me in the right direction!

Thu, 02/28/2019 - 18:03

I know this is an old post, but just wanted to share that I was running into this same issue here. mfive lead me onto the right path, but instead of changing the apache2.conf file, I modified the /etc/apache2/mods-available/php7.0.conf file to:

<FilesMatch ".+\.ph(p[3457]?|t|tml)$">
#    SetHandler application/x-httpd-php
<FilesMatch ".+\.phps$">
#   SetHandler application/x-httpd-php-source
    # Deny access to raw php sources by default
    # To re-enable it's recommended to enable access to the files
    # only in specific virtual host or directory
    Require all denied
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[3457]?|t|tml|ps)$">
    Require all denied

# Running PHP scripts in user directories is disabled by default
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
    <Directory /home/*/public_html>
        php_admin_flag engine Off
Sat, 04/06/2019 - 00:58

I was having the same problem on Ubuntu 18.04 where PHP pages where I was having all sorts of file permissions issues because the PHP/Apache user was www-data.

Commenting out the SetHandler directives in /etc/apache2/mods-available/php7.2.conf fixed it as per mfive and kevinhayashi


BTW, this happened because when I upgraded, I accepted the project author's version rather than keeping my old version of the apache conf files. Bad idea.

Topic locked