Apache downloads the PHP files instead of executing them in FCGId mode

The subject matter is happening on a fresh Virtualmin setup. The website pages display ok in Apache mod_php and FPM modes, however switching to FCGId (which is set by default) makes PHP pages to download.

Checking the Virtualmin configuration shows everything is alright:

The status of your system is being checked to ensure that all enabled features are available, that the mail server is properly configured, and that quotas are active ..
Your system has 992.58 MB of memory, which is at or above the Virtualmin recommended minimum of 256 MB.
BIND DNS server is installed, and the system is configured to use it.

Mail server Postfix is installed and configured.

Postfix is configured to support per-domain outgoing IP addresses.

Apache is installed.

The following PHP versions are available : 5.4.16 (/bin/php-cgi), 5.4 (mod_php)

PHP-FPM support is available on this system.

PHP versions have changed to 5, 5.4 since last check. Regenerating any missing php.ini files.

Webalizer is installed.

Apache is configured to host SSL websites.

MySQL is installed and running.

ProFTPD is installed.

Logrotate is installed.

SpamAssassin and Procmail are installed and configured for use.

ClamAV is installed and running.

Plugin DAV Login is installed OK.

Plugin AWstats reporting is installed OK.

Plugin Protected web directories is installed OK.

Using network interface eth0 for virtual IPs.

Default IPv4 address for virtual servers is xx.xx.xx.xx.

Default IP address is set to xx.xx.xx.xx, which matches the detected external address.

Both user and group quotas are enabled for home and email directories.

All commands needed to create and restore backups are installed.

The selected package management and update systems are installed OK.

Chroot jails are available on this system

.. your system is ready for use by Virtualmin.
Updating all Webmin users with new settings..
.. done

Updating status collection job ..
.. done

Applying web server configuration ..
.. done

Re-loading Webmin ..
.. done
Status: 
Closed (fixed)

Comments

The https://www.virtualmin.com/node/35582 suggests third party repository was used, however when I check Apache info it shows it was from Virtualmin:

yum info httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.mit.edu
* epel: linux.mirrors.es.net
* extras: linux.mirrors.es.net
* updates: mirror.hmc.edu
Installed Packages
Name        : httpd
Arch        : x86_64
Epoch       : 1
Version     : 2.4.6
Release     : 45.el7.centos.4vm
Size        : 9.4 M
Repo        : installed
From repo   : virtualmin
Summary     : Apache HTTP Server
URL         : http://httpd.apache.org/
License     : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
            : web server.
yum info php
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.mit.edu
* epel: linux.mirrors.es.net
* extras: linux.mirrors.es.net
* updates: mirror.hmc.edu
Installed Packages
Name        : php
Arch        : x86_64
Version     : 5.4.16
Release     : 42.el7
Size        : 4.4 M
Repo        : installed
From repo   : base
Summary     : PHP scripting language for creating dynamic web sites
URL         : http://www.php.net/
License     : PHP and Zend and BSD
Description : PHP is an HTML-embedded scripting language. PHP attempts to make it
            : easy for developers to write dynamically generated web pages. PHP also
            : offers built-in database integration for several commercial and
            : non-commercial database management systems, so writing a
            : database-enabled webpage with PHP is fairly simple. The most common
            : use of PHP coding is probably as a replacement for CGI scripts.
            :
            : The php package contains the module (often referred to as mod_php)
            : which adds support for the PHP language to Apache HTTP Server.

Howdy -- what is the output of these two commands:

ls /etc/yum.repos.d
find /etc/httpd -type f | xargs grep -i sethandler
ls /etc/yum.repos.d
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo  epel-testing.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo  epel.repo          virtualmin.repo

and

find /etc/httpd -type f | xargs grep -i sethandler
/etc/httpd/conf.d/php.conf:    SetHandler application/x-httpd-php
/etc/httpd/conf.d/php.conf:#    SetHandler application/x-httpd-php-source

but Apache is not from Epel.

I am not sure if this might be relevant, but the /var/log/httpd/error_log file also shows the error discussed on https://www.virtualmin.com/node/37310:

[Wed Aug 23 06:45:55.492914 2017] [suexec:notice] [pid 16743] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Wed Aug 23 06:45:55.532012 2017] [auth_digest:notice] [pid 16743] AH01757: generating secret for digest authentication ...
[Wed Aug 23 06:45:55.533163 2017] [lbmethod_heartbeat:notice] [pid 16743] AH02282: No slotmem from mod_heartmonitor
[Wed Aug 23 06:45:55.572393 2017] [mpm_prefork:notice] [pid 16743] AH00163: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod_fcgid/2.3.9 PHP/5.4.16 configured -- resuming normal operations
[Wed Aug 23 06:45:55.572423 2017] [core:notice] [pid 16743] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'

The mod_heartmonitor is commented out in /etc/httpd/conf.modules.d/00-base.conf

Commenting out the LoadModule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so line in /etc/httpd/conf.modules.d/00-proxy.conf didn't resolve the issue, so it is not relevant.

I've created another fresh KVM VPS from centos-7.3-x86_64, have ran only yum update and right away thereafter:

cd /usr/src
wget http://software.virtualmin.com/gpl/scripts/install.sh
chmod 755 install.sh
DISABLE_SCL=1
export DISABLE_SCL
./install.sh -y

Then I went through the Post-Installation Wizard without changing anything, except setting MySQL root password (By the way, you have to bring the cursor back to password field every single time you type a letter - worth another bug report), checked the configuration to get:

The status of your system is being checked to ensure that all enabled features are available, that the mail server is properly configured, and that quotas are active ..
Your system has 1.46 GB of memory, which is at or above the Virtualmin recommended minimum of 256 MB.
BIND DNS server is installed, and the system is configured to use it.

Mail server Postfix is installed and configured.

Postfix is configured to support per-domain outgoing IP addresses.

Apache is installed.

The following PHP versions are available : 5.4.16 (/bin/php-cgi), 5.4 (mod_php)

PHP-FPM support is available on this system.

PHP versions have changed to 5, 5.4 since last check. Regenerating any missing php.ini files.

Webalizer is installed.

Apache is configured to host SSL websites.

MySQL is installed and running.

ProFTPD is installed.

Logrotate is installed.

SpamAssassin and Procmail are installed and configured for use.

ClamAV is installed and running.

Plugin DAV Login is installed OK.

Plugin AWstats reporting is installed OK.

Plugin Protected web directories is installed OK.

Using network interface eth0 for virtual IPs.

Default IPv4 address for virtual servers is xx.xx.xx.xx.

Default IP address is set to xx.xx.xx.xx, which matches the detected external address.

Both user and group quotas are enabled for home and email directories.

All commands needed to create and restore backups are installed.

The selected package management and update systems are installed OK.

Chroot jails are available on this system

.. your system is ready for use by Virtualmin.
Updating all Webmin users with new settings..
.. done

Updating status collection job ..
.. done

Re-loading Webmin ..
.. done

Created a virtual server with everything default.

Created a very simple index.php in public_html:

<?php

print "Hello";

?>

and when trying to open the website in browser, it immediately starts downloading the file instead of displaying it.

It is very much sad that Virtualmin is released to public broken like this.

Joe's picture
Submitted by Joe on Wed, 08/23/2017 - 20:29 Pro Licensee

This has been fixed in the installer a couple of days ago. You can correct it on existing installations by editing /etc/httpd/conf.d/php.conf and commenting out all lines in the file (put a # in front of them). Then restart httpd:

# systemctl restart httpd
Joe's picture
Submitted by Joe on Wed, 08/23/2017 - 20:30 Pro Licensee

Assigned: Unassigned »
Status: Active » Fixed

Joe, I appreciate your input, but this was not fixed couple days ago, because I downloaded installed dozens of times during last days.

This has been fixed only today and I am pretty sure as result of this or similar discussions and error reports. Would be very nice if the *min developers finally change their mantra on every fucking reported issue: "This was fixed n days ago".

Start acknowledging errors and mistakes, appreciating your user base is reporting them like all other successful projects and then you will build stronger and more loyal community around your products.

Additionally, there is no such a file as /etc/httpd/conf.d/php.conf

ls -l /etc/httpd/conf.d/
total 40
-rw-r--r-- 1 root root 2926 May  1 01:32 autoindex.conf
-rw-r--r-- 1 root root 1210 Aug 23 21:52 awstats.conf
-rw-r--r-- 1 root root  401 Jun  9  2014 fcgid.conf
-rw-r--r-- 1 root root  366 May  1 01:34 README
-rw-r--r-- 1 root root 9438 Apr 12 09:50 ssl.conf
-rw-r--r-- 1 root root 1231 Aug 23 21:52 userdir.conf
-rw-r--r-- 1 root root  302 Jan 12  2017 webalizer.conf
-rw-r--r-- 1 root root  839 Aug 23 21:52 welcome.conf

In comment #4 above, when you ran the "find" command, it found the php.conf file that Joe was referring to:

/etc/httpd/conf.d/php.conf

That file contained a "SetHandler" line, which would have caused the issue you were describing. That would need to be commented out.

You mentioned in Comment #7 that you began with a new installation though... if you're working with another installation, can you try running that same "find" command again? That will check to see if there is another similar SetHandler line that is causing problems.

If it finds one, comment it out, and then restart Apache.

If you aren't seeing it, try just restarting Apache to see if maybe that .conf file was removed since the last time it was restarted.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

We have seen this one coming back on several pre-existing Virtualmin servers after the last OS update. Here are some data from one of such servers:

yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.mirror.ndchost.com
* epel: mirror.sfo12.us.leaseweb.net
* extras: centos.eecs.wsu.edu
* remi-safe: repo1.sea.innoscale.net
* updates: mirror.pac-12.org
repo id                                                          repo name                                                                                               status
base/7/x86_64                                                    CentOS-7 - Base                                                                                          9,591
epel/x86_64                                                      Extra Packages for Enterprise Linux 7 - x86_64                                                          12,113
extras/7/x86_64                                                  CentOS-7 - Extras                                                                                          282
remi-safe                                                        Safe Remi's RPM repository for Enterprise Linux 7 - x86_64                                               2,573
updates/7/x86_64                                                 CentOS-7 - Updates                                                                                       1,089
virtualmin/7/x86_64                                              RHEL/CentOS 7 - x86_64 - Virtualmin                                                                         39
virtualmin-universal                                             Virtualmin Distribution Neutral Packages                                                                    42
repolist: 25,729
cat /etc/*release*
CentOS Linux release 7.4.1708 (Core)
Derived from Red Hat Enterprise Linux 7.4 (Source)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

CentOS Linux release 7.4.1708 (Core)
CentOS Linux release 7.4.1708 (Core)
cpe:/o:centos:centos:7
arch
x86_64
l /etc/httpd/conf.d/
total 44
-rw-r--r-- 1 root root 2926 Sep 20 02:44 autoindex.conf
-rw-r--r-- 1 root root 1210 Aug 22 01:58 awstats.conf
-rw-r--r-- 1 root root  432 Aug 22 02:01 fcgid.conf
-rw-r--r-- 1 root root  691 Nov 15 11:36 php.conf
-rw-r--r-- 1 root root  366 Sep 20 02:46 README
-rw-r--r-- 1 root root 9438 Aug 23 07:11 ssl.conf
-rw-r--r-- 1 root root 1231 Aug 22 01:58 userdir.conf
-rw-r--r-- 1 root root  302 Jan 12  2017 webalizer.conf
-rw-r--r-- 1 root root  839 Aug 22 01:58 welcome.conf

so php.conf exists since November 15, 2017.

What is the output of this command:

rpm -qf /etc/httpd/conf.d/php.conf

rpm -qf /etc/httpd/conf.d/php.conf
php-5.4.16-43.el7_4.x86_64

Hmm, it sounds like the php.conf file had been deleted. And then likely re-created during the package updates, which would indeed cause problems with the SetHandler lines.

I've talked it through with Joe, and Virtualmin should never delete that file. If for some reason it is, that's certainly a bug, though thus far we haven't been able to reproduce it.

The one possible exception to that, is Joe says that package isn't used in the case of Nginx.

I don't imagine you had experimented with Nginx on any of those servers, and then later switched back to Apache?

And then the other question I have to ask, is it possible that an admin had manually removed that file at some point in the past?

We're not seeing this issue on our own CentOS-based systems (such as the one that runs virtualmin.com), and with the majority of our customers, so we're trying to determine what might be different in the case of your systems that might be triggering that problem.

Never used Nginx. At the same time not sure if we deleted the file previously on those servers. This time we fixed this issue by just commenting out the respective lines, so let's consider this as closed for now and see if this issue pops up again in the future.

Yeah, commenting out those lines is best, so that the file doesn't get re-created by a package update.

Same issue here on a fresh installation (CentOS 7)

rpm -qf /etc/httpd/conf.d/php.conf php-5.4.16-46.el7.x86_64

cat /etc/httpd/conf.d/php.conf

#
# Cause the PHP interpreter to handle files with a .php extension.
#
#<FilesMatch \.php$>
#    SetHandler application/x-httpd-php
#</FilesMatch>
#
#
# Allow php to handle Multiviews
#
#AddType text/html .php
#
#
# Add index.php to the list of files that will be served as directory
# indexes.
#
#DirectoryIndex index.php
#
#
# Uncomment the following lines to allow PHP to pretty-print .phps
# files as PHP source code:
#
#<FilesMatch \.phps$>
#    SetHandler application/x-httpd-php-source
#</FilesMatch>
#
#
# Apache specific PHP configuration options
# those can be override in each configured vhost
#
#php_value session.save_handler "files"
#php_value session.save_path    "/var/lib/php/session"

virtualmin check-config

Your system has 11.73 GB of memory, which is at or above the Virtualmin recommen                                                                 ded minimum of 256 MB.

BIND DNS server is installed, and the system is configured to use it.

Mail server Postfix is installed and configured.

Postfix is configured to support per-domain outgoing IP addresses.

Apache is installed.

The following PHP versions are available : 5.4.16 (/bin/php-cgi), 7.2.10 (/opt/r                                                                 h/rh-php72/root/usr/bin/php-cgi), 5.4 (mod_php)

The following PHP-FPM versions are available on this system : 5.4.16 7.2.10

Webalizer is installed.

Apache is configured to host SSL websites.

MySQL is installed and running.

ProFTPD is installed.

Logrotate is installed.

SpamAssassin and Procmail are installed and configured for use.

ClamAV is installed and assumed to be running.

The System and Server Status module is installed and checking on schedule.

Plugin AWstats reporting is installed OK.

Plugin DAV Login is installed OK.

Plugin Protected web directories is installed OK.

Using network interface ens192 for virtual IPs.

IPv6 addresses are available, using interface ens192.

Default IPv4 address for virtual servers is XXXX.

Default IPv6 address for virtual servers is XXXX.

Quotas are not enabled on the filesystem /home which contains home directories under /home and email files under /home. Quota editing has been disabled.

All commands needed to create and restore backups are installed.

Resource limits are supported and configured correctly.

The selected package management and update systems are installed OK.

Chroot jails are available on this system

The Virtualmin YUM repository is configured correctly

OK

We're happy to help!

Can you post all this into a new support request though? That will make it easier to lend a hand. Thanks!