Easy-peasy way to modify php.ini file using sed command

I often want to modify the php.ini file for many purposes, like increasing upload maximum size, memory limit, maximum execution time and so on, usually, I used to modify those just going to the php.ini file and find each of them and do. But that can be easily done with sed Linux command.

The things I want to modify

  • memory_limit
  • upload_max_filesize
  • post_max_size
  • session.gc_maxlifetime
  • max_execution_time
  • date.timezone
  • opcache.save_comments
Find your PHP version and make changes in your command, to find version run the following command 

php --version
 
sudo sed -i "s/memory_limit = .*/memory_limit = 1024M/" /etc/php/7.3/apache2/php.ini && sudo sed -i "s/upload_max_filesize = .*/upload_max_filesize = 256M/" /etc/php/7.3/apache2/php.ini && sudo sed -i "s/post_max_size = .*/post_max_size = 296M/" /etc/php/7.3/apache2/php.ini && sudo sed -i "s/session.gc_maxlifetime = .*/session.gc_maxlifetime = 7200/" /etc/php/7.3/apache2/php.ini && sudo sed -i "s/max_execution_time = .*/max_execution_time = 18000/" /etc/php/7.3/apache2/php.ini && sudo sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/7.3/apache2/php.ini && sudo sed -i "s/;opcache.save_comments.*/opcache.save_comments = 1/" /etc/php/7.3/apache2/php.ini

0 Komentar