Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Virtual Host not parsing PHP

Tags:

php

apache

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.

like image 445
user1075581 Avatar asked Feb 16 '12 04:02

user1075581


3 Answers

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.

like image 77
Ricky Theil Avatar answered Nov 15 '22 04:11

Ricky Theil


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>
like image 39
user1075581 Avatar answered Nov 15 '22 04:11

user1075581


In my case, the problem was fixed by running the following command:

apt-get install libapache2-mod-php
like image 7
LostMyGlasses Avatar answered Nov 15 '22 04:11

LostMyGlasses