How to remove the PHP X-Powered-By header from HTTP response for PHP 8.x apps on Linux App Service
Published Aug 22 2023 02:37 AM 2,551 Views
Microsoft

We can follow the below steps to remove the PHP X-Powered-By header from HTTP response for PHP 8.x apps on Linux App Service –

By default, PHP version is getting displayed as in the below screenshot-

Arjun_Baliga_0-1692696875019.png

 

 Updating PHP Settings-

  1. Go to your KUDU site https://<sitename>.scm.azurewebsites.net.
  2. Select Bash or SSH from the top menu.
  3. In Bash/SSH, go to your "/home/site" directory.
  4. Create a directory called "ini" (i.e. mkdir ini)
  5. Change directories to "ini".
  6. We'll need to create an "ini" file to add our settings to.  In this example, I'm using "settings.ini".  There are no file editors such as Vi, Vim, or Nano so we'll simply use echo to add the settings to the file.  I'm changing the expose_php setting to Off.  Below is the command that I used to add the setting and create an "settings.ini" file if one doesn't already exist.

 NOTE:  If you already have an extensions.ini file, you can use the same command which will add the new setting to the file. 

/home/site/ini>echo " expose_php = Off " >> settings.ini

If using SSH, you can use vi to create/edit the settings file using the following commands.

  1.  vi settings.ini
  2.  Press "i" on your keyboard to start editing and add the following.

 expose_php = Off 

3. Press "Esc", then ":wq!" and enter to save.

Add an Application Setting-

We'll now need to go to the Azure Portal and add an Application Setting to scan the "ini" directory

              1) Go to the Azure Portal (https://portal.azure.com) and select your App Service Linux PHP application.

              2) Select Application Settings for the app.

              3) Under the Application settings section, press the "+ Add new setting".

              4) For the App Setting Name, enter "PHP_INI_SCAN_DIR". For the value, enter "/usr/local/etc/php/conf.d:/home/site/ini"

 

Testing –

Go to kudu site and run the command below and you can verify that PHP header is removed.

CURL -I <site url pointing to a PHP script>

 

Arjun_Baliga_1-1692696875022.png

 

 

Co-Authors
Version history
Last update:
‎Aug 22 2023 02:45 AM
Updated by: