Asked  2 Years ago    Answers:  5   Viewed   108 times

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:

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>
    DocumentRoot /var/www/vhosts/Site1/httpdocs

<VirtualHost *:8080>
    DocumentRoot /var/www/vhosts/Site2/httpdocs

I tried adding this inside the tags:

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

...but to no avail.



This finally put me on the right path:

Here's the solution:

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

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

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 mod_php5.c>
        php_admin_flag engine on

    (Other configuration parameters)

Saturday, October 22, 2022

Apparently, when you access a VirtualHost through the alias, there is no trace of the original SERVER_NAME in any of the $_SERVER variables.

The only idea that comes to mind is setting an environment variable:


this should set the value of $_SERVER["MY_HOST"] to the correct host name. No guarantees though, I have never tried this in practice.

Friday, November 4, 2022

First of all, what is the version of PHP?

If other .php scripts work except for phpMyAdmin, the is pretty safe to assume something is wrong with phpMyAdmin installation. (either with the files or the Virtual Host)


  1. Can you run another script in phpMyAdmin directory? Try with a file containing phpinfo(); If it does not work then the problem is in your apache configuration.

  2. If the above is true, then the parser is not recognising phpMyAdmin/index.php as a php file, for some reason. Try reinstalling phpMyAdmin.


Remove AddType application/x-httpd-php .php. You should not need it.

In PHP 5.4 magic_quotes_gpc was removed. If you're running PHP5, remove that line.

As of PHP 4.0.3, track_vars is always turned on, so remove it also.

As of PHP 4.2.0, register_globals this directive defaults to off. In PHP5.3 register_globals is deprecated, as of PHP5.4 register_globals was removed. SO if running PHP > 4.2.0 remove that line.

Wednesday, December 14, 2022

Although you're not allowed to set the sendmail_path from within the <VirtualHost> directive, you can set it within the <Directory> directive. So I simply have something that looks like this:

<VirtualHost *:80>
    Standard stuff goes here

    <Directory /dir/to/your/web/root>
        php_admin_value sendmail_path "/usr/sbin/sendmail -t -i [email protected]"


I'm not sure if it's the most proper or elegant way to accomplish this, but it definitely worked. Sorry it took so long to respond, I don't go on SF that frequently and forgot about this question.

Thursday, December 22, 2022

You need NameVirtualHost set up.

Open ports.conf and add: (You can also put it above the first <virtualHost>

NameVirtualHost *:80
Listen 80

You can also use the ip address instead of the wildcard.

Your vhost has to be formatted exactly the same as the NameVirtualHost format.

If it's formatted like this:


then vhost should be:


Tuesday, August 9, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :

Browse Other Code Languages