Load Custom Configuration (.ini) in PHP for Azure App Service
Published Jul 18 2023 08:22 PM 3,887 Views
Microsoft

As a PHP developer, sometimes you might want to set the custom configuration file (.ini) to read when PHP starts up. For this article, I would like demonstrate how to load custom configuration file (.ini) in the Azure App Service.

 

By default, we set the PHP_INI_DIR = /usr/local/etc/php/conf.d, so when using SSH on Kudu, you could see there are lots of .ini files:

Joe_Chen_2-1689734386173.png

 

Based on this, you might think we could just manually add our custom .ini files in /usr/local/etc/php/conf.d, but it will not work after restart. Since only "/home" data will be persistent after restarting App Service. So what we need to do is to add our .ini in "/home", E.g. "/home/site/ini"

 

For example, if I would like to modify "upload_max_filesize to 64M (defualt is 2M) and post_max_size to 64M (default is 8M)" for the PHP website, I could follow the below steps to achieve it:

 

Step 1:

Use like vi/vim command to add setting.ini file in the "/home/site/ini" folder

Joe_Chen_3-1689734386176.png

 

Step 2:

PHP supports scanning multiple directories for .ini files. For this we need to set PHP_INI_SCAN_DIR with ":" to separate values on the Application Setting for the target App Service.

E.g. PHP_INI_SCAN_DIR = :/home/site/ini

This ensures that we load *.ini files from  /usr/local/etc/php and then load from /home/site/ini

Joe_Chen_4-1689734386178.png

 

 

After, we check the value by simple php page and it will show upload_max_size and post_max_size are set as 64M now.

Joe_Chen_5-1689734386180.png

 

Reference:

2 Comments
Co-Authors
Version history
Last update:
‎Jul 18 2023 07:54 PM
Updated by: