As a software application running on the server, WordPress takes up a certain amount of memory. In most cases, users will not have to worry about overstepping these limits. Being one of the most commonly run web applications on the Internet, server configurations in both shared as well as dedicated hosting plans are usually more than sufficient to take care of WordPress’s everyday needs. But sometimes a little bit of tweaking is required when a WordPress installation bloats to such an extent that it can’t run properly anymore. Some of the activities necessitating an increase in the amount of memory used by WordPress include loading a large number of plug-ins, and uploading huge files via the WordPress interface.
For situations like this, we need to know how to increase the amount of space allotted to WordPress. But there are some limits – in a shared environment specially, hosts place an upper limit on the amount of memory it is possible to allocate. But at least we can try and hit these limits. There are two distinct ways to attempt to do this – we can define WordPress’s memory limit from within wp-config.php, or we can try and achieve it via a php.ini file. Let’s look at both options below.
Increasing the Limit via wp-config.php
Before you increase the memory limit of WordPress, it’s useful to know how much is already allocated. I’ve already written earlier on how to check for WordPress variables using the phpinfo function. But some hosts don’t allow you to run that command. So you can try and find out the memory allocation by navigating to the following PHP file in your WordPress installation:
Under the function called “wp_initial_constants”, you see the various memory limits set up by default:
So let’s assume that your current memory allocation is 40 MB with it not being a multisite installation. We want to increase this limit to say 96 MB. To do this, open up your wp-config.php file in your WordPress root directory, and copy and paste the following line:
define( 'WP_MEMORY_LIMIT', '96M' );
The “WP_MEMORY_LIMIT” as shown in this command sets the memory for WordPress alone – it doesn’t affect any other PHP application on the server. This technique is the preferred way to overcome memory limits. After all, you don’t want to affect any other programs or anyone else running in a shared hosting environment.
Changing PHP Variables
If the above technique doesn’t work, we need to modify the PHP environment itself. But before fiddling around with php.ini files, let’s try and do this via the cPanel interface itself – why run the risk of messing something up if we already have a nice GUI to do the job for us?
This will depend on your host’s cPanel installation. At SiteGround for example, they have a separate “PHP Variables Manager” under the “1H Software” section as shown below:
Once in, choose your WordPress installation folder to specify which sub directory the new PHP changes should apply to. If you have several applications running, make sure you choose the right one so as to not affect the others. When you click on a folder, you’ll be shown a screen asking you to specify which environment variable you want to create/modify. As shown in the screenshot below, you’ll get a drop-down of PHP variables as you start typing – very convenient to ensure that you don’t make spelling mistakes!
Choose your PHP variable and click “Add”. The next step is to add a value next to the variable you just created. In this case, 96M.
Save your changes and that’s it. If your host allows WordPress to take up that much amount of memory, you should be all set. But what if your cPanel installation doesn’t allow you to change PHP variables like this? Well in that case you simply have to create the php.ini file yourself. Open up a blank file in Notepad and rename it to “php.ini”. Inside it, enter the single following line:
memory_limit = 96M
Save it and upload this file into the root directory of your WordPress blog. You can see below in my installation screenshot that I have 128M allocated.
One of these three solutions should definitely work for you if you come across insufficient memory errors in WordPress.