PHP not working in Apache virtual hosts

I just had the situation where PHP worked fine from the default/main site configured in Apache, but not in a virtual host. Instead of parsing/executing the PHP script, Apache would rather send its source code back to the browser, which would propose to download it.

I found various potentials solutions online, like:

  • Checking if the PHP module was enabled (it was)
  • Setting “php_admin_flag engine” or “php_admin_value”  to “on” (it didn’t help)

What helped was to enable explicitly the PHP handlers in the Directory section of the corresponding vhosts. On OpenSUSE Leap, the file /etc/apache2/conf.d/php7.conf does exactly that, so I could just include it:

<VirtualHost ...>
        DocumentRoot /some/path
        <Directory /some/path>
                Include /etc/apache2/conf.d/php7.conf
                Options ...
                AllowOverride ...
                Require all granted
        </Directory>
</VirtualHost>
Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s