How to increase WordPress PHP memory limit (2020)

Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on reddit
Share on email

Let’s say there is no PHP, well then there’s no WordPress.

PHP is used on every WordPress server.So it’s important to keep it fresh and up to date.

Luckily in today’s article, we’ll discuss:

  • What is php and why it’s important
  • How to upgrade it
  • Also, your maximum upload limit and how to increase that as well

Let’s dive right in.

First Let’s define the maximum upload limit and PHP WordPress limit.

PHP (Hypertext Preprocessor) is an open-source language that is specially developed for web development and can be integrated into HTML. With this integration you can jump in and out of PHP mode by enclosing your code in special start (<?php )and end ( ?>) processing instructions.

<!DOCTYPE html>
<html>
    <head>
        <title>Example</title>
    </head>
    <body>
        <?php
            echo "Hi, I'm a PHP script!";
        ?>
    </body>
</html>

The PHP memory limit defines the amount of memory allocated to execute each script on your WordPress website.

Since bad scripts require a lot of resources, the default memory allocation is set low and may need to be adjusted.

Table of Contents

A Few characteristics of PHP

  • PHP is a server-side language that executes code on the host’s server and then displays the HTML to the client.
    • The code is run in the back-end without being available to the front end user.
    • This makes server-side scripting languages like PHP relatively more secure than client-side scripting languages like HTML.
  • Above all, it’s easy to use.
    • And its advanced technical ability makes it suited for both beginners and advanced users alike.
  • Application of PHP cover areas such as using protocols, databases, text processing, databases and of course web development.
    Hence the reason why it is found on all WordPress websites.

Why there is a memory limit in WordPress.

The PHP memory limit is a “safety net” that makes sure that poorly written scripts fail to run on your server.

The default size for most websites using WordPress is 32MB. Which is often increased due to genuine plugin or script needs.

One of the bad things about PHP is that it does not share resources so, In other words, PHP is not multithreading technology.

Instead, each script separately occupies the memory set by the server. So if you are running 3 scripts side by side consuming 100MB each. They will not share 100MB they will individually consume 100MB totaling 300MB.

Through these processes collectively eating up the memory, you will want to increase the limit. And, normally 128MB is enough for most websites unless there is a high memory demanding plugin.

When you need to increase the PHP memory limit.

source:wp beginner

So you’d get an error message like: “Fatal error: Allowed memory size of ‘x’ bytes exhausted” and “x-file.jpg exceeds the maximum upload size for this site”. These are the first signs you will see that you will need to increase the PHP memory limit.

But don’t worry. The next thing you’d do is test which plugin is using up space.

Using a plugin called Server IP and Memory usage Display plugin will show you the amount of memory each plugin is using to execute commands.

From this, you can see which are resource hungry. Now, before you go ahead and jump to increase the memory (We will discuss that later on). It’s always wiser to find low memory alternatives before the limit is increased.

Why is this important?

Well, while getting rid of heavy plugins does not automatically increase the php limit. Doing this can kill the need for increasing the limit in the first place. And that’s a win.

The next huge thing to look at is PHP version.

Statistically speaking, only less than 1% of websites are using the most current update of PHP and more than 50% of websites are running PHP that is not receiving any more updates.

This is both a security and speed issue, as outdated PHP versions pose the risk of more cyberattacks and execute a significant, more requests per second. In many cases, it is easy to update your WordPress version on your server.

So reach out to your hosting company and they should provide you with help. If they are unable to upgrade the PHP then consider switching hosting providers.
And you could always let us do it for you.

What is the maximum upload limit in WordPress?

The max upload limit dictates the maximum file size for any media that you upload to your site.

And this, like the PHP memory limits, is server-side and serves as a safety limit to ensure that you are uploading files that are not too large.

Why is this important?

Large files make a slow site and cost more money to buy resources.

source: kinsta

While adding more memory is the automatic secondary thought here.

It is again, wise to assess your media before you upload it, and ensure that they are fully compressed and optimized. And with that being said. If you choose to increase the limit anyways, then you may run the risk of having large files on your server and that makes it perform poorer than it ought to.

You don’t want that. But, that’s not to say that increasing memory is a bad thing. However, you want to only do that when there is no other way or possible solutions left to try

Here is how to increase PHP memory limit and Maximum upload limit

By using your host’s support

If you don’t know what you are doing. Then relying on your host’s support is the safest bet.

SiteGround has stellar support and will be happy to help you with any technical related problems.

Their shared hosting platform keeps you up to date with the latest PHP technology so not only will you be secure but you are guaranteed to be always getting the best speed available.

If you are using another host, that’s fine just ensure that you contact them first if you do not know what to do.

Siteground hosting

Using your host’s support is a fail-safe method that guarantees your host’s liability for your website’s well-being. They will be able to fix your site if it goes down unexpectedly during the process and also diagnose to see if increasing the PHP or memory limit is the best option.

With support, you may even find problems that you would have otherwise missed in your initial analysis. In many cases, this is the only option as some hosts do not allow you to access the necessary files to make changes.

This is good for persons who do not want to spend too much time tinkering with the bells and whistles of a website.

Let’s move on to Manually

For this bit, there are three methods available to choose from.

However, it is vital to ensure that you back up your website in order to be able to restore them if something goes wrong. We can do this for you, just purchase one of our maintenance plans.

Increasing upload limit and maximum php limit by editing your wp-config.php file

ftp client

Using a third-party FTP file manager is often the most popular recommendation but for these demonstrations, I will use SiteGround’s inbuilt FTP client.

It doesn’t matter which FTP client you use.

The location of the files that you need to access is relatively the same across all platforms, only differing slightly. And you can find the location easily online by a simple search or going to your host’s resources page.

wp-config.php is one of the key core files that allow your website to function. The information stored in it consists of your credentials along with your website’s name.

This file allows clear contact between WordPress and your database, and it can be used to configure advanced options for WordPress.

Step 1 Select cPanel.

Step 2 Select your file manager and go to the home directory.

Navigate to the public_html folder then wp-config.php

It is very important that you back up your files before editing. Select and edit your file using utf-8 encoding.

Above “/* That’s all, stop editing! Happy publishing. */” insert the following code:

define('WP_MEMORY_LIMIT', '64M');<br>

Alternatively, you may see: /* That’s all, stop editing! Happy blogging. */

Note when you download WordPress for the first time wp-config.php will not be available, it is created in the WordPress setup process.

You can manually create the wp-config.php by editing wp-config-sample.php but do not change the order of the code contained in the file.

functions php

Next is Increasing upload limit using functions.php

Navigate to appearance>functions.php

The location of your WordPress memory limit settings is dependent on your theme so you will have to navigate until you find it.

  • Look for this line in the file
    define('WP_MEMORY_LIMIT', '32M');
  • Increase the limit to 128M which will leave you with the following code
    define('WP_MEMORY_LIMIT', '128M');
  • Save the file and then that’s it! Note that if you still need to improve the memory occasionally, consider one of the previous alternatives as you may end up loading your server unnecessarily.

If the fatal Error message is in your admin area then you need to modify define( 'WP_MAX_MEMORY_LIMIT', ‘64M’ );

Admin tasks use more memory so you will do well by doubling the amount, so you should have

define ( 'WP_MAX_MEMORY_LIMIT', ‘256M’);

Let’s look at Increasing upload limit and maximum php limit by editing your PHP.ini file

If the above method does not work then you can have a go at editing PHP.ini.

This feature is not available for shared hosting providers but cloud hosting platforms like Cloudways allows you the ability to do so.

This feature is not available for shared hosting providers but cloud hosting platforms like Cloudways allow you the ability to do so.

If you do not have access to the file then create one with the name php.ini and upload it to your root folder or, if you are able to access your php.ini file then ensure that the following limits are set to the values below and you should be alright.

memory_limit = 256M
upload_max_filesize = 12M
post_max_size = 13M 

These settings are located in the root folder but you may need research on your host’s forum or resource center to find out where exactly.

If this method doesn’t work, try the next solution below.

And finally Increasing upload limit and maximum php limit by editing your .htaccess file

ht access plugin

If you are not able to access your PHP.ini file

Then, your final option is to edit your .htaccess file. First of all, you can use a plugin called Htaccess Editor to do this.

If you choose to use FTP then please note that it is a hidden file (WordPress files that start with a dot are hidden).

So, if you do not see it. Ensure that your FTP or SFTP file manager is not keeping those from view being viewed by you.

Then all you have to do is
Increase PHP and upload memory by using

php_value memory_limit 256M
php_value upload_max_filesize 12M
php_value post_max_size 13M

This should solve all the issues.

If the limit had already been set above then edit it to suit your needs.

note: the .htaccess file may also be unavailable to you on a shared hosting so you will need to contact your host provider for help.

Here’s how you can update your PHP version to solve the problem

PHP 7.4 is the most secure WordPress version to date. With its speed, you’ll be able to execute scripts faster, hence reducing the overall loading time of your website.

source: Kinsta

Step 1: Check your PHP version

Your host contains information about your current PHP version and they often have the tools to allow an update to be made. If you do not want to use your host you can:

  • Use the Display PHP Version plugin
    This is a safe, lightweight plugin and though it has not been tested with the most updated version of WordPress there is no negative review. At best, use it and delete it when you’re finished, it’s that simple
  • Use Query monitor
    Query Monitor is a plugin used to detect high resource plugins on your site. Discard this plugin after use as it uses a lot of resources.
  • Use WP Health
    This plugin ought to show you tips and recommendations for safety and site maintenance. Also, learn more about what everything means by following the tutorials.

With all the checks in place, it’s time to perform the updates.

Step 2: Update your plugins and themes

If you are using a faulty theme and bad plugins then you will get a ton of errors including php memory limit so update them before updating the php version.

Final Step: Update your php version from your host account

Since your host account manages your php version you will have to log in to configure the php version. It’s slightly similar among hosts so find what you can find out on your host’s forum or resources page.

How to change PHP version on SiteGround:

Login to your account
Navigate to “account” tab
Go to the cPanel
Scroll down till you see 1H software
Click PHP version manager
Select your directory that you wish to change (applying this will change the subdirectories as well)

That’s it.

Choose a host that keeps up to date with php versions else you’re going to always have problems. Avoid companies like GoDaddy that requires persons to purchase a new plan to access php 7.3.

source: https://webhostingcat.com/

Pro-Tip Avoid high CPU plugins and poorly coded themes

High CPU plugins will stress your website on top of all the potential problems that can occur.

If you experience a php memory limit error after you’ve installed a plugin on your site then uninstall the plugin and find a safer alternative.

“65 WordPress plugins that slow down your website”

If you think the theme is the problem then activate the default theme and see if the error is resolved.

Genesis Framework, by StudioPress designs lightweight, premium themes that are optimized for speed, security, and SEO.

If you still need help, Sitepact handles technical difficulties

Sitepact Maintenance Plan pricing

The truth is, fixing fatal errors in WordPress is not the only issue you will encounter.

As WordPress is the largest CMS platform on the planet, you are bound to have problems popping up.

Preventing these errors only comes from the knowledge and experience you gain over the years of managing and maintaining websites.

This is why it is important to know what you are doing. And that’s where we can help.

Sitepact offers premium site care and maintenance for all WordPress website types.

Sitepact pricing and features

Our benefits include:

  • Saving time so you can make more money
  • Preventing these common WordPress errors
  • Monitoring your website health
  • Optimizing your website’s performance in security, speed, and SEO.
  • And much more

This is for you if:

  • If you do not have the ability to troubleshoot on your own
  • And need the extra resources

We will do the heavy lifting for you. Then you can just focus on improving the value that you bring to your customers.

Contact us right away.

And Good luck 😉

5/5
Danielthewriter

Danielthewriter

Creative Writer | Freelancer | Author I would like to hear your feedback. So leave a comment below.

Leave a Reply