Using Nginx as Webserver and PHP-FPM


I want to setup nginx as a the webserver and php-fpm for the the php handler. The reason i wanna do this: i have a server with only 1.7gb of ram and just one core processor. My plan is to host a lot of small sites (like 40 or so) with little traffic on this servers. So i want as much as efficiency as i can get. I have just 1 main virtual server and 1 subdomain running on this right now, if i made the changes would be easier to setup everything right now.

So my questions is:

  • Will be worth in performance to make the changes?
  • will be needed to manually configure each new virtual server?
  • will be that problem with ssl certificades that i will not be able to setup wildcard certificates for example?
  • is there other big problem?

Thanks a lot, zéYuri



Howdy -- before we answer those questions, I have a couple of questions for you.

What distro/version are you using?

And what is the output of the command "free -m"?

Lastly, is this a dedicated server or VPS? If it's a VPS, what kind of VPS is it?


Hello andrey, here the answers

What distro/version are you using?

Im using CentOS Linux 7.2.1511

And what is the output of the command "free -m"?
              total        used        free      shared  buff/cache   available
Mem:           1697         547         233          25         915         937
Swap:             0           0           0
Lastly, is this a dedicated server or VPS? If it's a VPS, what kind of VPS is it?

Its a VPS. Im hosted on Google Compute Engine, with 1vCPU(shared) and 1.7gb RAM.

thanks for the help

My apologies for the delay.

Our opinion is that we prefer Apache, in just about all cases. It has more features, is easier to manage, and is better understood by everyone so if you have a problem it's easier to fix.

The performance differences of Nginx are very unlikely to be noticed, unless your seeing extremely high traffic.

Nginx does use less RAM, but your server still has 1GB of available memory, which is plenty.

Having 40 small sites isn't going to generate much load on your server, so you should be able to handle that just fine on Apache.

So what I would do in your case, is review the running processes (in Webmin -> System -> Bootup and Shutdown), and stop any services you don't need. Mailman and Postgres are commonly not needed, for example.

You may also want to look in /etc/httpd/conf.modules.d/, and see if there are any Apache modules you don't need running. That will make Apache leaner.

Also, I wouldn't install any PHP modules except for the ones you need. Every PHP module installed will make each incoming request take more RAM.

So our opinion is to use Apache, and just optimize what Apache/PHP modules are being loaded, as well as what other processes are running.

So, what are you sugestions for optimizing the cache for the server? I will have a lot of static contents there will be almost never get changed.

Optimizing the server in general should allow you to use Apache with no problem. Removing unnecessary services, Apache modules, and PHP modules should make it so you can run 40 small sites very well.

And yeah if a lot of those are static, they will use very little resources.

Joe's picture
Submitted by Joe on Tue, 02/09/2016 - 13:15 Pro Licensee

The benefits of PHP-FPM only begin to show themselves when you have a single very large, and high load, PHP application. For low load sites, and for static sites, the benefits of PHP-FPM won't matter, as the PHP caches can't be shared across many independently owned sites, anyway (and there is no need for a PHP opcode cache, at all, for static sites).

I'm planning to get PHP-FPM support for Apache released in a few weeks (though it's configurable manually now). nginx support will likely be a while later. Though nginx did just announce dynamic modules support, which will likely make it possible for us to support nginx in ways that are comparable to our Apache support.

These little websites that i've are actually all wordpress sites, so, i dont know how resources hungry they're. They're not static, thats what i mean. There is no need for using some caching?

I'm not saying you won't benefit from caching. All websites that aren't using static HTML files would benefit from caching.

FCGID, which Virtualmin uses by default, does indeed offer some caching.

I'm just offering that I don't think you need Nginx in order to have a web server that functions well with the available resources you have, and the type of websites you will be running.

In addition to the suggestions I mentioned earlier, I would suggest looking into some of the various WordPress caching plugins out there, there are several to choose from.