Changing php.ini with code in a LEMP stack on Debian systems This is how I establish a Debian LEMP and use code to change php.ini directives, as part of php-fpm. 

Please review the way I change php.ini. I believe my approach here is bad because I edit a conf file directly instead overriding somewhere.

apt-get upgrade nginx mysql-server php-fpm php-mysql php-mbstring php-mcrypt -y
sed -i "s/post_max_size = .M/post_max_size = 200M/ ; s/upload_max_filesize = .M/upload_max_filesize = 200M/" /etc/php/*/fpm/php.ini
sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/*/fpm/php.ini
By doing ad hoc editing like that, you're making certain assumptions about what the php.ini configuration currently looks like.  For example, you have assumed that the size limits end with M, and that those lines are not commented out.  You have also assumed that the cgi.fix_pathinfo line is commented out.

There are two better ways that I prefer.


The simple solution is to put all of the local overrides together in one file.  From the PHP manual:


  Within each directory, PHP will scan all files ending in .ini in alphabetical order.


So, instead of editing, simply create a file with a name like /etc/php/7.0/fpm/zz_overrides.ini containing four lines:

[PHP]
post_max_size = 200M
upload_max_filesize = 200M
cgi.fix_pathinfo = 0


This has the benefit that you leave all of the distro-provided configuration files in their pristine state, and won't need to merge your changes when upgrading.  The disadvantage is that you will need to keep in mind where to look for the effective settings — but that's not hard if you make it a habit.
Alternatively, use augtool, which is a configuration file editor, as in this example.