3

This is not a question about a current problem but more of a "preventive medicine" question:

I have the following code which is part of a much larger scrip I use to rise up Nginx environments on Debian-oriented systems:

sed -i 's/post_max_size \= .M/post_max_size \= 200M/g' /etc/php/7.0/fpm/php.ini
sed -i 's/upload_max_filesize \= .M/upload_max_filesize \= 200M/g' /etc/php/7.0/fpm/php.ini
sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g" /etc/php/7.0/fpm/php.ini
/etc/init.d/php7.0-fpm restart && systemctl restart nginx.service

This piece of code is the only one from the whole scrip which isn't version agnostic. I find this fact a tiny bit "disturbing" because I might run the script a year or 5 years from now with version 7.0 intact and that's likely to cause errors.

Do you think regex is good enough to make the above code version agnostic? Maybe there's a better way?

Arcticooling
  • 119
  • 1
  • 14

1 Answers1

3

Use a symlink.

ln -s /etc/php/7.0 /etc/php/current
ln -s /etc/init.d/php7.0-fpm /etc/init.d/phpcurrent-fpm
sed -i 's/post_max_size \= .M/post_max_size \= 200M/g' /etc/php/current/fpm/php.ini
sed -i 's/upload_max_filesize \= .M/upload_max_filesize \= 200M/g' /etc/php/current/fpm/php.ini
sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g" /etc/php/current/fpm/php.ini
/etc/init.d/phpcurrent-fpm restart && systemctl restart nginx.service
bviktor
  • 756
  • 5
  • 12