One apache server, one document root per virtual host, multiple/conditional PHP environments

    Date: 09/05/06 (PHP Community)    Keywords: php, html, web, apache

    This is a very simple trick I came up with for my test environment at home.  It's used with Apache 2.* with the virtual host module loaded in httpd.conf and a virtualhost.conf file included at the end.

    The trick is this:

    Say you have your virtual host sites in this directory structure.

    /websites/users/myDomain.com/public_html/

    At
    /websites/
    create two junctions/links to /websites/users/
    /websites/php4 -> /websites/users/
    /websites/php5 -> /websites/users/

    Now use the following conf file.


    ScriptAlias /php4/ "d:/wamp/php4/"
    ScriptAlias /php5/ "d:/wamp/php5/"


        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.1
    #Tell php where to find INI settings
        SetEnv PHPRC "d:/wamp/php4"
    #Tell Apache to process this mime with this CGI parser
        Action application/x-httpd-php "/php4/php.exe"    


     Options Indexes FollowSymLinks
     AllowOverride all
     Order Deny,Allow
     Deny from all
     Allow from 127.0.0.1
    #Tell php where to find INI settings
        SetEnv PHPRC "d:/wamp/php5"
    #Tell Apache to process this mime files with this CGI parser
        Action application/x-httpd-php "/php5/php-cgi.exe"

    #Tell's apache files of this type are php mime type

    AddType application/x-httpd-php .php .phtml .php3
    #if a broswer calls the server with http://php(4||5).myDomain.com it parses out to
    #d:/website/php(4||5)/myDomain.com/public_html/

    VirtualDocumentRoot "d:/website/%1/%2/public_html/"



    So now when you setup your hosts or local DNS server, you can run the same website/application in either environment by
    changing out the subdomain.  And further more, there is no way to mistake what environment your in or the need to have multiple copies of websites.
    Best of all, you can make other junction/links and Directory statements in Apache so you could test your site on just about every version of PHP there is.

    So
    http://php4.myWebsite.com/ would run the website with php4
    http://php5.myWebsite.com/ would run the website with php5


    I tested this out on XP 64, but because the idea is universal, it should work on *nix environments as well.  I made a project log of setting this up along with phpDocumentor and subversion, so if anyone is interested just contact me.

    Source: http://community.livejournal.com/php/491339.html

« PHP math-y goodness? || Forced variable declaration? »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home