Skip to content
Advertisement

Apache Virtual Host not parsing PHP

I decided to enable virtual hosts on my Apache server, and chose to make it port-based.

First thing I did, of course, was RTM. I followed the instructions found here. Well, it worked — kind of. As far as the virtual host running, it does. The content pulled from :80 is different from :8080.

But PHP isn’t working. The “original site”, (port 80) is running PHP just great. The port 8080 site, however, sends the PHP to the browser. I see nothing in the browser, but the source code shows:

<?php
echo "It worked!";
?>

This topic seems to be very loosely documented on a few websites, but either I can’t find a solution in them, or the solution listed isn’t working for me.

Again, the virtual host itself is running fine. PHP, on the other hand, is not.

Any ideas on what it could be? What content from my httpd.conf file should I provide so I don’t blow up my question by copy/pasting the whole thing?

(Sorry I forgot to post that I had these in place, Phil. Adding to avoid further confusion)

Listen 80
Listen 8080

NameVirtualHost *:80
NameVirtualHost *:8080

<VirtualHost *:80>
    ServerName mysite.com
    DocumentRoot /var/www/vhosts/Site1/httpdocs
</VirtualHost>

<VirtualHost *:8080>
    ServerName mysite.com
    DocumentRoot /var/www/vhosts/Site2/httpdocs
</VirtualHost>

I tried adding this inside the tags:

AddHandler php5-script .php
AddType text/html .php

…but to no avail.

Advertisement

Answer

This finally put me on the right path:

http://www.linuxquestions.org/questions/linux-server-73/php-not-working-on-one-vhost-but-works-on-all-others-851093/

Here’s the solution:

In the <Directory> section, I included these lines:

<IfModule sapi_apache2.c>
    php_admin_flag engine on
</IfModule>
<IfModule mod_php5.c>
    php_admin_flag engine on
</IfModule>

Or, a redacted copy/paste of the solution on my server:

<Directory "/var/www/vhosts/A2/httpdocs">
    <IfModule sapi_apache2.c>
        php_admin_flag engine on
    </IfModule>
    <IfModule mod_php5.c>
        php_admin_flag engine on
    </IfModule>

    (Other configuration parameters)

</Directory>
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement