How to Increase Memory Limit on WordPress?
If you are a WordPress user, you have probably already encountered frustrating errors like:
- “The uploaded file exceeds the upload_max_filesize directive in php.ini”.
- “Fatal Error: Allowed memory size exhausted”.
These errors occur when your server reaches the limits defined by your PHP configuration. In this article, we will guide you step by step to increase important parameters such as: - The maximum size of uploaded files (
upload_max_filesize
). - The memory limit allocated to PHP (
memory_limit
). - The maximum execution time of a script (
max_execution_time
). - And other essential parameters to optimize the performance of your site.
With the right configurations, you can avoid these issues and provide a better user experience.
1. Understanding Essential PHP Settings
Before we dive into the changes, here’s a quick overview of the settings we’ll be adjusting:
upload_max_filesize
: Maximum size of a file that can be uploaded.post_max_size
: Total size of the data in a POST form (files + text).memory_limit
: Maximum amount of memory PHP can use.max_execution_time
: Maximum time a PHP script can take before it’s interrupted.max_input_time
: Maximum time to parse input data from a script.
These settings are defined at the server level and can be modified in several files, depending on your hosting.
2. Identify your current limits
Before changing anything, it is useful to know what the current limits of your configuration are. You can check them:
a) Via the Site Health tool
- In your WordPress dashboard, go to Tools > Site Health > Information.
- Under the Server tab, look for values like:
upload_max_filesize
memory_limit
max_execution_time
b) Via a phpinfo()
- Create a
phpinfo.php
file in the root directory of your site. - Add the following code: <?php phpinfo(); ?>
- Access this file via your browser (e.g.
https://yoursite.com/phpinfo.php
). - Find the settings mentioned above.
3. Edit Settings to Increase Limits
Edit the php.ini
The php.ini
file is the main place where you can adjust PHP settings.
- Connect to your server via FTP or SSH.
- Locate the
php.ini
file (often in/etc/php/7.x/apache2/
or similar). - Add or modify the following lines:
upload_max_filesize = 64M
post_max_size = 64M
memory_limit = 256M
max_execution_time = 300
max_input_time = 300
Edit the .htaccess
file
If you are using Apache and do not have access to php.ini
, you can adjust the settings via .htaccess
:
- In the WordPress root directory, open or create a
.htaccess
file. - Add the following lines:
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value memory_limit 256M
php_value max_execution_time 300
php_value max_input_time 300
⚠️ Warning: some hosting configurations may block these directives, which could cause 500 errors.
Edit wp-config.php
For set or increase the memory allocated to WordPress:
- Open the file
wp-config.php
. - Add the following lines before
/* That's all, stop editing! Happy publishing. */
:
define(‘WP_MEMORY_LIMIT’, ‘256M’);
define(‘WP_MAX_MEMORY_LIMIT’, ‘512M’);
This allows WordPress to use more memory for intensive tasks like plugin updates or imports.
Using a .user.ini
If you are on a shared hosting without access to php.ini
, create a .user.ini
file in the root directory and add:
upload_max_filesize = 64M
post_max_size = 64M
memory_limit = 256M
max_execution_time = 300
max_input_time = 300
Adjusting settings via the hosting panel
Many hosting providers (like cPanel or Plesk) offer an interface to edit PHP settings. Log in to your dashboard and look for a section like PHP Settings or MultiPHP INI Editor.
4. Test your changes
After applying these changes, you should verify that the new limits are taken into account:
- Reload your
phpinfo.php
page or use Site Health to validate the new values. - Test by downloading a large file or running a task that requires more memory.
5. Troubleshooting Common Issues
- Changes not applying?
- Make sure you are editing the correct configuration file (some servers use a global
php.ini
file). - Restart your Apache/Nginx server after making changes.
- Make sure you are editing the correct configuration file (some servers use a global
- Error 500 after editing
.htaccess
?- Remove the added lines in
.htaccess
. Your hosting may not allow PHP directives through this file.
- Remove the added lines in
Conclusion
Optimizing your WordPress site’s PHP settings is crucial to avoiding errors and improving its performance. Whether you’re a developer or a site owner, knowing how to adjust values like memory_limit
, upload_max_filesize
, and max_execution_time
can save you time and frustration.
If you run into any issues or have any questions, contact us here 😊