Sometimes while in development or production, we find that our software uses more memory than we ever expected. To keep things under control, PHP has default memory limits to avoid some runaway program from crashing your box.
Luckily, it is extremely easy to change how much RAM we allocate toward a single PHP script. We can even let PHP use an infinite (or all that’s available, to be more precise) amount of memory.
Really, there are only two simple steps to getting this done so you can move on with your life.
1. Find Your php.ini
For example, in Ubuntu:
- Command line: /etc/php5/cli/php.ini
- Apache: /etc/php5/apache2/php.ini
Note: On shared hosts, you may not have access to these files. So, you need to get in touch with your hosting provider and ask them to increase it for you.
2. Edit Your “memory_limit”
The line you are looking to edit is called the memory_limit. It will look similar to the following:
1 |
memory_limit = 64M |
In this example, the memory limit is set to 64MB. If you wanted to change it to 128MB or 32MB or whatever, you just need to change this line. Once you have this line set appropriately, save and exit your php.ini file.
For web servers (!): If you’re changing a web server’s php.ini you must restart the web server. For example on Ubuntu with Apache, you would need to run:
1 |
sudo service apache2 restart |
After that, your memory limit should change accordingly.
Setting the PHP “memory_limit -1”
To accomplish this just set the memory limit to -1 like this:
1 |
memory_limit = -1 |
- Are You StartUp? You Must Have Referral Program - September 12, 2023
- How to Fix 403 Error in WordPress? - September 5, 2023
- Understanding Domain for Your Website - August 29, 2023