Local php.ini Settings aren’t Working or Loading in Apache

Recently while working for a client’s web host, I had the trouble that local php.ini changes weren’t taking effect. I had already created a custom php.ini file in the user’s home directory and set rules. But these local php.ini settings were not working at all.

Apache server wasn’t loading the php.ini configuration file for the user. As a result, the settings were completely ignored. I’ve managed to fix that. If you have the same trouble then here I will tell you how to rectify this.

Local php.ini Settings aren't Working

The Order of Loading php.ini Settings

First of all, you have to identify the working php.ini settings including the local one. In this step by step tutorial, we will first identify which PHP configuration files are loading. By default, PHP directives take effects in the following order.

  • Global or root’s php.ini file that comes with the installed PHP version
  • A file set up by the server control panel software
  • The custom configuration in the user’s home directory
  • Local file in the domain’s document root
  • In the same directory where the PHP file resides
  • Using the ini_set() function at runtime

So here you see that any directive defined in the later file can override the same from the former one. However, there might be multiple PHP versions installed in your hosting account. Further, you might have the capability to specify PHP executable version per domain or website. Refer to this article to know the two ways to perform the same.

Thus it’s better to know which local as well as master PHP settings files are taking effect. It will also help us to create correct and working configuration files.

Identifying the Effective PHP Configuration Files

It’s time to write and run a line of code. Write phpinfo(); in a PHP file and access this file in the browser. You will come up with the information about Apache and PHP in your system.

The Local Value column displays values from the user’s ini file while Master Values contains values form the global file. Further, the local value displays one from the master if it doesn’t exist in the custom one.

Since Apache is ignoring our PHP ini settings, let us first look at configuration path and loaded files. Search for rows “Configuration File (php.ini) Path” as well as “Loaded Configuration File”. The first one is the file that came with Apache and PHP. While your control panel software (cPanel, Plesk) loads its own php.ini file as shown in the second term.

So you have gotten the file. You can change the necessary directives in the loaded configuration file if have access to it. Otherwise, we should try to load the local php.ini file. Also, not sure but the loaded configuration file might change in the future with updates as well.

Making Local php.ini Settings Working in Apache

Well! It’s not always the php.ini file that loads. PHP has the setting to rename the user-defined configuration file. Look for the directive “user_ini.filename” on the PHP information page in the browser.

Local PHP ini not Loading

Instead of “php.ini”, there might be “.user.ini” provided. it means PHP will look for custom configuration in files named as “.user.ini”. So either you rename local php.ini to .user.ini or set “user_ini.filename” directive to “php.ini”.

Now Apache will load user-specific local ini file for PHP. You can verify the same by reloading PHP information on the browser. Just remember to delete phpinfo(); function or the file from your hosting account afterward.

Additionally, give attention to “user_ini.cache_ttl” directive as well. PHP caches the configuration and avoids re-reading until the cache expires. The value is measured in seconds. 300 seconds means 5 minutes. So either wait or reboot Apache if immediate changes don’t work.

Changing Local or User php.ini to Take Effect

So You have come to know why were PHP settings ignored. Now the local php.ini settings started working after changing the file name. PHP information and configuration are quite helpful utility. I have almost modified more than 25 directives to let Apache and PHP effectively work.

For example, “extension_dir” is one such useful directive. I have set up the PHP extension for Redis using this. Finally, hope you have fixed local php.ini settings aren’t working issue in Apache. If this article is helpful then don’t forget sharing and commenting.

You Might Interested In

Leave a Reply