I have a server with a few different domains on it (each in a separate VHost). Each VHost runs fine, executing PHP properly, etc. For the sake of example, two of the domains are foo.com and bar.com. I'm trying to create an alias on foo.com that will include files from a directory on bar.com. Easy, right?

# Apache config file for foo.com
Alias /bar-alias /var/www/vhosts/bar.com/httpdocs/somedir
<Directory "/var/www/vhosts/bar.com/httpdocs/somedir">
        Options Indexes FollowSymLinks
        Order Allow,Deny
        Allow From All
        Deny From None

It works fine and dandy, except when trying to run a PHP script. Under my configuration, going to www.foo.com/bar-alias/script.php returns the source code of the script instead of executing it. I've been beating my head against the wall trying to figure out how to get Apache to execute PHP in this way, and I'm drawing a blank.

(If it is at all possible, I'd like to avoid having to do any symbolic linking or stuff like that. This seems like something that I should be able to do purely within Apache's config, I just can't work out how to do it.)


Looks like it might be executing the alias before it finishes reading the full http conf. Is the following line found before or after your Alias? Try moving it above:
Include conf.d/*.conf

  • The Include conf.d/*.conf line comes before the Alias line. In fact, the Include actually points to the file containing the Alias. – TimE Aug 12 '10 at 17:45
  • Try renaming the alias file to zz_whateveritscallednow.conf to ensure it gets read after the PHP include. – James L Aug 12 '10 at 18:22

Actually, I think I got it. Out of sheer frustration, I copied the following out of an earlier part of the configs and stuck it into the <Directory> block for this alias...

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

And lo and behold, it started to work as I expected it to. I'm going to hammer on it some more (it really doesn't seem like I should need that) but for the time being it's working well enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy