Are you bugged by exhausted memory errors and want to increase PHP memory limit in WordPress? Then read this tutorial which provides you with not one but four ways to rectify the issue. Many recent users who have just converted site to WordPress will be unaware of some unique features of the platform. PHP which is a server-side programming language is a vital constituent of the CMS. Hosting servers require memory to execute multiple applications at once. Server administrators allot specific memory to all applications including PHP. Sometimes the code needs more space than the default memory limit which can cause an error message to be generated. Webmasters trying to upload rich content can also have to encounter upload errors.
Types Of Error Messages Related To PHP Memory Limit
There are different kinds of warning messages that can be generated when a PHP memory limit error occurs. People trying to upload a large file can encounter this alert:
When the default limit gets exhausted, the following message may appear:
Another alert that can flash during such situations is:
Let us now take a look at the methods which can be used to resolve the issue. Make sure you have the latest version of PHP before trying these tactics.
1. Update The php.ini File
When you try to upload a file and receive a warning that it exceeds the limit, you can use this method. First, access your hosting account and go to the cPanel. Another way to access the cPanel is by entering the following URL in a browser:
example.com/cpanel
Replace “example.com” with your domain and you will be taken to a login page. Enter your username and password and you will access the cPanel. Locate the section named “Files” and press the “File Manager” button. Tick the box against the “Show Hidden Files” option and then click the “Go” tab.
Now open the “wp-admin” folder and locate a file named “php.ini” or “php5.ini”. In case you cannot find any such file create one. Hit the “+ File” tab in the top left-hand corner. Enter the file name as “php.ini” and press the “Create New File” tab.
Now open the file and if you cannot open an existing file, rename it to “php5.ini”. After opening the file add the following code to it:
In this code “M” stands for megabytes. You can change the values with this unit in the first three lines to numbers of your choice. The value in the last line (max_execution_time) defines the time in seconds for loading a script. Always remember to increase the value from small to large from the first to the third line. The value in the first line must be the smallest followed by a larger number in the second and finally the largest figure in the third line. Clear your browser cache and try re-uploading the file.
2. Modify The .htaccess File
In case the above method does not resolve the issue, try this one. This process involves modifying the .htaccess file which is a configuration file. It is located in the root folder and dictates to the server how it should manage permalinks, redirects, etc. It is in fact, a short form of the term “Hypertext Access”. The period at its beginning indicates that it is a hidden file. In order to make it visible, you will have to configure the FTP client’s settings when it connects to the website. The image given below shows how it can be done in Filezilla.
You can also do so through cPanel as explained in the previous method. Now you will be able to locate the file. Add the following code to the bottom of the .htaccess file of your website and save it:
Just like we did in the first method, you can change the values to limits of your choice. Clear your browser’s cache and the problem will be solved.
3. Edit The wp-config.php File
Another way to increase PHP memory limit in WordPress is by editing the “wp-config.php” file. It is one of the most important and core files of interfaces built with the CMS. This configuration file is not a part of the default package of the WordPress installation. It is generated specifically for an interface during its installation. This file contains all vital database information and defines some other advanced options. The information in this file allows WordPress to connect with the website’s database. It is impossible to make an interface function without this vital data. In case, this information is absent, users trying to access the website will see the database connection error.
Locate this file in the root folder and open it. Find the line in the code highlighted in the image given below.
Add the following line of code just before the highlighted line:
define(‘WP_MEMORY_LIMIT’, ‘3000M’);
Now save the file and clear your browser’s cache and the issue will be resolved.
4. Change Limits In The Web Host Manager
This method can be used only for websites hosted on dedicated servers or Virtual Private Servers (VPS). Such website owners can access the Web Host Manager (WHM) in their account. They can use their username and password to log in to the WHM. Once you have logged in successfully, locate the “Server Configuration” section. In the menu, find the “Tweak Settings” option and click on it. On the screen which opens now locate the “PHP” tab. In case, it is not visible try clicking the navigation arrows to see all the tabs. Press the tab to open its settings screen. Here you can define the desired maximum upload size and post size. You can also set the execution time in seconds. Hit “Save” after making the configurations.
You will now have to access the “PHP Configuration Editor” in “Service Configuration” section. Then locate the options for “memory_limit” and “upload_max_filesize” in the “Core” sections. Enter accurate values in both fields.
Update “max_execution_time” to the same limit you specified in methods 1 and 2. Press “Save” and clear the cache of the browser.
Conclusion
It is essential to know the ways to increase PHP memory limit in WordPress or else you will continue to encounter irritating error messages. In case, the above methods do not work, contact your hosting service or an expert for help.
Leave a comment