Turn off PHP on Apache
Posted July 14th, 2010 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:
- Disable PHP in a directory with Apache .htaccess (Monday, March 29th 2010)
- Disabling PHP short tags in an Apache .htaccess file (Thursday, March 11th 2010)
- Get Apache to parse .html files as PHP (Sunday, January 10th 2010)
- Set PHP configuration options with an Apache .htaccess file (Thursday, April 16th 2009)
Share or Bookmark
Share or Bookmark this page using the following services. You will need to have an account with the selected service in order to post links or bookmark this page.
Subscribe or Follow
Subscribe via RSS or email, or follow me on Facebook or Twitter below. The RSS icon takes you through to Feedburner where you can select the service or application to use.

