1

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

/etc/php/7.0/apache2/php.ini, /etc/php/7.1/apache2/php.ini, 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'

is

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?

1
  • At times different php.ini files are used for apache and the command line as you have observed! Feb 20, 2018 at 17:31

2 Answers 2

2

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.

5
  • Thanks, I did run the code above, and this was the output: (Reading package lists... Done Building dependency tree Reading state information... Done libapache2-mod-php7.2 is already the newest version (7.2.2-3+ubuntu16.04.1+deb.sury.org+1). libapache2-mod-php7.2 set to manually installed. ) Not sure of how to "manually install"
    – Henry Hall
    Feb 20, 2018 at 20:41
  • @HenryHall That just means it's already installed and set to not be uninstalled when its parent package is removed. What did a2enmod php7.2 output?
    – Somrlik
    Feb 20, 2018 at 23:45
  • If one uses a2enmod php7.2 is it necessary to also use a2dismod php7.0? In other words, should the existing php7.0 be disabled if php7.2 is to be enabled?
    – Henry Hall
    Feb 21, 2018 at 0:31
  • Just saw your comment. I've lost the output of the original a2enmod, when I run it now I get $ a2enmod php7.2 Considering dependency mpm_prefork for php7.2: Considering conflict mpm_event for mpm_prefork: Considering conflict mpm_worker for mpm_prefork: Module mpm_prefork already enabled Considering conflict php5 for php7.2: Module php7.2 already enabled
    – Henry Hall
    Feb 21, 2018 at 0:33
  • @HenryHall If you run a2dismod without any arguments you will see a list of enabled modules. If there are both phps, disable the old one and sudo service apache2 restart.
    – Somrlik
    Feb 21, 2018 at 0:45
1

Check your apache config to see what modules apache is loading. You should look for a line like this:

LoadModule auth_basic_module modules/libphp7.so

And change it to the php module you want to use. Something more like this:

LoadModule auth_basic_module modules/libphp72.so

Of course this assumes that you have the php module inside apache's modules directory.

You can also specify a certain php.ini for apache to use.

2
  • Did it! I ran sudo a2dismod php7.0 and got this: $ sudo a2dismod php7.0 Module php7.0 disabled. To activate the new configuration, you need to run: systemctl restart apache2 then restarted apache2, re-created phpinfo.php, and now I'm using php7.2! Victory is sweet. Thanks so much for the help, could not have done it otherwise.
    – Henry Hall
    Feb 21, 2018 at 0:55
  • You were right, in file /etc/apache2/mods-available/php7.2.load is the line LoadModule php7_module /usr/lib/apache2/modules/libphp7.2.so
    – Henry Hall
    Feb 21, 2018 at 0:58

You must log in to answer this question.

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