Reduce memory consumption of apache/php processes

I use virtualmin to manage my web server. For performance reasons, the database server is hosted on another VPS. Therefore, the server hosting virtualmin has only two active services: SSH and APACHE

I have noticed that, as the hours go by, there is a very high memory consumption for processes linked to apache / php (print attachment).

this consumption is so strange, that webmin refuses my connection to the manager (URL.COM:10000).

normally, to reduce this high memory consumption of the processes involving apache, I have to access the server via SSH and restart the apache services.

Thus, the memory goes back to 400mb/500mb. however, after a few hours, the processes again consume a large amount of memory.

I already looked for some topics here in the forum, but I did not find any information that would help me to reduce this high memory consumption of processes involving apache/php.

I don’t know if I should limit the time (age) of these processes (I don’t even know if there is a way to do this).

for information:

  • there are 8 virtual servers configured in this VPS
  • PHP’s memory limit is 256mb for 2 sites. the others I put 128mb
  • there is no high access traffic to justify this high consumption

Has anyone had this problem? is there a solution?

tks

tweak php/apache, move to php-fpm, setup firewall in case this is an web attack of some sort…
logs should help investigate what is causing the high mem/swap usage.

hi @dimitrist,

I believe that a web attack can be mitigated because there is cloudflare managing the DNS (and promoting the necessary solutions).

I will test changing the script execution mode to php-fpm, however, I have a question: is not php-fpm less secure?

tks

properly setup php-fpm can be more secure than the apache module/cgi. security doesn’t depend on just one thing, rather on the whole web setup…

about cloudflare, i don’t trust/use it. and for low volume websites it seems unnecessary, could be slowing them down.

this has nothing to do with attacks on a new system. its directly related to your php configuration for virtual servers.

for example, take a look at the following php-fpm configuration on my system…notice that i have set “pm=ondemand”. This reduces your memory load for that Virtual Server dramatically

also, check in webmin > Servers > Apache Webserver > Modules and make sure that “mpm_prefork” is not the one selected.

this uses huge amounts of memory on the server and is the apache default (nothing to do with Virtualmin). In all honestly, the mpm_prefork setting is absolutely hopeless for me where i offer shared webhosting services for clients. I always change it to either mpm_event or mpm_worker.

Both of the above can also be configured as a default option for your system.

I have altered my php configuration files for all new virtual servers so that “pm-ondemand” doesnt need to be done manually every time you create a new virtual server. The default configuration file has “pm=ondemand” as the default already.

doing the above 2 things will save an enormous amount of system memory…especially as you add more virtual servers to your system.

3 Likes

thanks.

I’ll make some changes and let you know if it works out.