Linux Apache – Securing PHP Webservers

apache-2.2linuxPHPSecurityweb-server

PHP applications have a reputation for higher than average security problems. What configuration techniques do you use for making sure the application is secure as possible?

I'm looking for ideas like:

I normally use Linux, but feel free to suggest Windows solutions too.

Best Answer

  1. Use the open_basedir directive to confine your PHP scripts to their home directory and eventual extra application directories. This is very efficient by itself.

  2. Use hardened php because that costs nothing and it can help.

  3. Use suPHP to have PHP scripts execute as the owner of the file (one user per website) and avoid using files with bad permissions such as 777... suPHP can also allow you to have on php.ini per website so that one site's stupid requirement don't destroy everything.

  4. Mod_security is a big plus but needs to be well used and configured.