Increasing PHP's memory limit

Setting A New Limit

By default, PHP will limit itself to using 128MB, which may be exceeded depending on your tasks. In some cases, it's easy to pass along a new memory limit to one-off commands using the following command, replacing -1 with the new memory limit (e.g 512M, 1G. -1 will remove any memory limit and could result in consuming all the memory):

php -d memory_limit=-1 <command>

Sometimes, this isn't an ideal solution, and the memory limit should be persisted throughout the job. In this instance, it's easy to set a new memory limit by creating a new memory limit configuration file using the following command, which will ensure PHP runs with the increased memory each time it executes (again, replacing -1 with the actual limit you would like):

echo 'memory_limit = -1' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini

Alternatively, if you receive a permission denied error with the above command, the tee command may be necessary to append the configuration:

echo 'memory_limit = -1' | sudo tee -a /usr/local/etc/php/conf.d/docker-php-memlimit.ini


Additional Resources

Was this article helpful?
11 out of 22 found this helpful



Article is closed for comments.