Turn off PHP on Apache

Posted in Apache and PHP -

This post is a response to a question asked on my "Disable PHP in a directory with Apache .htaccess" article asking how to disable PHP completely in Apache, or as it was asked: "Could you tell me how can I turn off PHP on Apache (Run Apache without PHP)".

It depends on the operating system and distribution

To disable PHP entirely within Apache depends on the operating system and distribution. The following shows how to do it on what I have access to at the current time.

Debian 5

This should also work for other Debian 5 based distros.

Run the following using sudo or as the root user:

/usr/sbin/a2dismod php5
/etc/init.d/apache2 restart

To revert back and allow PHP to run again, again using sudo or as the root user:

/usr/sbin/a2enmod php5
/etc/init.d/apache2 restart

CentOS 5

This should also work for other Red Hat Enterprise Linux 5 and CentOS 5 based distros.

Run the following using sudo or as the root user:

mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf~
/etc/init.d/httpd restart

To revert back and allow PHP to run again, again using sudo or as the root user:

mv /etc/httpd/conf.d/php.conf~ /etc/httpd/conf.d/php.conf
/etc/init.d/httpd restart

OSX Snow Leopard with MAMP 1.9

Note: I have not actually tried this myself so it may not actually work.

I could not see any way to switch PHP off in the GUI configuration (although you can switch between PHP 5.2 and 5.3) so the only way I figure this can be done is to edit the main Apache configuration file from the command line. However, any changes made may well be automatically overridden at a later stage so I can't vouch for how well this would work.

sudo nano /Applications/MAMP/conf/apache/httpd.conf

Locate the following two lines and comment them out by prefixing with a #

LoadModule php5_module modules/php5.2/libphp5.so
AddType application/x-httpd-php .php .phtml

Then use the MAMP GUI to restart the servers.



Related posts:


Comments