Php – Apache Virtual Host not parsing PHP

apachePHP

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.

Best Answer

This could also be due to php files using short php tags <? instead of <?php. By default, short tags are not enabled in the php.ini config file.