This tutorial explains how to locate your php.ini
file and change the php memory_limit
setting from the command line.
Prerequisites
Summary
- Locate php.ini file
- Configure php.ini file
- 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_errors
, max_execution_time
, post_max_size
, short_open_tag
, upload_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.