Running PHP Scripts Outside of DocumentRoot

In some WAMP configurations, PHP execution is only enabled under a specific root folder and given path (instead of for any *.php filename under any folder or path).

For example, under WampDeveloper Pro, PHP is enabled for all *.php files under the path of:
C:\WampDeveloper\Websites\*\webroot\

There are two ways to enable the execution (running) of PHP scripts outside of a website’s DocumentRoot (\webroot) folder…

* In this example we’ll enable the running of PHP scripts in folder: D:\Folder\path\

Junction Point Into DocumentRoot

The preferred way to enable PHP in an outside folder is to keep the existing configuration (by not adding anything to it), and creating a “Junction Point” to link…

1. A folder inside a website’s DocumentRoot:
C:\WampDeveloper\Websites\www.example.com\webroot\path\

2. Into the PHP web-app/script folder:
D:\Folder\path\

Open the command line (with elevated privileges) and execute:

mklink /j C:\WampDeveloper\Websites\www.example.com\webroot\path D:\Folder\path

This will create folder:

C:\WampDeveloper\Websites\www.example.com\webroot\path

And link it to folder:

D:\Folder\path

This folder will inherit all the proper configurations (from the base WAMP configuration) of the later.

The only limitation here is that the target folder needs to be a local volume (e.g., can’t be a networked drive).

Enable PHP Directly For a Specific Folder

The second option is to directly enable PHP execution in the specific folder by placing this into a website’s VirtualHost, or into the global configuration (included into httpd.conf via Config\Apache\extra\wampd-custom.conf):

Alias /path/ "D:/Folder/path/"

<Directory "D:/Folder/path">
    Options All
    AllowOverride All
    Order allow,deny
    Allow from all

    # PHP-FCGI
    <IfModule mod_fcgid.c>        
        AddHandler fcgid-script .php .php4 .php5 .php7
        Options +ExecCGI +FollowSymLinks

        FcgidWrapper "C:/WampDeveloper/Components/Php/php-cgi.exe" .php virtual
        FcgidWrapper "C:/WampDeveloper/Components/Php/php-cgi.exe" .php4 virtual
        FcgidWrapper "C:/WampDeveloper/Components/Php/php-cgi.exe" .php5 virtual
        FcgidWrapper "C:/WampDeveloper/Components/Php/php-cgi.exe" .php7 virtual
    </IfModule>

    # Apache 2.4 / PHP7
    <IfModule mod_php7.c>
        AddType text/html .php .php4 .php5 .php7 .phps
        AddHandler application/x-httpd-php .php .php4 .php5 .php7
        AddHandler application/x-httpd-php-source .phps
    </IfModule>

    # Apache 2.2 and 2.4 / PHP5
    <IfModule mod_php5.c>
        AddType text/html .php .php4 .php5 .php7 .phps
        AddHandler application/x-httpd-php .php .php4 .php5 .php7
        AddHandler application/x-httpd-php-source .phps
    </IfModule>

    # Apache 2.2 / PHP 4.4
    <IfModule php4_module>
        AddType text/html .php .php4 .php5 .php7 .phps
        AddHandler application/x-httpd-php .php .php4 .php5 .php7
        AddHandler application/x-httpd-php-source .phps
    </IfModule>

    # Apache 2.0 / PHP 4.4
    <IfModule sapi_apache2.c>
        AddType text/html .php .php4 .php5 .php7 .phps
        AddHandler application/x-httpd-php .php .php4 .php5 .php7
        AddHandler application/x-httpd-php-source .phps
    </IfModule>
</Directory>

The limitation with this option is that while this will enable PHP execution in the specific folder, this folder will not inherit any other configuration of the base WAMP setup.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>