If you've ever seen an error message like "Allowed memory size of X bytes exhausted" on your website, it means your PHP script is trying to use more memory than your server is currently allowing. This is a common issue for websites, especially those running content management systems like WordPress with multiple plugins, or complex applications.
This guide will show you how to increase your PHP memory limit using your cPanel File Manager and a simple .htaccess file modification, helping to resolve these errors and keep your website running smoothly.
What Causes This Error?
PHP scripts require a certain amount of memory to execute. When a script, such as a plugin, theme function, or complex database query, demands more memory than the `memory_limit` setting in your PHP configuration allows, the "memory exhausted" error occurs. Increasing this limit gives your scripts more room to run.
What You'll Need:
Before you begin, make sure you have the following:
- Access to your cPanel account via your EncodeDotHost customer portal.
- The specific directory where your website's main
.htaccessfile is located (usuallypublic_html), or the directory where the error is occurring.
Step 1: Access Your cPanel File Manager
You'll need to access your website's files to modify the .htaccess file.
- Log in to your cPanel account.
- In the "Files" section, click on the "File Manager" icon.
Step 2: Navigate to Your Website's Root Directory
Locate the main directory of your website, which is typically public_html.
- In File Manager, navigate to your website's root directory (usually
public_html). This is where your main website files are located. - Note:
.htaccessfiles are hidden by default. If you don't see it, click "Settings" in the top-right corner of File Manager and ensure "Show Hidden Files (dotfiles)" is checked, then click "Save".
Step 3: Edit Your .htaccess File to Increase Memory Limit
You will add a specific line to your .htaccess file to tell PHP to use more memory.
- Locate the
.htaccessfile in yourpublic_htmldirectory. - Right-click on the
.htaccessfile and select "Edit" or "Code Edit". - Add the following line to the very top or bottom of the file on its own line:
php_value memory_limit 256M- Explanation: This line sets the PHP memory limit to 256 megabytes. You can adjust the value (e.g.,
128M,512M) as needed. Start with256Mand increase if the error persists.
- Explanation: This line sets the PHP memory limit to 256 megabytes. You can adjust the value (e.g.,
- Click "Save Changes" in the top right.
Step 4: Test Your Website
After making the change, clear your website's cache (if applicable) and test the page that was previously showing the error.
- Clear any website caching (e.g., WordPress caching plugins).
- Open your website in a web browser and navigate to the page or perform the action that previously caused the "memory exhausted" error. The error should now be resolved.
Alternative Method: RLimitMem (Less Common)
While `php_value memory_limit` is the most common and widely supported method for PHP memory limits via `.htaccess`, some specific Apache configurations might use `RLimitMem`. If the `php_value` method doesn't work, you can try this alternative:
- In your
.htaccessfile, instead of `php_value memory_limit 256M`, add:RLimitMem max- Note: `RLimitMem max` attempts to set the memory limit to the maximum allowed by the server. However, this directive is less commonly supported for PHP memory limits and might cause a 500 Internal Server Error if your server doesn't allow it.
Troubleshooting Tips:
- Error persists after change:
- Try increasing the `memory_limit` value further (e.g., to `512M`).
- If the error occurs in a specific subdirectory, try adding the `php_value memory_limit` line to an `.htaccess` file within that particular directory.
- Clear your website's cache and your browser's cache after every change.
- Internal Server Error (500):
- This usually means there's a typo in your `.htaccess` file or the directive is not allowed on your server. Remove the line you just added and save the file.
- If using `RLimitMem`, switch back to `php_value memory_limit`.
- Still having trouble? Contact EncodeDotHost support for further assistance. There may be server-level restrictions or other configuration issues that require our support.
By increasing the PHP memory limit, you provide your website's scripts with the resources they need to run efficiently, helping to prevent common errors and ensure a smooth user experience.