Correct way to modify php.ini for Apache and/or CLI
FYI, configuration files in /etc/
installed by a package are not overwritten by default; on upgrade if a file changes a prompt is presented with options.
Coming back to the original question, here is how I would do it:
Create a config file
/etc/php/7.0/mods-available/50-mydirectives.ini
and do common configuration there; then usephpenmod mydirectives
to enable it.Do
apache
andcli
specific configuration in/etc/php/7.0/apache2/conf.d/
and/etc/php/7.0/cli/conf.d/
respectively.Do virtualhost specific configuration in the virtualhost itself.
With the above configuration will not need to edit system provided php.ini
.
Related:
- https://stackoverflow.com/questions/13383806/what-the-ini-files-in-etc-php5-conf-d-folder-are-for
- https://duraturk.wordpress.com/2014/04/27/php5enmod/
Related videos on Youtube
Dom
Updated on September 18, 2022Comments
-
Dom over 1 year
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_admin_value
,php_admin_flag
,php_value
andphp_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/etc/php/7.0/mydirectives
, placingphp.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?
-
muru over 6 years
phpenmod
can enable configs for just a given SAPI if you use-s
option, so even FPM or CLI specific config can be kept in/etc/php/7.0/mods-available/
and enabled per-SAPI.