disable php in an apache virtualhost

March 14, 2010

in web

As long as I’m messing with apache configs, I’ll share another quick tip. If you have PHP generally enabled in apache, but you want to disable it in a certain VirtualHost, just add the line “php_admin_value engine off” and you’ll be all good. PHP will work elsewhere, but it will be off inside your described virtualhost. For example:

<VirtualHost *:80>
        ServerName www.foobar.com
 
        php_admin_value engine off
 
        DocumentRoot /var/www/foobar
</VirtualHost>

as a note (albeit an important one), using “php_admin_value” rather than “php_value” keeps the directive from being overridden in .htaccess files.

whammy.

{ 2 comments… read them below or add one }

Ian May 16, 2010 at 2:41 pm

Thanks!

Chris August 30, 2010 at 2:52 pm

Thanks. If you want to cause the PHP files to be served as html (which might or might not be a good idea, but in some situations you want to) you can add the directive

AddType text/html .php

to the VirtualHost container.

Leave a Comment

Previous post:

Next post: