How to Increase PHP Memory Limit for Your Website
Increasing the PHP memory limit is a common solution for resolving issues like slow website performance, plugin errors, or WordPress memory exhaustion warnings. This guide will walk you through the steps to increase the PHP memory limit on your website hosted with ReloHost (Pty) Ltd.
Why Increase the PHP Memory Limit?
Many content management systems (CMS) like WordPress, Joomla, and Magento require a certain amount of PHP memory to function properly, especially as your website grows and includes more features or plugins. If the allocated memory is insufficient, you might encounter errors like:
-
"Allowed memory size exhausted"
-
Slower performance
-
Problems activating or running plugins/themes
By increasing the PHP memory limit, you provide your website with the resources it needs to function smoothly.
How to Increase PHP Memory Limit on Your Website
1. Modify the wp-config.php File (For WordPress Websites)
If you’re using WordPress, the easiest way to increase the PHP memory limit is by editing the wp-config.php file.
Steps to Follow:
-
Log into your cPanel account and go to File Manager.
-
Locate the wp-config.php file in the public_html directory (or the root folder of your WordPress installation).
-
Right-click on the file and choose Edit.
-
Add the following line of code just before the line that says "That's all, stop editing! Happy blogging":
This will increase the PHP memory limit to 256MB. You can adjust this number depending on your requirements (e.g., 512M for higher memory).
-
Save the file and check your website to see if the issue is resolved.
2. Modify the php.ini File
If you're not using WordPress or you're looking for a more universal solution, you can increase the PHP memory limit by editing the php.ini file.
Steps to Follow:
-
Log into cPanel and open the File Manager.
-
Look for the php.ini file in the root folder of your website or public_html directory. If you don’t find it, create a new one.
-
Open the php.ini file for editing.
-
Add or modify the following line:
Again, adjust the memory value as per your needs. For instance, 512M for larger websites.
-
Save the changes and restart the PHP process (this may be done via your cPanel or hosting control panel).
3. Modify the .htaccess File
If your hosting plan doesn’t allow editing the php.ini file, you can increase the PHP memory limit via the .htaccess file. This solution works well for many websites, especially if you are on a shared hosting plan.
Steps to Follow:
-
Access your website’s root directory (usually public_html) via cPanel's File Manager.
-
Look for the .htaccess file. If it's not visible, ensure that hidden files are shown in your file manager settings.
-
Right-click the .htaccess file and click Edit.
-
Add the following code to the end of the file:
-
Save the file and refresh your website to check if the issue is resolved.
4. Increase PHP Memory Limit Using cPanel (For ReloHost Users)
Some hosting providers, including ReloHost (Pty) Ltd, offer a simple way to increase PHP memory via cPanel’s PHP Selector or MultiPHP Manager.
Steps to Follow:
-
Log into your cPanel account.
-
Go to the PHP Selector or MultiPHP Manager under the Software section.
-
Select the PHP version you’re using for your website.
-
Click on the Options tab.
-
Locate the memory_limit directive and increase the value (e.g., set it to 256M or 512M).
-
Save the changes and restart your PHP session.
How to Check If the PHP Memory Limit Has Increased
After increasing the memory limit, it’s important to confirm that the changes have been applied correctly.
Steps to Follow:
-
Create a PHP Info File:
-
Create a new file called phpinfo.php in your website’s root directory (public_html).
-
Add the following code to the file:
-
-
Visit the PHP Info File:
-
Open your browser and go to www.yourdomain.com/phpinfo.php.
-
Look for the memory_limit setting on the PHP info page. If the value matches the memory limit you set (e.g., 256M or 512M), the changes were successful.
-
-
Delete the phpinfo.php File after confirming the settings for security reasons.
When to Increase the PHP Memory Limit
Consider increasing the PHP memory limit if:
-
You encounter memory exhaustion errors.
-
You’re running memory-intensive plugins or scripts.
-
Your website is running slowly or having performance issues.
Final Thoughts
Increasing the PHP memory limit is a simple yet effective way to solve many common website performance issues. Whether you're using WordPress, a custom-built website, or any CMS, increasing the memory limit ensures your website has the resources it needs to function optimally.
If you encounter any difficulties or need further assistance with increasing the PHP memory limit on your hosting plan, don’t hesitate to contact our 24/7 support team at support@relohost.co.za.