I have inherited a dev test server that "is not running php webs as it should".
PHP appears to be installed:
$ php -v
PHP 7.0.33-0+deb9u3 (cli) (built: Mar 8 2019 10:01:24) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.33-0+deb9u3, Copyright (c) 1999-2017, by Zend Technologies
And also the Apache php module is loaded:
$ apache2ctl -M | grep php
php7_module (shared)
The module config file /etc/apache2/mods-enabled/php7.0.conf
appears to be completely normal. It contains the following lines that set the MIME type for php files:
<FilesMatch ".+\.ph(p[3457]?|t|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
But a vanilla virtualhost would not process php files, and shows plain php code instead.
So the way I (kind of) fixed it, for time being, is this:
- created a folder
/var/www/php-bin
- created in this folder a file
php
that contains one line:#!/opt/php72/bin/php-cgi
added the following two lines to the site config:
ScriptAlias /php-bin/ /var/www/php-bin/ Action application/x-httpd-php /php-bin/php
And not this particular virtual host runs php files correctly.
It's clear that this is just a hack. The /opt/php72/bin/php-cgi
file was just found in the file system, and it's not the same php version that runs when $ php -v
command is executed.
I'd like to fix this server and avoid this hack with custom ScriptAlias and Action config directives. Since php and apache php mod packages are installed, and the php mod loaded, any vanilla virtual host should process php files by default. That extra configuration should be needed only when the site has to be processed by a different php version.