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.
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 ln -s /etc/php/7.2/mods-available/user.ini /etc/php/7.2/fpm/conf.d/20-user.ini
sudo ln -s /etc/php/7.2/mods-available/user.ini /etc/php/7.2/cli/conf.d/20-user.ini
sudo ln -s /etc/php/7.2/mods-available/user.ini /etc/php/7.2/apache2/conf.d/20-user.ini
sudo service php7.2-fpm restart
sudo service apache2 restart
A quick check of phpinfo() confirmed that the custom configuration was being used.