Both WordPress and PHP allow users to set a maximum quota for memory usage. Sometimes these predefined values do not allow certain programs or specific needs to run appropriately because they are set too low.
Here are a few ways of changing the predefined value.
Within WordPress
Find the root directory for the WordPress installation, normally for an ubuntu setup using apache this would be:
/var/www/html
open wp-config.php using your favorite editor, I simply SSH to do this and use vim.
Paste the following snippet in the file and edit the numeric value to reflect your needs (Ex. 256M -> 512M ).
// Set custom memory limit for WordPress.
define('WP_MEMORY_LIMIT', '256M');
Within PHP config file (php.ini)
If you tried changing the value or adding it to the WordPress config file but still not getting the required results, try changing the value directly in the php.ini file if you have access to it ( Most shared hosts providers do not expose this ).
Article continues below
So I know our tutorials are totally awesome 😉. But maybe, going through how-to's is not how you would like to be spending your precious time. Imagine a world where things just work. Kinsta's hosting platform gets our official -"Easy Way of the Day" seal. Advanced features that are incredibly easy to set up.
- Cloudflare integration
- Automatic daily backups
- DDoS protection
- Exclusively for WordPress
If like in my case you are using Linux, use the following command to find the PHP.ini
configuration file.
php -i | grep "Loaded Configuration File"
Now this will give you the config file (php.ini) related to the command line (CLI), it is important to realize that we have a few:
$ example/path/cli
Command-line .ini file directory, this will not affect server-related functions.
$ example/path/fpm
Nginx file directory, affects server-related functions for Nginx setups.
$ example/path/apache2
Apache file directory, affects server-related functions for apache setups.
Find and Open the indicated file that results from the above command related to your server ( Nginx or apache ), and add or edit ( search the file to make sure it is not already included ) the following line.
memory_limit = 256M
Again, remember to edit the numerical value (256M ) to whatever you actually need it to be.
Using an .htaccess file
But what if we do not have access to the php.ini file?
Options and behaviors set may be overwritten using the local .htaccess file [*]. Find your root .htaccess file and add the following line of code to it.
php_value memory_limit 256M
Footnotes