Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache memory error

As I was trying to restart apache2, I encountered the following error:

Fatal Error Unable to allocate shared memory segment of 67108864 bytes: mmap: Cannot allocate memory (12)

I only found out that this error often occures on virtual servers, but I couldn't find a solution oter than switching to php-fpm and nginx to reduce memory use.

Server: Ubuntu 14.04 LTS, 2GB RAM, VPS

Does anyone know how to resolve this issue, because RAM doesn't seem to be the problem (1.9GB free).

Sodaa

like image 866
SparklingWater Avatar asked Jul 24 '15 21:07

SparklingWater


1 Answers

"Fatal Error Unable to allocate shared memory segment".

Use ipcs -lm to determine current shared memory limits. And use ipcs -ma to determine how much shared memory is currently in use.

UPDATE you have added the comment to show "max seg size (kbytes) = 32768". So max segment size is 32MB. Original error is "Unable to allocate shared memory segment of 67108864 bytes". So unable to allocate segment of 64MB.

Increase your maximum shared memory segment size from 32MB to 128MB.

echo "134217728" >/proc/sys/kernel/shmmax
echo "134217728" >/proc/sys/kernel/shmall

And then retry. If apache2 then works ok, make the change survive reboots, by placing an entry in /etc/sysctl.conf as below:

kernel.shmmax=134217728
kernel.shmall=134217728
like image 142
steve Avatar answered Sep 27 '22 22:09

steve