0

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.

Passiday
  • 7,573
  • 8
  • 42
  • 61
  • Possible duplicate of [PHP code is not being executed, instead code shows on the page](https://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-instead-code-shows-on-the-page) – treyBake Jul 04 '19 at 11:17
  • @treyBake I saw that post, unfortunately none of the points mentioned there were helpful. I don't have the luxury of reinstalling everything from scratch, so I'm trying to fix a broken config. – Passiday Jul 04 '19 at 11:25
  • Without being able to re-code the apache modules etc. I think you're best bet is to reinstall. Just grab the sites and extensions and just do a plain install and copy across your sites and stuff :) – treyBake Jul 04 '19 at 11:29
  • 1
    As a side note you realise PHP 7 is end of life? get up to 7.2 `;-)` – Martin Jul 04 '19 at 11:31
  • Just to make sure... You're testing stuff with a script that uses ` – Álvaro González Jul 04 '19 at 17:56
  • @ÁlvaroGonzález yes, of course. As I say, I have verified the trivial possible causes. – Passiday Jul 05 '19 at 09:05

0 Answers0