I am trying to automate the configuration of opcache in php7.2.
I have a long winded script the configures the entire server, but i'm struggling to get something working to edit php.ini.
I've tried the answers found here: Change php.ini values from shell script, but i'm not using vagrant, and the dot in the filenames is preventing me from using the settings as bash variables.
AKA this doesn't work
opcache.enable=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=12
opcache.max_accelerated_files=16000
opcache.max_wasted_percentage=5
opcache.validate_timestamps=1
opcache.revalidate_freq=2
opcache.save_comments=0
opcache.enable_file_override=1
opcache.error_log=/var/log/php-opcache.error.log
opcache.log_verbosity_level=1
for key in opcache.enable opcache.memory_consumption yadda yadda
do
sed -i "s/^\($key\).*/\1 $(eval echo \${$key})/" php.ini
done
For obvious reasons, you can't just do this at a command prompt
my.variableproperty=1
You CAN do this, but its not what I need
my_variableproperty=1
I have sed with -i and awk available, as well as any other command can be added if needed. This is an Ubuntu 18.04 VM with php7.2 built on Azure.
Well, I guess I can do this:
sed -i s/opcache.enable=1/opcache.enable=0/g php.sh
But it seems really clunky. I mean, I guess the opcache.enabled string will be in the file, but what if it isn't? Also, what if opcache.enable doesn't have a default value?
Also, this seems to work somewhat well:
sed -i 's,^opcache.enable.*$,opcache.enable=1,' php.ini