To ensure optimal performance of your WordPress site, it's crucial to have an adequate PHP memory limit. The default PHP memory limit might be too low for resource-intensive plugins or themes, leading to errors such as "Fatal error: Allowed memory size of X bytes exhausted". This article will guide you through three methods to increase the PHP memory limit for WordPress: editing the wp-config.php file, using an .htaccess directive, and modifying the php.ini file via Plesk.
Method 1: Edit wp-config.php File
The wp-config.php file is a core WordPress configuration file. You can define the PHP memory limit directly in this file.
- Log in to your hosting account via FTP or use the file manager provided by your ISP (Internetport).
- Navigate to the root directory of your WordPress installation.
- Download a copy of the
wp-config.phpfile to your local machine for editing. - Open the
wp-config.phpfile in a text editor (such as Notepad++ or Sublime Text). - Add the following line of code before the line that says
/* That's all, stop editing! Happy blogging. */:define('WP_MEMORY_LIMIT', '256M'); - Save the changes and upload the modified
wp-config.phpfile back to your server.
Method 2: Use .htaccess Directive
The .htaccess file is used for various configuration settings on Apache servers. You can increase the PHP memory limit by adding a directive in this file.
- Log in to your hosting account via FTP or use the file manager provided by your ISP (Internetport).
- Navigate to the root directory of your WordPress installation.
- Download a copy of the
.htaccessfile to your local machine for editing. If there is no.htaccessfile, you can create one. - Open the
.htaccessfile in a text editor (such as Notepad++ or Sublime Text). - Add the following line of code at the end of the file:
php_value memory_limit 256M - Save the changes and upload the modified
.htaccessfile back to your server.
Method 3: Modify php.ini via Plesk
If you are using a hosting service that provides access to Plesk, you can modify the PHP settings directly through the control panel.
- Log in to your Plesk account.
- Navigate to the "Websites & Domains" section and click on the domain where WordPress is installed.
- In the left-hand menu, find and click on "PHP Settings".
- Scroll down to the "Additional configuration directives" section.
- Add the following line of code:
memory_limit = 256M - Click "Apply" or "OK" to save the changes.
Verifying the PHP Memory Limit
To verify that the memory limit has been successfully increased, you can create a phpinfo.php file and access it through your browser:
- Create a new text file on your local machine.
- Add the following code to the file:
- Save the file as
phpinfo.php. - Upload the
phpinfo.phpfile to your WordPress root directory. - In your web browser, navigate to
http://yourdomain.com/phpinfo.php. - Look for the "memory_limit" entry under the "Core" section. It should display the new value (e.g., 256M).
- For security reasons, delete the
phpinfo.phpfile from your server after verifying.
Troubleshooting
- Changes not taking effect: Ensure that you are editing the correct file and that there are no conflicting settings in other configuration files. Clear any caching mechanisms on your server or browser to see changes immediately.
- Server error after making changes: Check for syntax errors in your code edits. Revert to a backup if necessary, then try again carefully.