GitHub Project - Nginx configuration for Drupal and Aegir

Events happening in the community are now at Drupal community events on www.drupal.org.
omega8cc's picture

There are many ways to use Nginx. With Aegir and Boost compatible configuration, without all that Aegir and Boost related stuff, with subdirectory install, compatible with Purl and Spaces, and many different modules, where some specific rewrites are required.

It is always handy to have something tested and working as default setup, but there is also room for improvements, different setups, and it seems GitHub fork feature would be useful to create and maintain different configuration examples for wider audience.

So, I started initial project on GitHub to invite anyone interested to fork and maintain own version, listed later also here on g.d.o.

http://github.com/omega8cc/nginx-for-drupal

Enjoy!

Comments

I can install php-fcgi

rokape's picture

I can install php-fcgi php-fmp for nginx....It said:make: *** [sapi/fpm/php-fpm] Error 1

It is not enough information

omega8cc's picture

It is not enough information to help you. Also, I prefer Debian or Ubuntu, so if you are using CentOS etc. you will need CentOS specific advise. See also my comment here: http://groups.drupal.org/node/26227#comment-121286

Cool! here's my nginx config

yhager's picture

Funny, just last week I decided to publish my own nginx config files to github, and I have yet to post about it.
I am not an Ægir user, so I don't know how compatible is it with Ægir, but I've had in mind the following points when I implemented it:

  • Simple config files, hiding common options in include files
  • Very easy to add another site (standard or multi) - just a few lines of config code
  • Allow for different environments on the same server - production, staging, dev, etc.
  • Boost support
  • Allows different server for images & imagecache (differentiate by name only. You can share this config among web and images servers. Think NFS)
  • static files (of course!) and gzipped static are used if exist.
  • simple htpasswd protection for anything not 'index.php' :)

You can access (and fork) the project at http://github.com/yhager/nginx_drupal

Thanks for sharing your work

omega8cc's picture

Thanks for sharing your work on GitHub. I think it's a good idea to post complete configuration, with all files included in a standard nginx install. My project is for now just a place to keep a few files and how-to, posted before here on g.d.o, but for starters it is better to have complete config/files ready to use, probably.

~Grace

Hello :) I've tried your

Terko's picture

Hello :)
I've tried your setup and now it's working just fine!
But one problem - I have AJAX comments enabled. When I post comment, the new comment appear on the screen, but the progress bar of publishing of the comment don't disappear.
I saw that Omega have special rules for ajax comments, but they are related to og and I am not sure if this rule can be used for me too.

Can you show me exactly what

yhager's picture

Can you show me exactly what is not working? I have not used ajax comments before.

Just a sec. Right now I face

Terko's picture

Just a sec. Right now I face another problem. I am trying to figure how to serve imagecache files from different folders. I am using files/imagecache for one of my sites, jokefiles/imagecache for other site, and car/imagecache for third
This is biggest problem right now. How to modify imagecache file to serve correctly the files and from these locations?
Meanwhile I will try to make you screenshot of the problem with the Ajax comments

I have pushed a fix for the

yhager's picture

I have pushed a fix for the imagecache issue - http://github.com/yhager/nginx_drupal/commit/b17b08baf538930a1bdcd91aa4b....

Please let me know if it is fixed the issue.

I have installed and tested ajax_comments, and it is working fine in my setup - so I would love to get more details about yours.

This works! Thanks! I see,

Terko's picture

This works! Thanks!
I see, that Ajax work fine with one of my sites, just do this strange behavior with one of them. Maybe this is JavaScript problem with my config of the site. So don't worry about this. Thanks again! :)

Thanks for reporting that

yhager's picture

Thanks for reporting that issue. Feel free to contact me again if you have anything to report/contribute.

Thanks! Can I ask you some

Terko's picture

Thanks!
Can I ask you some other thing.. I have 3 directories. pictures1, pictures2, pictures3. How I can block hotlinking to them?
I found this script, but I am not sure where to put it in your config.

location ~ .(jpg|png|gif)$ {
valid_referers server_names blocked none frienddomain.com *.frienddomain.com ;
if ($invalid_referer) {
return 403;
}
}

Look for 'serve static files

yhager's picture

Look for 'serve static files directly' comment in drupal_common, then put it there (without the 'location' line and the closing curly brace at the end).

Yes, this works :) In fact, I

Terko's picture

Yes, this works :) In fact, I want to deny hotlink only to these 3 directories, because one of the sites uses Drigg and people have to hotlink to button images. And to reffer to Submit.php file. I think that in your setup everything except index.php is denied.

I've resolved it :) Just

Terko's picture

I've resolved it :)
Just created this config in nginx.conf

server {
  listen 80;
  server_name cdn1.example.com cdn2.example.com cdn3.example.com;
valid_referers server_names blocked none frienddomain.com .frienddomain.com ;
if ($invalid_referer) {
return 403;
}
  access_log off;
  root /home/uhaaa22/public_html;
  server_name_in_redirect off;

  location / {
    return 404;
    # or
    # rewrite ^ http://www.example.com permanent;
access_log        off;

  }

  location ~ ^.+.(jpg|jpeg|gif|png|ico|js|css)$ {

    # access_log      off;
    # error_log /dev/null crit;
    expires         45d;
access_log        off;

    try_files $uri @drupal;
  }

location @drupal {
        ###
        ### now simplified to reduce rewrites
        ###
        rewrite ^/(.
)$  http://example.com/$1 permanent;    }

}

Now every request for cdn1.example.com - the images for the particular domain will be refused if they are hotlinked :)
But my Drigg install will not be afected.

Nginx Config

vidichannel's picture

Thank you for sharing. I am giving nginx a tryout and having some trouble. This could be just the help I was looking for. I'm hoping the nginx built-in reverse proxy server will let me route domains to different Ubuntu servers behind the firewall.

Your github

cwittusen's picture

Yhager:
What would change in your github nginx setup if I had nginx+php-fpm+apc+memcache+mysql like Omega8cc configured it? I see you are using php-cgi instead so I"m just wondering if there is a big change or not?

I'm almost there and I would like to use your setup since you are working with boost as well.

Regards,
Chris W

Thanks, I'm using this config

interx's picture

Thanks, I'm using this config and everything works ok, except :

  # This is mostly based on Drupal's stock .htaccess
  location ~* ^.+(.(txt|engine|inc|info|install|module|profile|po|sh|.sql|theme|tpl(.php)?|xtmpl)|code-style.pl|/Entries.|/Repository|/Root|/Tag|/Template)$ {
    return 404;
  }

This is similar in both yours and the Aegir config. It does a case insensitive match (~*), while the original FilesMatch in the htaccess was case sensitive.

The module HTMLMail has a menu entry "admin/settings/htmlmail/template" wich matches and returns a 404.
Once I split up the case-sensitive CVS folders, it worked.

  # This is mostly based on Drupal's stock .htaccess
  location ~* ^.+(.(txt|engine|inc|info|install|module|profile|po|sh|.sql|theme|tpl(.php)?|xtmpl)|code-style.pl)$ {
    return 404;
  }
  location ~ ^.+(/Entries.
|/Repository|/Root|/Tag|/Template)$ {
    return 404;
  }

subscribing :)

wik's picture

subscribing :)

I install php-fpm but it said

rokape's picture

I install php-fpm but it said error when complainer...what best ..configure on centos 5 64bit for me?

mime.types

indytechcook's picture

This is great. I setup a nginx+php-fpm setup and had issue with drupal. Your config files are awesome. I just have one questions, you include mime.types, just wondering if you had an example of this.

nm

indytechcook's picture

Nevermind on this, i just realized that it comes with nginx.

Right

yhager's picture

The idea is that this is a fully working config, you simply replace your nginx config with this.

Thanks.And how about run d6

rokape's picture

Thanks.And how about run d6 only nginx+Boost is better than nginx+boost reveser proxy for apache back-end?How to config for that?

I don't see any reason to use

omega8cc's picture

I don't see any reason to use nginx as a proxy for Apache to run Drupal, when you can do that using just nginx + php-fpm.

Agreed. May be temporary phase.

yhager's picture

nginx+php is a good architecture. Some people know (and love?) the ability to tweak .htaccess files, so they might want to use nginx+apache until they are confident enough with nginx alone.

Another note is that although I expected to find clear cut benchmarks that show that nginx+php is faster than nginx+apache for PHP processing, I have yet to find any such benchmarks on the net. On the contrary, I found some that claim that Apache runs PHP faster than PHP as cgi.
I have not done any benchmarking myself, as I believe that
a) if there is a difference it is minor;
b) it makes much more sense to run a lightweight web server and a separate PHP processor, over running two web servers that talk HTTP internally.

I prefer sound architecture over 5% performance increase.

There is another thread about

omega8cc's picture

There is another thread about this and there are reasons to use Apache as a backend, when you need svn/webdav etc.

http://groups.drupal.org/node/27082

Xcache vs. APC

Th30philus's picture

@omega8cc

Could you comment on the choice of xcache over APC for this configuration? Would there be any detriment in using APC instead of xcache?

I'm not trying to start a cache flame war here. My primary motivation for asking is that it seems like some other Drupal modules (e.g. devel) use APC, and I'd prefer not to have both xcache and APC installed if possible. Of course, this is based on the assumption that having both installed is redundant, or am I mistaken? Do APC and xcache serve the same function?

@LegacyAtty

omega8cc's picture

I like to test all available options. BTW - this is why we are using now also Redis and not only Memcache for cache chaining: http://twitter.com/omega8cc/status/8737587433

We tested Xcache in production in the last few months and I'm not happy with the results, so we are now switching all servers back to APC, and I will update also my how-to on GitHub, so it will include full Debian 5.0 Lenny setup from scratch (not just nginx + php-fpm).

~Grace

Great update Grace, this is a

indytechcook's picture

Great update Grace, this is a great guide!

I originally compiled using this guide (but using different .conf files): http://interfacelab.com/nginx-php-fpm-apc-awesome/

It wasn't until after I started to install Drupal (D7 in particular) that I noticed how wrong the configure options were :) DOH!!

I agree with APC, I noticed XCache being quite unstable.

Hi Neil

omega8cc's picture

Thank you, I hope to improve it soon, as time permits.

Greetings

What is the issue with Xcache

osu_bucks's picture

Hi,
I have been running XCache for few months. What was the XCache issue you guys are seeing? Performance, seg fault, or?
If it's really bad, I might change to APC and test it out too.

On mine, I did set auto_globals_jit to off in php.ini to prevent drupal segmentation fault: http://www.slantview.com/blog/slantview/apache2-php-5-x-xcache-load-segf...

I noticed random seg faults

omega8cc's picture

I noticed random seg faults and overall bad memory management with XCache, while APC looks far more stable and trouble-free for me, but in any case, that tip about auto_globals_jit off is probably worth to test further and use. Thanks!

WSOD with signwriter w/r/t GD and truetype fonts

DanGarthwaite's picture

Need to add some additional libraries to php. Here is the patch against commit: 95661cf1b6421bc4b9bc6cdc37d7e80c508eb005

diff --git a/php-fpm-install.txt b/php-fpm-install.txt
index 2a2ebf7..013462b 100644
--- a/php-fpm-install.txt
+++ b/php-fpm-install.txt
@@ -9,7 +9,7 @@
sudo aptitude update
sudo aptitude safe-upgrade
sudo aptitude install build-essential
-sudo aptitude install mc rsync libtool autoconf dnsutils libmcrypt-dev mcrypt sysvconfig libxml2-dev libc-client-dev libpng-dev libjpeg-dev xml2 libpcre3 libpcre3-dev memcached zlibc libmemcache-dev libcurl4-gnutls-dev libcurl4-openssl-dev ncurses-dev ntpdate graphicsmagick-imagemagick-compat munin bzr munin-plugins-extra curl dstat ifstat sysstat htop devscripts git-core xml-core bc php5-xsl libxslt-dev php5-cli mysql-client-5.1 mysql-server-5.1 libmysqlclient16 libmysqlclient-dev cvs libevent-dev
+sudo aptitude install mc rsync libtool autoconf dnsutils libmcrypt-dev mcrypt sysvconfig libxml2-dev libc-client-dev libpng-dev libjpeg-dev xml2 libpcre3 libpcre3-dev memcached zlibc libmemcache-dev libcurl4-gnutls-dev libcurl4-openssl-dev ncurses-dev ntpdate graphicsmagick-imagemagick-compat munin bzr munin-plugins-extra curl dstat ifstat sysstat htop devscripts git-core xml-core bc php5-xsl libxslt-dev php5-cli mysql-client-5.1 mysql-server-5.1 libmysqlclient16 libmysqlclient-dev cvs libevent-dev libfreetype6-dev


#
@@ -80,7 +80,11 @@ cp -f /etc/init.d/php-fpm /etc/init.d/php-fpm.bak
--with-curl \
--with-curlwrappers \
--with-gd \
---with-jpeg-dir=/usr/lib \
+--enable-gd-native-ttf \
+--with-jpeg-dir=/usr \
+--with-png-dir=/usr \
+--with-freetype-dir=/usr \
+--with-t1lib=/usr \
--with-pear \
--with-imap \
--with-imap-ssl \

I always prefer to build as

omega8cc's picture

I always prefer to build as small as possible PHP binary, but those libraries looks like worth to be added anyway. Thank you for the patch.

So.. what is the reason for

Carl Johan's picture

So.. what is the reason for patching the apache provision files, rather than making some nginx ones to go besides the apache ones?

The reason is (in fact - was)

omega8cc's picture

The reason is (in fact - was) - previous Aegir versions had in too many places hardcoded 'Apache-only' stuff, so even provision submodule was not an option. This simple patch was the most effective way to get it done for nginx without patching Aegir everywhere to avoid Apache-only stuff.

Now it all changes with latest server/service abstraction in alpha6+ and we can finally create nginx plugin for Aegir. We plan to release our version on Github soon, and also submit the code for review.

Some details on those changes in Aegir:
http://developmentseed.org/blog/2010/mar/01/aegir-04-alpha-6-released-ne...

HTH
~Grace

nginx config/build

cwittusen's picture

Hi
I'm about to install and configure nginx+php-fpm+apc+mysql; question I have is when I look at the github from Omega8cc in the install nginx it doesn't seem as if mysql is taken into consideration or am I missing something? Additionally, should I use postgres instead of mysql, is there a benefit one over the other?

Regards,
Chris W

PHP must be compiled with

jcisio's picture

PHP must be compiled with MySQL (but that's enabled by default). That's all.

About pgsql, I couldn't recommend it. Not all modules support it (they should, though). About the performance, there is a discussion at If you are running Drupal with Postgres as the database it runs at 1/2 the speed compared to running Drupal with MySQL as the database?

PHP by default

cwittusen's picture

So when I build php the fact that I build that with support for mysql takes care of this "issue" then?

Ok, so MySQL is still the winner.

Regards,
Chris W

Best way to do this?

cwittusen's picture

So, I just got my new server and I'm getting ready to install nginx+php-fpm+apc+mysql; however, when I look at the github for Omega8cc, I feel a bit lost because I'm not sure how to use it. I can read the files but it says nginx is running on port 88 because of port 80 is used by Pound/Nginx load balancer or Varnish/Ncache fast proxy; however, I don't see any instructions for how that is configured or installed.

Additionally, I'm not sure how to use the provision .patch file, can someone assist me?

Regards,
Chris W

Yes, you can run nginx

brianmercer's picture

Yes, you can run nginx directly on port 80 by changing the listen directive on line 76 to your public IP address and port 80.

I believe the provision patch is only if you're using Aegir.

Ok but...

cwittusen's picture

Ok so I should just read the files and follow them or is there another approach I should be using with the github and the wonderful contributions?

Regards,
Chris W

I haven't seen a perfect step

brianmercer's picture

I haven't seen a perfect step by step walkthru for setting up a whole nginx+drupal server. Mostly it's tinker and google and learn.

I've tried to make

yhager's picture

I've tried to make http://github.com/yhager/nginx_drupal as simple as possible. But it only covers the nginx part, not the fastcgi/php part...

No such file...

cwittusen's picture

I'm working through Omega8cc's php-fpm install and at the following step I get the responses listed below, does it mean I have done something wrong previously?

#

step 2

#
./buildconf --force
mkdir fpm-build && cd fpm-build
cp -f /etc/init.d/php-fpm /etc/init.d/php-fpm.bak

RESPONSE
cp: cannot stat `/etc/init.d/php-fpm': No such file or directory

Regards,
Chris W

I'm not sure why that's

brianmercer's picture

I'm not sure why that's there. Maybe to preserve some settings if it's already installed.

I'm currently using php-fpm from the dotdeb repo, which is compiled for Debian, but has caused no major issues on Ubuntu 9.10 and it's very easy to install. However, it is PHP 5.3.2 and certain contrib modules have required patching to be compatible for PHP 5.3. http://groups.drupal.org/node/56558

Dotdeb repo

cwittusen's picture

I'm not to familiar with the dotdeb repo, I'm just now getting back into the life of "admin", been away from it for years since my career where going more into business. Now having to manage the server due to my own businesses is yet putting me back into the driving seat for a while so I'm trying to pick up as much as I can from this forum and the nginx/multisite group as well.

Regards,
Chris W

rsyslogd

cwittusen's picture

Does anyone recommend against rsyslogd when using nginx+php-fpm+mysql+apc? I have noticed that its consuming a fair amount of memory (120M+). Additionally, is munin a required combination with nginx-php-fpm+mysql?

Regards,
Chris W

rsyslog consumes about 1.1MB

brianmercer's picture

rsyslog consumes about 1.1MB on my system. It shouldn't use 120MB. I don't believe it is optional. You probably need some type of logger.

Munin (or cacti or collectd) continually collects data about your system and writes it to rrd format files. You can then use various rrd compatible tools to create historical graphs. I use collectd myself. It's nice to see memory use, load, cpu, network traffic in those pretty little graphs. Since it is writing data to your disk almost continually, it consumes one of your most precious resources, disk io. I use renice to prioritize it down and it doesn't seem to interfere with anything. Definitely something to consider after you have everything else running.

renice and step 3..

cwittusen's picture

Brian:
Thx; I'm not familiar with renice yet but if it does a lot of disk io then I would not like it right now, perhaps later. As with rsyslogd, not sure how you got it running on 1.1MB but I would love to find, I did a top and then shift +m and thats when I was that it was holding 120Mb.

I am at step 3 of omega8cc configuration of php-fpm but when I run the ../configure --with-fpm it doesn't work, not sure why; initially I had the autoconf2.13 issue but I resolved that by installing autoconf2.13 but now I got this. I'm ready to pay someone $200 to build a compete yum install of all this, to much time spend on the build. :)

Here is partial output of the ../configure --with-fpm

../configure: 14097: 5: Bad file descriptor
../configure: 14097: :: checking for __dn_skipname in -lresolv: not found
../configure: 14097: 6: Bad file descriptor
../configure: 14097: checking for __dn_skipname in -lresolv... : not found
../configure: 14097: ac_fn_c_try_link: not found
../configure: 14097: 5: Bad file descriptor
../configure: 14097: :: result: no: not found
../configure: 14097: 6: Bad file descriptor
../configure: 14097: no: not found
../configure: 14097: 5: Bad file descriptor
../configure: 14097: :: checking for dn_skipname in -lbind: not found
../configure: 14097: 6: Bad file descriptor
../configure: 14097: checking for dn_skipname in -lbind... : not found
../configure: 14097: ac_fn_c_try_link: not found
../configure: 14097: 5: Bad file descriptor
../configure: 14097: :: result: no: not found
../configure: 14097: 6: Bad file descriptor
../configure: 14097: no: not found
../configure: 14097: 5: Bad file descriptor
../configure: 14097: :: checking for __dn_skipname in -lbind: not found
../configure: 14097: 6: Bad file descriptor
../configure: 14097: checking for __dn_skipname in -lbind... : not found
../configure: 14097: ac_fn_c_try_link: not found
../configure: 14097: 5: Bad file descriptor
../configure: 14097: :: result: no: not found
../configure: 14097: 6: Bad file descriptor
../configure: 14097: no: not found
../configure: 14103: 5: Bad file descriptor
../configure: 14103: :: checking for ANSI C header files: not found
../configure: 14103: 6: Bad file descriptor
../configure: 14103: checking for ANSI C header files... : not found
../configure: 14202: ac_fn_c_try_compile: not found
../configure: 14204: 5: Bad file descriptor
../configure: 14204: :: result: no: not found
../configure: 14204: 6: Bad file descriptor
../configure: 14204: no: not found
../configure: 14252: ac_cv_header_dirent_dirent.h: not found
../configure: 14252: 5: Bad file descriptor
../configure: 14252: :: checking for dirent.h that defines DIR: not found
../configure: 14252: 6: Bad file descriptor
../configure: 14252: checking for dirent.h that defines DIR... : not found
eval: 1: Bad substitution

Regards,
Chris W

Discard...

cwittusen's picture

I just went back to step (2 step forward, step back :) ) now compiling it correctly.

Regards,
Chris W

Data collection per process?

dipen chaudhary's picture

Hi,

I haven't really used these monitoring tools but planning to, does these tools collect data per process as well or its system wide? For instance I would like to know how much memory, cpu did mysql consume over time. I am hoping thats possible?

Thanks


Dipen Chaudhary
Founder, QED42 http://www.qed42.com Drupal development

No doubt that it's possible,

brianmercer's picture

No doubt that it's possible, but you might have to write the plugin yourself.

monitoring plugins

andybill's picture

Not used munin but cacti has a fair number of plugins for monitorig (e.g.) MySQL
http://code.google.com/p/mysql-cacti-templates/wiki/MySQLTemplates

I haven't used it, but I hear

brianmercer's picture

I haven't used it, but I hear there's a Centos repository for php-fpm. see: http://adityo.blog.binusian.org/?p=654

I didn't think of it til you mentioned YUM.

php-fpm memory print

cwittusen's picture

So, I finally got through the build, now I see the following memory print when I run top, is it normal for php-fpm to consume 102M per child? What is the recommended number of children to spawn at start-up?

1331 mysql 20 0 238m 24m 6520 S 0 1.2 0:04.04 mysqld
1603 root 20 0 67784 13m 1816 S 0 0.7 0:00.55 miniserv.pl
18465 root 20 0 42024 7296 1644 S 0 0.4 0:02.02 munin-node
28111 myhealth 20 0 22132 4904 1592 S 0 0.2 0:00.24 bash
16971 root 20 0 102m 4300 1340 S 0 0.2 0:00.00 php-fpm
16972 www-data 20 0 102m 3784 824 S 0 0.2 0:00.01 php-fpm
16973 www-data 20 0 102m 3784 824 S 0 0.2 0:00.00 php-fpm
16974 www-data 20 0 102m 3784 824 S 0 0.2 0:00.00 php-fpm
16975 www-data 20 0 102m 3784 824 S 0 0.2 0:00.00 php-fpm
16976 www-data 20 0 102m 3784 824 S 0 0.2 0:00.00 php-fpm
1634 postfix 20 0 41584 3108 2204 S 0 0.2 0:00.08 tlsmgr

Regards,
Chris W

I think you're reading the

brianmercer's picture

I think you're reading the wrong column. You should be looking at the RESident column and not the VIRTual column. Also you can subtract the SHaRed column from each instance except one. So each php-fpm instance is using 2964 (3784-824) except for one instance which is actually using 3784.

On mine they typically are about 45000 RES and 33000 SHR because of the shared APC cache of about 32K. So each child process uses about 10-15k each.

Here's a free -m on my

brianmercer's picture

Here's a free -m on my system:

brian@nutmeg:~$ free -m
             total       used       free     shared    buffers     cached
Mem:           348        322         26          0         36        115
-/+ buffers/cache:        170        177
Swap:          511         19        492

so you can see out of the 340MB of my linode, from the second line, that 170MB is being used. Another 36MB is in buffers and 115MB is in cached, with 26 free.

my top atm (shift-m)

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
5155 mysql     40   0  120m  66m 3156 S    0 19.0   2:13.04 mysqld
4400 www-data  40   0  127m  50m  28m S    0 14.5   0:41.34 php5-fpm
4403 www-data  40   0  110m  38m  27m S    0 11.2   0:39.38 php5-fpm
4401 www-data  40   0  107m  32m  25m S    0  9.4   0:40.20 php5-fpm
4402 www-data  40   0  105m  32m  26m S    0  9.4   0:37.52 php5-fpm
30376 root      35  15 73732 8220 1188 S    1  2.3  89:39.10 collectd
4371 nobody    40   0 42676 6376  732 S    0  1.8   0:12.89 memcached
14952 www-data  40   0 18740 3808 1572 S    0  1.1   0:01.41 nginx
14955 www-data  40   0 18740 3496 1496 S    0  1.0   0:00.38 nginx
14954 www-data  40   0 18612 3424 1480 S    0  1.0   0:00.49 nginx
14953 www-data  40   0 18612 3396 1488 S    0  1.0   0:00.36 nginx
27573 root      40   0  8184 2676 2120 S    0  0.8   0:00.03 sshd
14554 root      40   0 18220 2548 1160 S    0  0.7   0:03.05 nginx
4399 root      40   0  102m 2444  872 S    0  0.7   0:00.06 php5-fpm
27584 brian     40   0  3604 1944 1296 S    0  0.5   0:00.01 bash
14956 www-data  40   0 18220 1840  448 S    0  0.5   0:00.00 nginx
12463 postfix   40   0  5868 1724 1408 S    0  0.5   0:00.08 qmgr
27438 postfix   40   0  5732 1672 1336 S    0  0.5   0:00.00 pickup
12459 root      40   0  5720 1604 1316 S    0  0.4   0:00.55 master
27582 brian     40   0  8316 1580 1004 S    0  0.4   0:00.00 sshd
27633 brian     40   0  2480 1140  872 R    1  0.3   0:00.03 top
2120 syslog    20   0 29328 1124  652 S    0  0.3  44:37.25 rsyslogd

So similar to yours. mysqld

brianmercer's picture

So similar to yours. mysqld gets up to about 84MB with a 48MB query cache. You can start using mysqltuner.pl and tuning-primer.sh to fine tune your mysqld variables after you get some actual use. I use collectd instead of munin, but munin seems very popular. I also have a small 6MB instance of memcached for variables and router tables and such, but I use boost so drupal page caching is off, otherwise memcached would fill up fast.

I reset some of them a couple days ago so they're not quite at their peak usage.

VIRT

cwittusen's picture

But what does the VIRT allocation mean, does it not take out of the overall memory though? I know when I read the man pages it states that it is for total of virtual memory allocated for the task, including all code, etc. I would assume that it has an impact on my overall memory consumption. If it doesn't, then I have been chasing the wrong thing for a while.

I still don't like the fact that I only have 500M+ left of my memory, I would love to be up and around 1GB.

Regards,
Chris W

VIRT must be useful for

brianmercer's picture

VIRT must be useful for something, but it doesn't show usage of physical memory. The "free" command shows your usage of physical and swap memory by code/data + buffers + cache.

As for number of php-fpm

brianmercer's picture

As for number of php-fpm children, I'm not sure for a high memory box like you have. For smaller VPSes like mine, four to six is fine, I'd say. Linode uses Xen virtualization and allocates 4 virtual CPUs to each node on physical servers with 8 physical CPUs. With four php-fpm instances I can tie up my full CPU allotment if all four are running CPU intensive tasks. If one is running a network or disk IO intensive task, then I could use a couple more children, but in my case I'd rather give that 10-15MB back to the OS for caching files from disk. (I use drush for cron so when cron tasks run, they start their own instance of php-cli and don't use any of my php-fpm children.) Since you probably have much more memory, you are probably better off going with more children, but it'll take some experimenting.

Other stuff I think are

brianmercer's picture

Other stuff I think are useful:

mysqltuner.pl (mysqld tuner)
tuning-primer.sh (mysqld tuner)
awstats (for web stat reports based on server logs)
fcgiwrap (needed by nginx to run awstats.pl web pages)
reniced (to give collectd lower priority)
duplicity (daily encrypted differential backup to amazon s3)
automyqlbackup (daily dump and rotated weekly dumps of databases for backup by duplicity)
openntpd (to keep server time synced)
apc (and the apc.php page that gives nice stats on apc usage)
memcached (and memcache.php stat page)
htop/iotop/mytop
phpmyadmin
imagemagick

APC

cwittusen's picture

Hi, I finally got my nginx+php-fpm+apc+memcache+mysql installed and configured and running; however, when I check the apc.php file I get the following response "No cache info available. APC does not appear to be running."

Now, I followed Omega8cc's guide of building/configure most of the stuff apart from using yhager's configuration of vhost.d setup for nginx; so in my php.ini which is located in /etc/php5/cli/ and in /etc/php5/apache2/ I have added the lines that Omega8cc stated would be needed (see below) but still it doesn't seem that I'm actually using apc. Can anyone help me figure this out? I even went through my phpinfo() and I did not find anything saying apc in that output.

This is what I added to my php.ini
#

add this to your php.ini

#

-- php.ini --

; Enable APC
extension="apc.so"
apc.shm_size = 128
apc.stat = 0

; Enable Memcache
extension="memcache.so"
memcache.hash_strategy="consistent"

; Enable Suhosin
extension="suhosin.so"
suhosin.request.max_vars = 8000
suhosin.post.max_vars = 8000

-- php.ini --

Regards,
Chris W

Look at your phpinfo() and

brianmercer's picture

Look at your phpinfo() and look where it says "Loaded Configuration File"

Or do an "updatedb" and "locate php.ini". There should be another php.ini around for php5-fpm. It might be at /etc/php5/fpm/php.ini or maybe at /usr/local/etc/...

Then make the apc.so changes.

The ones at /etc/php5/cli/ and /etc/php5/apache2/ won't be loaded for php5-fpm.

Loaded Config file

cwittusen's picture

I checked my phpinfo and it says none and the "Loaded Configuration File"; I don't have another php.ini file in the entire system but I do have php-fpm.conf. Here is the output from locate php.ini; on my phpinfo it points to /usr/local/lib for my php.ini but there is no php.ini there.

/etc/php5/apache2/php.ini
/etc/php5/cli/php.ini
/usr/share/doc/php5-common/examples/php.ini-dist
/usr/share/doc/php5-common/examples/php.ini-paranoid
/usr/share/doc/php5-common/examples/php.ini-recommended
/usr/share/php5/php.ini-dist
/usr/share/php5/php.ini-dist.cli
/var/opt/php-5.2.11/php.ini-dist
/var/opt/php-5.2.11/php.ini-recommended

/Chris

Regards,
Chris W

Loaded new php.ini

cwittusen's picture

I copied the php.ini from /etc/php5/cli to /usr/local/lib and then restarted everything and now it shows up in phpinfo and the apc.php shows me data.

Now the question is if that is a good way of doing it, I'm not sure the php.ini file in the cli directory has anything that would f-me up; so far it seems to work.

Regards,
Chris W

You didn't mention where the

brianmercer's picture

You didn't mention where the php-fpm.conf file is located, but I assume it's something like /usr/local/etc/php5/php-fpm.conf? You can try putting a php.ini file in that same directory. It might check there by default.

Omega8cc should probably add the --with-config-file-path=/usr/local/etc/php5/fpm parameter to the compile options to specify the location.

Looking at http://php.net/manual/en/configuration.file.php, other than recompiling you can probably add "-c /usr/local/etc/php5/fpm/php.ini" to the init script right before --fpm-config.

php-fpm.conf

cwittusen's picture

Brian:
php-fpm.conf is in /etc/; I put the php.ini in /usr/local/lib because it was looking at that place by default so it made sense to put it there.

I agree, Omega8cc probably should add that, it would make sense. I ended up modifying part of config values that she had after doing some research but without her part and yhagers help and yours, I would probably sit in my "dark" dungeon and still trying to get this to work.

However, now when apc is enabled, WOW, my sites are SMOKING. :)

Brian, thank you for your response.

Regards,
Chris W

My github recipe will be updated soon

omega8cc's picture

However: /usr/local/lib is here the default place for php.ini used by php-cli, so try to avoid that or be prepared for new problems (for example with Aegir drush tasks using standard php-cli, not php-fpm).

I don't use --with-config-file-path because I need many php-fpm instances on different ports, and also with different php.ini values, so I'm using php-fpm startup script(s) to specify both php-fpm config file and php.ini file. See example of my init script:

http://omega8.cc/dev/php-fpm-init.txt

By the way, this is why I'm using in step 2:

cp -f /etc/init.d/php-fpm /etc/init.d/php-fpm.bak

and in step 3:

cp -f /etc/init.d/php-fpm.bak /etc/init.d/php-fpm

because any custom php-fpm init script will be overwritten by default during install.

HTH ~ Grace

Is there any updates for

vedat.kamer's picture

Is there any updates for Aegir 0.4-alpha8?

This patch:

omega8cc's picture

This patch: http://omega8.cc/dev/provision.diff.txt is compatible with Aegir 0.4-alpha8. However Aegir dev-nginx branch includes now new nginx integration, so the patch will became obsolete soon and my github project will be updated with this complete, new configuration and some new improvements, like upload progress etc.

DanGarthwaite's picture

Grace,

Where can I download the old per system build instructions?

You were my oracle on how to build linux + nginx + php-fpm + APC + memcache stacks.

I'm not a hosting company, I'm just a consultant that 'speeds up' client's drupal websites on their servers.

-dan

Nginx alias- drupal

karthick62's picture

Hi,

I am using ubuntu 10.01, nginx 0.7.65 and drupal 6.19

I have drupal multisite set up like /documentroot/globalsite/subsite1 ..... /documentroot/mainsite/subsite.n... I have enabled all the sites using clean-urls provided symbolic links are created for all subdirectories. Its working fine.

Now I want to set up a drupal subdirectory on the documentroot/globalsite/subsite-x .I dont want to give symbolic links for this particular directory. I want to use alias for accessing this directory. am trying to use this.

location /subsite/ {
alias /document/globalsite/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;

}

am trying to get http://localhost/globalsite/subsite to http://localhost/globalsite/subsite/index.php (or install.php)

my setup goes like this

/documentroot/globalsite/sites/localhost.globalsite.subsite# ls
default.settings.php files images modules themes

nice share

iwhy's picture

nice share

High performance

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: