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.

I have found three different php.ini files (no idea why there are three) this is how I found the files

$ sudo find / -name php.ini

I also did....

$ sudo php -i | grep 'Configuration File'
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 was still only 2M

I tried rebooting my computer thinking maybe that would 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?

  • 7
    the 'correct' one is in the apache2 subdirectory
    – Joren
    Oct 12, 2013 at 0:21
  • 3
    use updatedb; locate php.ini instead of find.
    – sjas
    Aug 13, 2015 at 9:46
  • @Michael The file is /etc/php/5.6/apache2/php.ini in Ubuntu 16.04 LTS Xenial Xerus, where 5.6/ is the version of php installed. First copy the file to php.original.ini then open for editing with sudo gedit /etc/php/5.6/apache2/php.ini Jan 9, 2017 at 11:21

7 Answers 7


The three files you have there are each meant for different uses.

/etc/php/5.6/cli/php.ini is for the CLI PHP program, which you found by running php on the terminal.

/etc/php/5.6/cgi/php.ini is for the php-cgi system which isn't specifically used in this setup.

/etc/php/5.6/apache2/php.ini is for the PHP plugin used by Apache. This is the one you need to edit for changes to be applied for your Apache setup which utilizes the in-built PHP module to Apache.

/etc/php/5.6/fpm/php.ini is for the php5-fpm processor, which is a fastcgi-compatible 'wrapper' for PHP processing (such as to hand off from NGINX to php5-fpm) and runs as a standalone process on the system (unlike the Apache PHP plugin)

For versions of Ubuntu lower than 16.04, /etc/php/5.6/,/etc/php/7.0/,/etc/php/7.1/, and so on, are replaced by /etc/php5/ and so on. Otherwise, these paths remain accurate. Adapt this accordingly for your environment, replacing the 5.6 or number with the actual version folder that exists on your environment.

  • 2
    php.ini is not found in /etc/php5/apache2 directory. but it is available there in cli directory.
    – Anuj TBE
    Jun 5, 2015 at 6:15
  • 2
    @anujsharma9196 The only reason that would be the case is if you aren't using the Apache built plugin for PHP. The file paths still work as is listed here to this day (confirmed on my 15.04 VM)
    – Thomas Ward
    Jun 5, 2015 at 10:53
  • 1
    And if you have several version of PHP installed, check the active one with ll /etc/apache2/mods-enabled/php* which will give you a hint about the version.
    – Matthieu
    Mar 27, 2020 at 12:08
  • Yes but what is the command to restart php - it isn't just sudo service apache2 restart...
    – NoBugs
    Dec 23, 2020 at 6:38
  • That's a different question @NoBugs. And that varies based on how PHP is installed (Apache plugin or FPM or CGI installation of PHP components all use different restart calls)
    – Thomas Ward
    Dec 23, 2020 at 6:50

To find which php.ini the CLI is using you can run:

php -i | grep 'php.ini'

Example output:

$ php -i | grep 'php.ini'

Configuration File (php.ini) Path => /etc/php/7.0/cli
Loaded Configuration File => /etc/php/7.0/cli/php.ini
  • 1
    This should be the accepted answer! Jul 4, 2018 at 13:49
  • 4
    This is good, but will give the cli loaded configs for php only. To get the apache loaded configs it need to do the phpinfo() on a web page.
    – Dipu Raj
    Jul 9, 2019 at 6:16
  • What is the use of php -i and what is the use of grep command. Would you please add the in explanation that would be good. Jun 15, 2022 at 6:45

Try running a script containing this snippet in your browser <?php phpinfo(); ?> and then try to search for something like Loaded Configuration File. This entry specifies the php.ini your PHP uses in your Apache server.


for php7 ubuntu 16.4

  • 2
    I am missing that file. Which package is providing that file?
    – galmok
    Sep 7, 2016 at 7:21
  • is for php7 on ubuntu 16.4
    – Softmixt
    Oct 3, 2016 at 7:04

You can find the file being used by running this on terminal:

php --ini

just use <?= phpinfo() ?> and read :

Loaded Configuration File


I am on LAMP stack on Amazon Lightsail and the location of the correct php.ini file for my Ubuntu server is:


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .