Out of memory | Virtual Memory Exhausted Error - PHP Compilation

Getting  Out of Memory or Virtual Memory Exhausted error while compiling PHP in your web server ? This post will help you to overcome it and compile PHP particularly in low end VPS.

I have litespeed in one of my low end VPS (just 128 MB RAM). Few days back I thought of upgrading my PHP. So I tried to compile the latest version of PHP.

The first problem I faced was out of memory error.

 cc1: out of memory allocating 2036 bytes after a total of 98377728 bytes 

The compilation stopped. On searching about this error found out that this happens in low end servers where PHP compilation cannot get adequate RAM to compile. But there is a way to overcome this. :) Just raise the soft-limits (ulimit) in server by issuing these commands as root.
ulimit -S -s 3276800
ulimit -S -m 13107200
ulimit -S -d 13107200

So out of memory problem solved :). However on further progress of compilation, i faced another error, this time it was virtual memory exhausted . 
virtual memory exhausted: Cannot allocate memory

Again i did some R & D and found out that this may happen due to a extension called fileinfo which eats up RAM during compilation and cripples system (particularly low end systems ). So i just disabled that extension as i dont need that (In simple words fileinfo extension is used to find the file type of the file)

To disable this extension and to solve virtual memory exhausted error just use this parameter before compiling.  
For example in my case since i am using litespeed i set parameters in the compile PHP page. Here are the parameters i used :

Thats it. After that PHP compilation was smooth and successful.

Hope this post helps :) Feel free to ask any questions regarding this.

About This Blog

There is something for everyone. !! A tech blog on various topics. Let it be devops, programming etc; we have it all covered here in layman terms :)

Total Pageviews

Back to TOP