Monday 16 July 2018

Why My php.ini Changes Weren’t Taking Effect

Why My php.ini Changes Weren’t Taking Effect

Today I needed to change a PHP directive in my php.ini file after needing to increase the maximum POST size allowed. The directive that needed changing was ‘post_max_size‘ from 8MB to 24MB.
As a bit of a background before I begin, the server is a 1and1 dedicated server and is running Centos as the operating system.
FINDING THE PHP.INI FILE – ATTEMPT ONE
To find out where the php.ini file resided, I ran the following command:
  1. php -i | grep php.ini  
Let’s break this down into it’s two bits:
php -i – Calls phpinfo() and returns the results.
grep php.ini – The output of ‘php -i‘ is piped (ie passed into with the ‘|’ character) into a grepcommand which searches for a particular string. In this case we’re searching for the string ‘php.ini‘.
The output was as follows:
  1. Configuration File (php.ini) Path => /etc  
  2. Loaded Configuration File => /etc/php.ini  
From the above output, we can see that the php.ini file being loaded is located in the directory ‘/etc/‘, so I headed over to this folder and edited this php.ini file. I found the post_max_size directive, changed it and saved the file.
TESTING THE CHANGES
Once I’d saved the file I was ready to test it. The reason for increasing the post_max_sizelimit was because a form on my site kept producing a fatal PHP error when submitting a large amount of data. If I was now able to submit the form successfully I would know the changes had worked.
Unfortunately, I still got the same fatal error coming back and oddly, the error was still claiming that the limit was set to 8MB.
RESTARTING APACHE
I’d seen some forums claiming that for the changes to take effect I needed to restart the Apache service. I tried this by running the command below:
  1. apachectl restart  
Alas, the problem still remained when testing the changes again. This got me thinking; maybe there are multiple php.ini files and I’m editing the wrong one. There was only one way to find out…
FINDING THE PHP.INI FILE – ATTEMPT TWO
To find out if another php.ini file existed on the server I performed a search for the filename like so:
  1. find / -name php.ini  
By running the above we can search the entire server for a file of a particular filename. This came back with a couple of results, with one in particular that caught my eye belonging to the site in questions folder (ie /var/www/vhosts/mysite.com/etc/php.ini).
I now went into this newly discovered file and updated the post_max_size setting in there, saved it, and got ready to test again.
TESTING THE CHANGES
By submitting the troublesome form I was instantly able to tell that this time the changes had taken effect. There was no need to restart Apache, I got no fatal errors, and the form submitted successfully.
SUMMARY
I was curious as to why there might be multiple php.ini files so I did a little research into it. Turns out that it’s beneficial so that each site on the server can have it’s own set of directives. Seems to make sense, I just wish I knew this before going round the houses and making changes to the wrong files.

0 comments:

Post a Comment