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.
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
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!
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.
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
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?
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)?
Hi, well - joe just did explained it… sorry to say you that…
…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???
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.
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!
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:
# SetHandler application/x-httpd-php
# 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')
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 .) Do NOT set it to On as it
prevents .htaccess files from disabling it.
php_admin_flag engine Off
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.
to fix this just disable sudo 2disconf php7.3-fpm