How to Hide PHP Version in Linux

PHP is a popular scripting language used to develop web applications. However, displaying the PHP version on a website can be a security risk as it reveals valuable information to attackers. By hiding the PHP version, you can make it more difficult for attackers to exploit vulnerabilities in your PHP installation.

In this guide, we will show you how to hide the PHP version on Linux.

Before:

[root@centos66 ~]# curl -I https://webhostinggeeks.com/howto/
HTTP/1.1 200 OK
Server: nginx
Content-Type: text/html; charset=UTF-8
Vary: Accept-Encoding
X-Powered-By: PHP/5.3.3
X-Pingback: https://webhostinggeeks.com/howto/xmlrpc.php
Date: Wed, 11 Feb 2015 14:10:43 GMT
X-Page-Speed: 1.9.32.2-4321
Cache-Control: max-age=0, no-cache

After:

[root@centos66 ~]# curl -I https://webhostinggeeks.com/howto/
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 11 Feb 2015 15:38:14 GMT
Content-Type: text/html; charset=UTF-8
Vary: Accept-Encoding
X-Pingback: https://webhostinggeeks.com/howto/xmlrpc.php
Date: Wed, 11 Feb 2015 14:10:43 GMT
X-Page-Speed: 1.9.32.2-4321
Cache-Control: max-age=0, no-cache

Step 1: Locate the PHP Configuration File

The first step is to locate the PHP configuration file. Depending on your Linux distribution, the location of this file may vary. In most cases, you can find it at:

/etc/php.ini

Step 2: Edit the PHP Configuration File

Once you have located the PHP configuration file, you need to edit it. Open the file in your preferred text editor:

sudo nano /etc/php.ini

Find the following line:

expose_php = On

Change it to:

expose_php = Off

Save the changes and exit the editor by pressing Ctrl + X, then Y, and finally Enter.

See also  How to Install and Configure PHP 5.3.3 on CentOS 6.4

Step 3: Restart the Web Server

Finally, you need to restart the web server for the changes to take effect. The command to restart the web server depends on the web server you are using. If you are using Apache, run the following command:

sudo service apache2 restart

If you are using Nginx, run the following command:

sudo service nginx restart

Commands Mentioned:

  • sudo nano /etc/php.ini – Open the PHP configuration file in nano text editor
  • sudo service apache2 restart – Restart Apache web server
  • sudo service nginx restart – Restart Nginx web server
See also  How to Enable Admin Script of APC on PHP

Conclusion

In this guide, we have shown you how to hide the PHP version on Linux. By following these steps, you can prevent attackers from discovering the PHP version running on your web server, making it harder for them to exploit vulnerabilities. It is important to note that hiding the PHP version is just one of many security measures you should take to secure your web server. We hope this guide has been helpful to you. If you have any comments or suggestions for improvements, please feel free to share them below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *