Following Ubuntu PHP7 upgrade, Apache now runs as www-data instead of virtual server owner

Ubuntu 14.04 standard install, been running fine for months. Updated to latest Virtualmin 5.0 and system fully up to date.

I upgraded to PHP7 using the following tutorial:

https://www.digitalocean.com/community/tutorials/how-to-upgrade-to-php-7...

PHP7 is working, but Apache is now running as www-data instead of the virtual server owner, which breaks existing sites. Fortunately this is not a production server (I made a copy for testing), so no harm done. But I would like to get this working properly. Can you help?

Additional info: Re-checking Virtualmin config doesn't show any problems. Also, I see another person on the forum has the exact same issue:

https://www.virtualmin.com/comment/749422#comment-749422

Status: 
Active

Comments

Howdy -- there's likely a config file that was installed by the new PHP packages that's causing a problem.

If you go into System Settings -> Re-Check Config, does it detect any PHP-related errors?

Re-checking Virtualmin config doesn't show any problems. The system is ready for use by Virtualmin.

Okay, what is the output of this command:


find /etc/apache2/mods-enabled | xargs grep -i sethandler

$ find /etc/apache2/mods-enabled | xargs grep -i sethandler
grep: /etc/apache2/mods-enabled: Is a directory
/etc/apache2/mods-enabled/proxy_balancer.conf: # SetHandler balancer-manager
/etc/apache2/mods-enabled/php7.0.conf: SetHandler application/x-httpd-php
/etc/apache2/mods-enabled/php7.0.conf: SetHandler application/x-httpd-php-source
/etc/apache2/mods-enabled/status.conf: SetHandler server-status

Ah, there we go... it looks like those packages installed a new config file for PHP7, located in "etc/apache2/mods-enabled/php7.0.conf".

In there, you would want to comment out the two "SetHandler" lines, as those can cause mod_php to override the other PHP handlers. After doing that, restart Apache, and then see if it begins working properly.

That's caused the php code to show as text in the browser. For example, if I go to /phpinfo.php, the browser actually displays the following as plain text:

<?php phpinfo(); ?>

When this happened on one of my tests I had to go to each domain then Server Configuration --> Website Options and change PHP script execution mode back to FCGI.

Yeah that's an interesting question, what is the PHP Execution Mode currently set to for this domain?

It's FastCGI. I've tried switching between different modes, and commenting / uncommenting the SetHandler lines, with various combinations but Apache always runs as www-data.

I'm not sure if this is significant, but in ~/etc there is a symlink to ~/etc/php7/php.ini, however the directory ~/etc/php7 does not exist.

The PHP config file it's pointing at shouldn't be the issue here.

Could you try disabling mod_php altogether, restart Apache, and then try accessing your site again?

When disabling mod_php, the "/etc/apache2/mods-enabled/php7.0.conf" file would be gone altogether... I'm wondering if something within that is causing a problem.

Another thought would be to try switching the PHP Execution Mode to CGI, just in case something with FCGID isn't working properly.

I disabled mod_php and restarted Apache, and this got rid of the php7.0.conf file as you said.

Trying to run as FastCGI doesn't work, I get a 500 error. This is the error in the Apache logs:

[Tue Jan 12 12:48:52.275523 2016] [fcgid:warn] [pid 6956] (104)Connection reset by peer: [client 86.139.10.174:63538] mod_fcgid: error reading data from FastCGI server
[Tue Jan 12 12:48:52.275586 2016] [core:error] [pid 6956] [client 86.139.10.174:63538] End of script output before headers: phpinfo.php

So, I tried switching to CGI mode. This also doesn't work, and I get the following error in the browser:

The requested URL /cgi-bin/php7.0.cgi/phpinfo.php was not found on this server.

OK, I've managed to get this working. It turns out that when installing PHP7, there are some extra packages required. In this case in was php7.0-cgi that was missing.

For the record, this works for me on Ubuntu 14.04.

sudo add-apt-repository ppa:ondrej/php-7.0
sudo apt-get update
sudo apt-get install php7.0
sudo apt-get install php7.0-cgi
sudo apt-get install php7.0-mysql
sudo apt-get install php7.0-mcrypt
sudo apt-get install php7.0-gd
sudo apt-get install php7.0-curl
sudo reboot

ALSO I had to disable mod_php

sudo a2dismod php7\.0

Thanks for your help with this.

Aha! I'm glad you figured that out, as I was getting pretty puzzled :-)

Thanks for sharing how you got it working!

Actually, it turns out this isn't entirely fixed after all. Since I managed to get the first Virtual Server working, any subsequent Virtual Servers that have been added since are not working.

Currently, I have two newly created Virtual Servers - test.com and test2.com. Both have a single file public_html/index.php which contains <?php phpinfo(); ?>.

test.com - works fine.
test2.com - not working, with the following errors:

[Wed Jan 13 11:17:00.971035 2016] [fcgid:warn] [pid 1990] (104)Connection reset by peer: [client 86.139.10.174:53870] mod_fcgid: error reading data from FastCGI server
[Wed Jan 13 11:17:00.971114 2016] [core:error] [pid 1990] [client 86.139.10.174:53870] End of script output before headers: index.php

I've been through everything, and cannot find any configuration differences between the two Virtual Servers. And yet, only one of them is working :(

Can you try changing the PHP Execution Mode to CGI again, to see if it's still the same error you saw previously?

CGI produces better errors than FCGID, so that'll give us a better idea of what's going awry.

I changed the test2.com server to CGI mode.

The browser now displays this:

"Not Found - The requested URL /cgi-bin/php7.0.cgi/index.php was not found on this server."

I got PHP7 to work on Centos 7.2.1511 with nginx https2 and WOW I couldn't be happier, my wordpress site is loading freakishly fast 3x faster even with a bunch of plugins activated.

I ended up going with ius repo since centos says its ok https://wiki.centos.org/AdditionalResources/Repositories and these are the commands I used.

cd ~ curl 'https://setup.ius.io/' -o setup-ius.sh

bash setup-ius.sh

yum remove php-fpm php-cli php-common (when i used apache I didn't have to remove php 5.4 but with nginx I couldn't get it to use php7 no matter what I did)

yum install php70u-fpm-nginx php70u-cli php70u-mysqlnd

yum install php70u-cli.x86_64 php70u-common.x86_64 php70u-fpm.x86_64 php70u-gd.x86_64 php70u-mbstring.x86_64 php70u-mcrypt.x86_64 php70u-mysqlnd.x86_64 php70u-opcache.x86_64 php70u-pdo.x86_64 php70u-pear.noarch php70u-process.x86_64 php70u-xml.x86_64 php70u-xmlrpc.x86_64 php70u-json.x86_64 php70u-imap.x86_64 php70u-gmp.x86_64 php70u-bcmath.x86_64 php70u-pecl-apcu.x86_64 php70u-pecl-imagick.x86_64 php70u-soap.x86_64 php70u-tidy.x86_64

I am new to Virtualmin (came from cpanel was constantly being attacked) friend recommend Virtualmin with changed default ports and I've become a true believer! I've been testing this dev server for about 3 weeks now and I'm planning to move it to a production server if it continues to run this good.

The IUS repo is not supported nor provided by Centos. Just because it is on the wiki does not mean centos endorses it. In face there is this specific statement above that section that lists potential third party repos for centos:

WARNING: These repositories are not provided nor supported by CentOS. The CentOS project has no control over these sites. Many have their own mailing lists, IRC channels, issue trackers, etc. for support issues with their packages.

If you get php7 to work with centos ...great. If not then you will need to remove them and go back to php provided by centos.....