Le Trong Tan
Le Trong Tan

Reputation: 47

Fatal error: Out of memory in WordPress running on AWS EC2

I launch an instance (EC2): Amazon Linux AMI 2018.03.0 (HVM), SSD Volume Type all the options are default (free tier) In installed Wordpress and run it online for test.

I configured as bellow : sudo vim /etc/php.ini (php.ini file)

memory_limit = 1024M

I added two line in wp-config.php

define('FS_METHOD','direct');
define('WP_MEMORY_LIMIT', '1024M');

Using .htaccess

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress

<IfModule mod_php7.c>
php_value memory_limit 1024M
</IfModule>

But sometimes I still get the error messages like:

Fatal error: Out of memory (allocated 28311552) (tried to allocate 65536 bytes) in Unknown on line 0

or

Fatal error: Out of memory (allocated 24117248) (tried to allocate 143360 bytes) in file...

Does anyone know how to fix this issue? Please help? In php.ini file I see
; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
before line
memory_limit = 1024M
Is that mean even I set memory_limit = 1024M the memory limit still is 128MB on EC2?

Upvotes: 0

Views: 1633

Answers (2)

Atiqur Rahman
Atiqur Rahman

Reputation: 66

It looks like your wordpress needs more memory to run than you have given, which is 256M. Now solution is to optimize your wordpress like remove un-necessary plugins / themes etc. Use proper caching and CDN. But if still it gives error then try to increase the instance type to next level. Like from t2.nano to t2.micro

Upvotes: 0

Madhav
Madhav

Reputation: 71

  1. Try adding this line to your wp-config.php file:

define('WP_MEMORY_LIMIT', '1024M');

  1. If you have access to your PHP.ini file, change the line in PHP.ini

memory_limit = 1024M;

  1. Using htacess.

php_value memory_limit 1024M

PS: Try restarting the PHP service as well

Upvotes: 1

Related Questions