10

Try to yum install php56w-mcrypt and system gave me this error

libmcrypt-2.5.8-13.el7.x86_64: [Errno 5] [Errno 12] Cannot allocate memory
php56w-mcrypt-5.6.5-1.w7.x86_64: [Errno 5] [Errno 12] Cannot allocate memory

I ran a check on free -m

             total       used       free     shared    buffers     cached
Mem:           490        421         68          8          3         42
-/+ buffers/cache:        376        113
Swap:            0          0          0

top

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
 9756 mysql     20   0  727588  81556      0 S  0.3 16.2   1:04.61 mysqld
11089 root      20   0       0      0      0 S  0.3  0.0   0:16.25 kworker/0:2
    1 root      20   0  129396   2020    576 S  0.0  0.4   0:05.88 systemd
    2 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kthreadd
    3 root      20   0       0      0      0 S  0.0  0.0   0:00.16 ksoftirqd/0
    5 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kworker/0:0H
    7 root      rt   0       0      0      0 S  0.0  0.0   0:00.00 migration/0
    8 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcu_bh
    9 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/0
   10 root      20   0       0      0      0 S  0.0  0.0   0:01.82 rcu_sched
   11 root      20   0       0      0      0 R  0.0  0.0   0:02.10 rcuos/0
   12 root      rt   0       0      0      0 S  0.0  0.0   0:00.91 watchdog/0
   13 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 khelper
   14 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kdevtmpfs
   15 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 netns
   16 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 writeback
   17 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kintegrityd

Not sure where else to check.

I am using DigitalOcean VPS with RAM 512MB, the $5/month plan.

6

This issue is the server seem to only have 490MB of RAM on the machine and you have 421MB used. Leaving only 68MB free; that is not a lot of memory for any system to work with.

Looking at the output from top shows that MySQL (aka: mysqld) is the culprit.

The best thing you can do if this is a temporary situation is to simply stop MySQL like this:

sudo service mysqld stop

Then with MySQL stopped, you can run yum install as expected.

But another solution would be to use a script like “MySQL Tuning Primer” to help assess the MySQL usage and configuration on the serve and adjust accordingly. The reason being is plain vanilla MySQL out of the box will be a memory hog. But “MySQL Tuning Primer” will help assess your install and let you know what you can tweak. Including lowering memory requirements so the setup can be happy with your limited resources. The only catch is MySQL needs to be actively running for at least 48 hours straight for the “MySQL Tuning Primer” results to be worth anything. Past that, performance tuning MySQL with this script a great way to fine-tune your L.A.M.P. setup.

Additionally, since you are running Apache you can probably lower the RAM requirements for Apache (aka httpd) so you free up more RAM that way. This is a fairly generic set of tweaks for a basic development environment of Apache, but should help you. First open up your Apache config via your favorite command line editor like this; I prefer nano but any text editor is good:

sudo nano /etc/httpd/conf/httpd.conf 

Now find the line that a says Timeout and change that to “120”; two minutes is a reasonable timeout window:

Timeout 120

Similarly find MaxKeepAliveRequests and change that to “24”; “keep alive” connections are good, but don’t let them overwhelm your setup:

MaxKeepAliveRequests 24

And find KeepAliveTimeout and set that to “2”; this should correlate to how fast one page on your site loads and 2 seconds is a good average:

KeepAliveTimeout 2

Now look for the XML config directive set as <IfModule mpm_prefork_module>:

<IfModule mpm_prefork_module>
  StartServers           8
  MinSpareServers       16
  MaxSpareServers       32
  ServerLimit           40
  MaxClients            40
  MaxRequestsPerChild 2000
</IfModule>

The key to this is ServerLimit and MaxClients. By default Apache’s settings are quite high; 255 for MaxClients I believe. But the reality is even a high traffic site will only get 70-80 connections per second… And then die… Meaning Apache connections are stateless so the benchmark is connections per second. So for a development or small scale server, “40” is a good number.

Now with those key adjustments made, restart Apache like this:

sudo service httpd restart

By adjusting MySQL and Apache to have more reasonable settings than default/canned values can free up resources on your server and make everything run more smoothly.

14

You can create swap file:

fallocate -l 512M /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile

This will create swap file and you will be able to install applications. To remove swap file:

swapoff -a
rm -f /swapfile

see Arch wiki for details.

  • 1
    Nice idea. Any reason, besides losing some disk space, to turn off swap? – raider33 Dec 15 '16 at 4:14
  • Depends on swap settings a system can start using it on 50% memory load or so. If your system is having, let say, 512MB but most of the time it's using ~400MB then it will work perfectly fine without swap, but with it, it can slow down trying to swap 150MB back and forth. But I may be wrong on that one. – pbogut Dec 15 '16 at 14:40
  • Don't forget to use sudo for the commands – Raptor Aug 22 '17 at 9:35
  • fallocate may cheat and not work... use sudo dd if=/dev/zero of=/swapfile count=512 bs=1MiB – Ray Foss Jun 18 '18 at 13:42

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.