Disable expose_php: hide the PHP version in the X-Powered-By header
By default PHP adds the header X-Powered-By: PHP/8.x.y to every response. Automated scanners can therefore see at a glance
whether a website uses a vulnerable version – for example for PHP2Shell. Removing the header takes only
a minute and is one of the basic hardening steps.
Important: hiding the version does not replace updates. It only makes it harder to search for vulnerable servers.
1. In php.ini (recommended)
expose_php = Off
Then restart PHP-FPM or the web server:
sudo systemctl restart php8.4-fpm # adjust the version number
sudo systemctl restart apache2 # with mod_php
expose_php can only be set in php.ini or the server configuration – not via ini_set() or .user.ini.
php --ini or the phpinfo() output ("Loaded Configuration File") shows where php.ini is located.
2. Via .htaccess (Apache, also on shared hosting)
If you cannot change php.ini, Apache can remove the header with mod_headers:
<IfModule mod_headers.c>
Header always unset X-Powered-By
Header unset X-Powered-By
</IfModule>
Both lines make sense because, depending on how PHP runs, it sets the header in different header tables.
3. With nginx and PHP-FPM
location ~ \.php$ {
# ... existing fastcgi configuration ...
fastcgi_hide_header X-Powered-By;
}
If nginx works as a reverse proxy in front of another server, the directive is proxy_hide_header X-Powered-By;.
4. In PHP code
<?php
header_remove('X-Powered-By');
Run this at the very start of the application (e.g. in a central bootstrap file). It is the fallback if you cannot change the server configuration.
Shorten the Server header too
The Server header often reveals versions as well, e.g. Apache/2.4.41 (Ubuntu):
- Apache:
ServerTokens ProdandServerSignature Off(in the server configuration, not in .htaccess) - nginx:
server_tokens off;
Check it
curl -sI https://www.example.com | grep -iE "x-powered-by|server"
Or simply use PHPCheck.net – under "Information disclosure" you can see whether versions are still visible.