25

I am currently trying to locate the correct php.ini file to edit it and restart Apache, so the changes will take place and I'm stumped.

What I have done...

I have found three different php.ini files (I don’t have any idea why there are three). This is how I found the files: sudo find / -name php.ini. It resulted in the following....

/etc/php5/cli/php.ini
/etc/php5/apache2/php.ini
/etc/php5/cgi/php.ini

I also did....

sudo php -i | grep 'Configuration File'

This showed....

Configuration File (php.ini) Path => /etc/php5/cli
Loaded Configuration File => /etc/php5/cli/php.ini

I changed all of them (just to be sure) to the settings I wanted.

I restarted Apache using:

sudo service apache2 restart

The results...

* Restarting web server apache2

I reloaded the page and it showed that the php.ini file was not updated.

I know this because I used

echo ini_get('post_max_size');

Which was supposed to be changed to 20M, but it was still only 2M.

I tried rebooting my computer thinking maybe that would legit stop the Apache server and reload the php.ini file with the correct setting, but alas that attempt also failed.

Is there any chance there could be another php.ini file that could be interfering?


A better, more helpful for other users answer can be found here: Find the correct php.ini file

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Michael
  • 495
  • 1
  • 11
  • 29
  • Have you changed value & Checked using ini_get() function in all php.ini files one by one? – Jenson M John Oct 12 '13 at 15:22
  • 1
    I'm not sure how to check different php.ini files using the ini_get() function, but yes I have done ** echo ini_get('post_max_size'); ** . Which prints the default value (which should have been changed to 20) – Michael Oct 12 '13 at 15:34
  • Have you edited the `php.ini` file which is shown in the webpage by `phpinfo()`. You must do this by `sudo`. – srain Oct 12 '13 at 15:39
  • Find `post_max_size` in the phpinfo page, is it still `2M` after you changed the value in `/etc/php5/apache2/php.ini`? Have you set the value in the `.htaccess` file? – srain Oct 12 '13 at 15:45
  • @srain Yes it is still the same (as if I had not changed a thing) and no, I don't even have .htaccess file. – Michael Oct 12 '13 at 16:02
  • I have found a possible solution here http://stackoverflow.com/a/11673121/1653716. Saying basically they had a syntax error in their php.ini file which prevented apache from loading the other non-default values. Do you know if there is an easy way of checking the php.ini for syntax errors? – Michael Oct 12 '13 at 16:29
  • @Michael What I meant was edit only 1 php.ini file one time & see the output using ** echo ini_get('post_max_size'); ** If you're not seeing any change, Revert back to old value, edit 2nd php.ini file, see the output & so on..If none of the file edits shows the change you expected, It does mean (I think) file changes are not being updated Or have you already tried all these? – Jenson M John Oct 13 '13 at 09:53
  • 2
    Please avoid crossposting: http://askubuntu.com/questions/356968/find-the-correct-php-ini-file. – AStopher Feb 19 '15 at 14:05
  • I have read on Stack Exchange Meta that cross-posting is not necessarily a bad thing. It is increasingly more likely that questions will be ontopic at multiple sites as the number of SE sites increases. – mickmackusa Mar 23 '19 at 20:51

3 Answers3

20

As Apache calls PHP by mod_php, the configuration information is not the same with that in command line:

Create a file named index.php at the root directory, with the code below in it:

<?php
    phpinfo();

then open it in your browser: /index.php.

Then you will see all the configuration information.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
srain
  • 8,944
  • 6
  • 30
  • 42
3

Create a PHP file and put the following code in it:

phpinfo();

Open the file in your browser and find loaded configuration file. Presto.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Bryan
  • 3,449
  • 1
  • 19
  • 23
  • I have done this already (first thing I did actually). The results said this "/etc/php5/apache2/php.ini" was the loaded configuration file. I edited it, restarted apache, and still found that the configuration did not change. – Michael Oct 12 '13 at 15:27
3

The answer to this was very simple. Somewhere in my php.ini file I had a syntax error (or an error of some kind).

To fix this, I downloaded the latest php.ini file from http://git.php.net/?p=php-src.git;a=blob_plain;f=php.ini-production;hb=HEAD and then changed the values for upload_max_filesize and post_max_size, restarted Apache, reloaded my php_info() and everything was working as expected!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Michael
  • 495
  • 1
  • 11
  • 29