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>