I want to change and add some PHP directives, some for apache, some for CLI and some for both. As an example, I want to set the default timezone for all server contexts. There are a couple of different ways I can go about this, but I don't know which is the best approach.
I can directly edit the master php.ini files, which are here
/etc/php/7.0/apache2/php.ini and here
/etc/php/7.0/cli/php.ini, but I don't know whether this file will be overwritten on upgrade. Also for shared settings, such as the timezone, I have to remember to edit two files and keep those changes synchronised.
I can use Apache's
php_flag directives. The advantage here is that the php settings can be applied on a virtual host by virtual host basis and I can also apply them globally to Apache. However, this doesn't help with the CLI settings.
The php directory has a similar structure to Apache, allowing files full of directives to be enabled or disabled with the
phpenmod command. I can copy this structure, creating the directory
php.ini files within this folder, then creating symbolic links from
/etc/php/7.0/apache2/conf.d/ to my php.ini directive files. This allows me to have a single directive file which adds directives to both Apache and CLI version of PHP. The only thing I can't do with this is virtual host by virtual directives.
Any advice on how to do this properly?