How to Remove x-powered-by in Apache/PHP for Enhanced Security

PHP Header Remove Techhyme

In the realm of web servers and PHP applications, securing your server and applications is a paramount concern. One common security practice is to remove or hide the `x-powered-by` header, which reveals information about the server’s identity and version. This information can be exploited by malicious attackers to identify potential vulnerabilities.

In this article, we will explore different methods to remove the `x-powered-by` header in Apache/PHP.

Method 1: Using php.ini

If you have access to the php.ini file, which is the PHP configuration file, you can easily disable the `expose_php` directive, thereby removing the `x-powered-by` header.

1. Open your terminal and use a text editor to access the php.ini file. The location may vary depending on your Linux distribution:

sudo vi /etc/php.ini

2. Look for the following line in the file:

expose_php = on

3. Change it to:

expose_php = off

4. Save and close the file.

5. Restart the Apache server to apply the changes:

service apache2 restart

PHP Header

Method 2: Using PHP Code

If you don’t have access to php.ini, you can still remove the `x-powered-by` header by incorporating PHP code directly into your application.

1. To remove the header entirely, you can use the `header_remove` function:


2. If you prefer to replace the `x-powered-by` value with a custom string, you can use the `header` function:

header("X-Powered-By: YourCustomValue");

Replace “YourCustomValue” with the desired value.


Securing your Apache/PHP server involves various measures, and removing the `x-powered-by` header is a simple yet effective step. By implementing one of the methods mentioned above, you can enhance the security posture of your web server and mitigate potential risks associated with disclosing unnecessary information.

Remember to regularly review and update your security practices to stay ahead of evolving threats in the dynamic landscape of web security.

You may also like:

Related Posts

Leave a Reply