Mobile app version of vmapp.org
Login or Join
Martha676

: Apache: disable PHP in a directory I want to disable php in a specific directory on my server. I thought that setting Options -ExecCGI in httpd.conf would prevent php scripts from being executed,

@Martha676

Posted in: #Apache #Php

I want to disable php in a specific directory on my server. I thought that setting Options -ExecCGI in httpd.conf would prevent php scripts from being executed, but obviously I am wrong.

So, this is what I have in my httpd.conf, which obviously does not work:

<Directory "C:/xampp/htdocs/(path_to_directory)/dirname">
Options -ExecCGI
AllowOverride None
</Directory>


The question is, how can I prevent php scripts from being executed in a specific folder? Can in be done in httpd.conf or do I have to use a .htaccess file?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Martha676

2 Comments

Sorted by latest first Latest Oldest Best

 

@Michele947

Adding this line to your virtual host seems to work: php_value engine off

<Directory "C:/xampp/htdocs/(path_to_directory)/dirname">
php_value engine off

# other options
</Directory>


On Debian, the file would be located in the folder /etc/apache2/sites-available/

10% popularity Vote Up Vote Down


 

@Heady270

PHP scripts are not typically handled by the CGI module. They are usually handled by a separate PHP module with its own configuration options. This page has a few examples of syntax that should do the job for you. I expect that they would work either in your conf file or in .htaccess. Try:

<Directory "C:/xampp/htdocs/(path_to_directory)/dirname">
Options -ExecCGI
AllowOverride None
RemoveHandler .cgi .pl .py .php4 .pcgi4 .php .php3 .phtml .pcgi .php5 .pcgi5
RemoveType .cgi .pl .py .php4 .pcgi4 .php .php3 .phtml .pcgi .php5 .pcgi5
</Directory>


OR

<Directory "C:/xampp/htdocs/(path_to_directory)/dirname">
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
Options -ExecCGI
AllowOverride None
</Directory>


The link that Helping Hands put in the comments has a simpler way of removing all handlers by setting them all to the default and removing all options with "None":

<Directory "C:/xampp/htdocs/(path_to_directory)/dirname">
SetHandler default-handler
Options None
AllowOverride None
</Directory>

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme