HOWTO: Set expose_php=Off in php.ini To Hide PHP Version in HTTP Headers (X-Powered-By)

| No TrackBacks
Here's a relatively quick tip you can use to harden the security of your LAMP stack.

In a default Apache/PHP configuration, PHP likes to insert its own HTTP header advertising the fact that you are using PHP on your server.  The "X-Powered-By" response header displays the version of PHP you are running, and in some cases, even the PHP patch level.  This can be troublesome, because intelligent hackers often look for this information in your response headers as a way to verify the version of PHP you are using.  For example, if a hacker discovers you are running PHP 4, there is a possibility that they will attempt to exploit known PHP 4 vulnerabilities.

Luckily, you can set the expose_php variable to "Off" in your global php.ini configuration file to hide this "X-Powered-By" header.  Depending on your distro, php.ini is usually found at /etc/php.ini or /etc/php5/apache2/php.ini.  Here's a snapshot of my php.ini file, showing the expose_php config variable set to Off:

; Misc
;
; Decides whether PHP may expose the fact that it is installed on the server
; (e.g. by adding its signature to the Web server header). It is no security
; threat in any way, but it makes it possible to determine whether you use PHP
; on your server or not.

expose_php = Off

Using HttpFox, an HTTP header analyzer extension for Firefox, I verified that PHP is no longer adding the "X-Powered-By" header to my responses (click for larger view):

expose-php-before-after.png

If you enjoyed this tip, you might also enjoy my post on HOWTO: Hide your Apache Server Version in Your HTTP Response Headers.

The PHP documentation I've read, claims expose_php "decides whether PHP may expose the fact that it is installed on the server (e.g. by adding its signature to the Web server header).  It is no security threat in any way, but it makes it possible to determine whether you use PHP on your server or not."

I'm not sure what the PHP folks mean by "it is no security threat in any way." If a hacker knows what version of PHP you are running, this information helps them narrow down which vulnerabilities they can try to exploit.  For the security minded administrator, or security expert, this is definitely a security threat.

Anyways, enjoy!

Did You Find this Helpful?

Did you find this post helpful, or at least, interesting?

  

About Mark

A Silicon Valley native, Mark Kolich is a full-time Software Engineer and a consultant for hire. A web technologies expert, his current focus is on building powerful and robust cloud-driven web-applications using Java, PHP, Perl, AJAX, DHTML, CSS, and JavaScript. His favorite programming languages are PHP, Java and JavaScript. He uses Linux, enjoys biking to work, loves building great software, and always writes elegant, readable, and maintainable code.

No TrackBacks

No trackbacks attached to this entry.

Twitter (@markkolich)

Translate

About this Entry

This page contains a single entry by Mark Kolich published on April 20, 2009 10:39 PM.

HOWTO: Make Your Own Solar Shield was the previous entry in this blog.

Java to Capitalize the First Letter of Each Word in a Sentence is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.