Ubuntu – which is correct php.ini file to use in apache2


Running 16.04, Lamp stack setup and running OK.
Have several versions of php shown in /etc:

and /etc/php/7.2/apache2/php.ini

Similar situation exists for /etc/php/7.0/cli/php.ini and so on.
In a terminal window, the output of

php -i | grep 'php.ini'


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

Loaded Configuration File => /etc/php/7.2/cli/php.ini
So I gather that running php at the command line is using php version 7.2

My info.php file (http://localhost/info.php shows that apache2 is using php version 7.0:

PHP Version 7.0.27-1+ubuntu16.04.1+deb.sury.org+1
How do I get apache2 to use php versioin 7.2?

Best Answer

You can enable a different mod_php for apache2. Try

$ a2enmod php7.2

This should disable previous versions and create /etc/apache2/mods-enabled/php7.2.conf with proper php.ini location.

If you don't have this mod, run $ apt-get install libapache2-mod-php7.2.

Keep in mind that you need to restart apache2 to see changes in loaded modules.

Related Question