LINUX, FOSS AND LIBRARY TECHNOLOGY ENTHUSIAST

Saturday, July 4, 2020

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

1 comments
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/; s/upload_max_filesize = .*/upload_max_filesize = 256M/; s/post_max_size = .*/post_max_size = 296M/; s/session.gc_maxlifetime = .*/session.gc_maxlifetime = 7200/; s/max_execution_time = .*/max_execution_time = 18000/; s/;date.timezone.*/date.timezone = UTC/; s/;opcache.save_comments.*/opcache.save_comments = 1/" /etc/php/8.2/apache2/php.ini

sudo systemctl reload apache2 && sudo systemctl restart apache2

1 comment: