When running a WordPress website, you may encounter memory-related issues, especially if your site experiences high traffic or if you're using resource-intensive plugins or themes. Insufficient PHP memory can lead performance issues or fatal errors:
PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 462848 bytes)
Here's a guide on how to increase PHP memory for your WordPress site using various methods, including cPanel.
1. Editing wp-config.php File
One of the simplest methods to increase PHP memory is by editing the wp-config.php file, which is located in the root directory of your WordPress installation:
- Access your WordPress files either via FTP or through the file manager provided by your hosting provider.
- Locate the wp-config.php file in the root directory.
- Add the following line just before the line that says /* That's all, stop editing! Happy blogging. */: define('WP_MEMORY_LIMIT', '512M');
- Save the changes and upload the file back to your server.
2. Using .htaccess File
If you don't have access to the wp-config.php file or prefer an alternative method, you can also increase PHP memory via the .htaccess file.
- Access your WordPress files as before.
- Locate the .htaccess file in the root directory.
- Add the following line at the end of the file: php_value memory_limit 512M
- Save the changes and upload the file back to your server.
3. Using php.ini File
Some hosting providers allow you to customize PHP settings using a php.ini file.
- Access your WordPress files.
- Locate or create a php.ini file in the root directory (if it doesn't already exist).
- Add the following line to increase PHP memory: memory_limit = 512M
- Save the changes.
4. Using cPanel
If you have cPanel access, you can also increase PHP memory through the interface.
- Log in to your cPanel provided by your hosting provider.
- Navigate to the "Software" section and click on "Select PHP Version" or "PHP Configuration," depending on your cPanel version.
- Locate the option for "memory_limit" or similar.
- Increase the memory limit value. You may have a dropdown or input field to specify the limit. Set it to your desired value (e.g., 512M).
- Save the changes.