How to increase Memory Limit, Max Upload Size etc… on WordPress

8 January 2025
Estimated reading time: 4 min

How to Increase Memory Limit on WordPress?

If you are a WordPress user, you have probably already encountered frustrating errors like:

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:

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

  1. In your WordPress dashboard, go to Tools > Site Health > Information.
  2. Under the Server tab, look for values ​​like:
    • upload_max_filesize
    • memory_limit
    • max_execution_time

b) Via a phpinfo()

  1. Create a phpinfo.php file in the root directory of your site.
  2. Add the following code: <?php phpinfo(); ?>
  3. Access this file via your browser (e.g. https://yoursite.com/phpinfo.php).
  4. 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.

  1. Connect to your server via FTP or SSH.
  2. Locate the php.ini file (often in /etc/php/7.x/apache2/ or similar).
  3. 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:

  1. In the WordPress root directory, open or create a .htaccess file.
  2. 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:

  1. Open the file wp-config.php.
  2. 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:

  1. Reload your phpinfo.php page or use Site Health to validate the new values.
  2. Test by downloading a large file or running a task that requires more memory.

5. Troubleshooting Common Issues

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 😊

Did you like the article? Buy us a coffee... or two ☕️ to boost our creativity!

soutenez webwise