Disable PHP Execution in Certain Directories

September 22nd, 2011 by Mark Lewis

In deploying a web PHP application, there may be instances where you need to disable PHP execution in certain places. This is especially helpful if your application accepts uploaded files which are placed under the document root. This way if a person happens to upload a PHP file, it will not be executed.

Under Apache, you may turn off PHP execution on a per-directory basis. In the VirtualHost directive, add:

php_flag engine off

If you’re allowed to use .htaccess files, create a .htaccess file in the directory you wish to disable PHP execution:

php_flag engine off