Custom configuration for PHP 7.2 and Ubuntu 16.04

Manage custom PHP settings without breaking the apt-get upgrade process.

I am using WordPress on my Ubuntu machine and require some custom configuration of the PHP environment – but changing the php.ini file directly caused some issues for the apt-get upgrade process as it would stop with the following message:

php.ini: A new version (/usr/lib/php/7.2/php.ini-production) of configuration file /etc/php/7.2/fpm/php.ini is available, but the version installed currently has been locally modified. 

What do you want to do about modified configuration file php.ini?

- install the package maintainer's version
- keep the local version currently installed
- show the differences between the versions
- show a side-by-side difference between the versions
- start a new shell to examine the situation

While this was a nuisance, if I picked the wrong option, I lost my changes. So I found a better way.

I could not find any official documentation for this, but it appears to work the same way as Apache mods and there are numerous unofficial references online, such as How To Enable/Disable PHP Modules on Ubuntu 18.04 & 16.04 which describes this process and the phpendmod, phpdismod, and phpquery commands.

Note that this works for Ubuntu 18.04 and for PHP 7.3 as well.

The PHP configuration is in /etc/php/7.2/, within this are four folders: apache2, cli, fpm, mods-available. Rather than change the php.ini file in the apache2 folder, I created a new file (user.ini) in the mods-available folder to contain my custom configuration.


date.timezone = Australia/Melbourne

display_errors = On
display_startup_errors = On
error_reporting = E_ALL
html_errors = On
log_errors = On

This was then enabled using:

sudo phpenmod user 
sudo service php7.2-fpm restart 
sudo service apache2 restart

A quick check of phpinfo() confirmed that the custom configuration was being used.

Happy coding.


Need help? Let me take care of your IT issues.

Share this page

Scroll to Top