Virtualmin Pro - FCGI to mod_php

I have about 50 VS on my VPS under Virtualmin Pro.

I set almost all of them up with Server Templates. I started using FCGI for PHP because I understood it gives better isolation between VS, i.e. no user can see another user’s files.

Now, the extra 30 MB per VPS or whatever it is has added up to a substantial chunk of resources.

I converted one domain back to mod_php, and my webmail quit working. Seems that chowning everything in that dir to domainowner:apache was the fix.

I understand that I would have to do this for every mail user, recursively?

It looks like I would need to add php_admin_value open_basedir ${HOME} to the Apache Conf, because FCGI is no longer taking care of this issue?

Are these correct?

Is there anything else?

An easier way?



An alternative would be to try using CGI mode for PHP. That keeps the security benefits of fcgid, and your site should keep working.

It is the slower of the three execution types, but that’s often not a noticeable difference.


So, I should be able to just switch each VS to CGI instead of FCGI, and:

a) Nothing should break.
a2) I don’t need to do any mass chown or anything to run as apache, because PHP will continue to run as the server owner.

b) My perceived 30 M per site RAM penalty will be eliminated?

Thanks, Eric!


Those are all correct.

You’ll of course need to test it, but it should work at least as reliably as fcgid had, if not moreso.

Good luck!


Do I need to restart Apache to see the reduced RAM footprint?

Hm, for some reason, after switching some 6-8 domains FCGI to CGI, and restarting Apache, total memory usage is UP by about 200 MB.

How do get a handle on what’s going on?


I wouldn’t figure you’d see much of a RAM difference between FCGID and CGI.

One thing to make sure of is to verify that when looking at your RAM usage, that you aren’t counting RAM listed as “cached” as in use.

Also, if you aren’t using a given Apache module, you may want to remove it from Apache. After removing it from the Apache config, you’ll need to restart Apache to actually remove it.

The other thing to note is that things like MySQL, SpamAssassin, and ClamAV are all RAM hogs. Over time, each one of those is going to increase it’s RAM usage.

You can keep SpamAssassin and ClamAV under control by restarting them once a night, or perhaps once a week.


a few posts back, I tried to clarify with “b) My perceived 30 M per site RAM penalty will be eliminated?”, in regards to this change. You said that was “correct”. Anyway, very little invested, just hopes dashed.

Is there any authoritative info on the RAM usage diffs between the PHP modes? I have been Googling and found nothing clear… I am running my VPS at 3 GB, even though it rarely goes above 1.5, because bad things happen when MySQL runs out of memory, so am looking for a solution, because I would like to move to semi-dedicated, and that max there is 1.8 GB.

I’ll be asking my hosts, too.


Well, I’ll clarify… FCGID does keep processes in memory in order to keep them cached for future requests.

In that respect, using CGI should require less RAM than FCGID.

Also, once you remove the FCGID Apache module from the Apache config, that should further reduce the memory.

How much of a difference we’re talking about, after all is said and done, I’m not sure… however, it should at least be a little less – and certainly not more :slight_smile:

So if you’re seeing higher RAM usage, I have a suspicion it’s not related to using CGI… there may be something else going on there.


You may be seeing unintended consequences by going to CGI. CGI takes longer to process every request, so you’ll have more processes hanging around if you have pretty high load. For very low-load sites, it would be better to use CGI, but for any site that has more than a few requests per minute, you’d want fcgi.

I haven’t paid any attention to the rest of this thread, but if you haven’t already gone through your Apache configuration and disabled unused modules (especially mod_php, but there are several other hogs), you should definitely do that.

With the assistance of my hosts, I switched almost all my sites to mod_php. My RAM usage went from substantially over 1 GB, say 1200 MB, to below 700 MB, although it’s since crept up to almost 1100.

The benefit was that I was able to move to a semi-dedicated server, where my VPS has only 1.8 GB, down from 3 GB, and my Joomla sites immediately started running better. It appears that disk and CPU contention was hurting me more than the caching or extra RAM was helping me.

The switch to mod_php caused some issues with Joomla around the tmp directory, (perhaps partly because I am running openbasedir?) and I did have some general permissions issues.

I worked with Jamie to hopefully solve one of these issues by making sure to use {$HOME}/tmp as the tmp dir definition in Apache. Haven’t tested that yet, but it seems the right thing.

So, it was painful, but there were at least some benefits.

Thanks, everyone for following along and contributing.

I slogged through this partly because I have the notion that maybe a lot of (virtual) servers could use less RAM, and maybe a little server consolidation could happen, and that would be good for the environment.