Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache: Disable php in a directory

Tags:

php

apache

I want to disable php in a 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?

like image 985
user1660218 Avatar asked Sep 07 '25 07:09

user1660218


1 Answers

php_flag engine offonly works if you are using mod_php(as well as mod_php7.x) than php-fpm

Seems you are using php-fpm, so add the further lines into httpd.conf:

<Directory "C:/xampp/htdocs/(path_to_directory)/dirname">
<FilesMatch ".+\.*$">
SetHandler !
</FilesMatch>
</Directory>

or these in .htaccess in the Directory you don't expect the execution of PHP:

<FilesMatch ".+\.*$">
SetHandler !
</FilesMatch>

I have tested it on an Unix Platform rather than a Windows, Hope it would help U.

like image 51
Hardrain Avatar answered Sep 09 '25 20:09

Hardrain