How to extend the memory limit and max fil upload size in WordPress

Raise the memory limit in WordPress

You can do this in 2 places. The php.ini file and in the wp-config.php file.

Adding Memory Limit in php.ini

To avoid error messages from different programs regarding memory limit. Why not increase the memory limit?

Set the value in php.ini


There are two php.ini files

Make sure that you edit the right one for Apache.
This is th one for command line. Do not edit this.

sudo nano /etc/php/7.0/cli/php.ini

This is the one used by WordPress

sudo nano /etc/php/7.0/apache2/php.ini 

Ctrl+W to find in Nano editor:

memory_limit = 128M 
post_max_size = 64M
upload_max_filesize = 64M

Change the memory value to 256M or whatever you like.
64M or 32M is an alternative if you are short on RAM on your 1 GB server.

Modify the max file size to your desire

Running only one website on a 1 GB server or there is more than 1 GB RAM on the VPS. Then sentence could read:

memory_limit = 256M

Save and exit the file in Nano.

Then restart Apache

sudo service apache2 restart

Change using command line

sed -i 's/memory_limit = .*/memory_limit = 64M/'/etc/php/7.0/apache2/php.ini

Set the memory value in WordPress

sudo nano wp-config.php

Add the following line:

define('WP_MEMORY_LIMIT', '256M'); 
define(‘WP_MEMORY_LIMIT’, ’64M’);

Extending WordPress memory limit in .htaccess

You can add the memory limit in the file .htaccess

nano .htaccess

Add the following line:

php_value memory_limit 256M

Sources for this post about extending the memory limit in WordPress