How to change PHP memory limit in php.ini file?

This tutorial explains how to locate your php.ini file and change the php memory_limit setting from the command line.

 

Prerequisites
  • Apache2 webserver must be installed on your system.
  • PHP must be installed on your system.

 

Summary
  1. Locate php.ini file
  2. Configure php.ini file
  3. Restart Apache2 webserver

 

1. Locate php.ini file

Firstly, you need to locate your php.ini file. Different Linux distribution store php configuration files in different directories so you can lookup the php.ini file in your php configuration if you are not sure where the file is located.

Command: php -i | grep php.ini

In our case the php.ini file is located in /etc/php.ini.

 

2. Configure php.ini file

2.1. Edit your php.ini file using a text editor.

Command: nano /etc/php.ini

 

2.2. Next, find the memory_limit settings in the php.ini file. You can search the contents of the php.ini file by pressing the Ctrl + w combination on your keyboard while editing the php.ini file. Then, change the php memory limit value to the desired value in megabytes (M). Now save changes and exit the text editor.

For example: memory_limit = 256M.

Note: You will notice many other commonly used php settings in the php.ini file, which you can modify according to your needs, such as log_errorsmax_execution_timepost_max_sizeshort_open_tagupload_max_filesize.

 

3. Restart Apache2 webserver

Finally, you need to restart your Apache2 webserver for changes to take effect.

Command: systemctl restart httpd.service

 

Conclusion

You have successfully located the php.ini configuration file and changed the php memory_limit setting.

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.