Search code examples
phpapacheincludesubdomainserver-side-includes

How do I limit PHP apps to their own directories and their own php.ini?


I am running multiple PHP apps on my Mac, running OS X 10.5.6, Apache 2, PHP 5. I have subdomains setup for each project, a host file entries for each subdomain, and Virtual Directory blocks in the Apache config. So

project1.localhost goes to /Library/WebServer/Documents/Project1
project2.localhost goes to /Library/WebServer/Documents/Project2
etc...

However, this method doesn't really "isolate" the web apps. For example, if I include a script like so:

<?php
include("/includes/include.php");
?>

It references the script from the base directory of my computer. So it accesses
C:/includes/include.php

Is there a way for me to make it reference
C:/Library/WebServer/Documents/Project2/includes/include.php

Basically, make it so that its not aware of anything outside of its own directory. Also, is there a way to use php.ini's on a per subdomain basis as well?


Solution

  • I believe it's possible to set a php.ini per virtual host

    <VirtualHost *:80>
        ...
    
        PHPINIDir /full/path/to/php/ini/
    
    </VirtualHost>
    

    this way you can customize open_basedir and others