Nginx now properly supported in Aegir

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
omega8cc's picture

It finally works as expected (well, almost - it's still alpha! :). You can try Provision available on GitHub: http://github.com/omega8cc/provision. It includes modified install script and hostmaster makefile to make your life easier.

[UPDATE: now it supports also SSL integration and apt-get Nginx versions, with Boost compatibility, but it should be at least nginx-0.6.36, so with Debian you need backports, and with Ubuntu you need at least Karmic or newer.]

This version will be probably included in the upcoming Aegir 0.4-alpha9 release. In the meantime, I will add also some docs and Debian compatible install script, so you will be able to deploy Aegir powered server from scratch using just two shell scripts. This one-in-all script is used already in production on Voxel.net infrastructure, it is compatible with Voxel Adobe AIR desktop manager http://www.voxel.net/downloads/air, and allows to create *high* performance, complete Drupal hosting environment with Apache Solr multi-core etc. Stay tuned, since it will be far easier to use than you could expect.

This also means, that previously posted how-to http://github.com/omega8cc/nginx-for-drupal will be considered deprecated, however I will update it also, so it will be compatible with Aegir 0.4 alpha8 max.

Useful details: you can start with below steps:

1. Install Nginx using apt-get install nginx - it will create all standard config files and startup script for you.
2. Install latest Nginx from source (see below) - recommended since you need try_files compatible version.
3. Create one symlink as explained in the header http://github.com/omega8cc/provision/blob/dev-nginx/http/nginx/nginx.conf
4. Remember to add aegir ALL=NOPASSWD: /etc/init.d/nginx to /etc/sudoers.
5. Run (see below) installer taken from http://github.com/omega8cc/provision/blob/dev-nginx/install.sh.txt

Of course you need to create aegir user, database and dbuser first, as explained in the standard http://github.com/omega8cc/provision/blob/dev-nginx/docs/INSTALL.txt.

I will attach below a quick how-to for Nginx & PHP-FPM install, for your convenience.

Install required & useful stuff first

echo "deb http://ftp.us.debian.org/debian/ lenny main contrib non-free" > /etc/apt/sources.list
echo "deb-src http://ftp.us.debian.org/debian/ lenny main contrib non-free" >> /etc/apt/sources.list
echo "deb http://security.debian.org/ lenny/updates main contrib non-free" >> /etc/apt/sources.list
echo "deb-src http://security.debian.org/ lenny/updates main contrib non-free" >> /etc/apt/sources.list
echo "deb http://ftp.us.debian.org/debian experimental main" >> /etc/apt/sources.list
echo "deb-src http://ftp.us.debian.org/debian/ experimental main" >> /etc/apt/sources.list

wget -O- http://ourdelta.org/deb/ourdelta.gpg | apt-key add -
wget http://ourdelta.org/deb/sources/lenny-mariadb-ourdelta.list \
      -O /etc/apt/sources.list.d/ourdelta.list

aptitude update
aptitude full-upgrade

aptitude -y install locales cron ssh build-essential
aptitude -y install postfix
aptitude -y install apticron autoconf automake automake1.4 autotools-dev bc curl cvs defoma devscripts dnsutils dstat fontconfig-config git-core graphicsmagick-imagemagick-compat htop ifstat libapr1 libaprutil1 libc-client-dev libc-client2007b libc-client2007b-dev libcurl4-gnutls-dev libdbd-mysql-perl libdbi-perl libfilesys-diskspace-perl libfontconfig1 libfreetype6 libfreetype6-dev libfribidi0 libgd2-xpm libhtml-template-perl libjpeg-dev libjpeg62 libltdl7 libltdl7-dev libmariadbclient-dev libmariadbclient16 libmariadbd-dev libmcrypt-dev libmemcache-dev libnet-daemon-perl libpcre3 libpcre3-dev libplrpc-perl libpng-dev libpng12-0 libpq5 libsasl2-modules libssl-dev libt1-5 libt1-dev libtool libwww-perl libxml2-dev libxpm4 libxslt-dev libxslt1-dbg libxslt1-dev libxslt1.1 m4 makepasswd mariadb-client-5.1 mariadb-common mariadb-server-5.1 mc mcrypt nano ncurses-dev ntpdate pwgen python-dev python-mysqldb rsync shtool ssl-cert subversion sudo sysstat sysvconfig t1lib-bin time ttf-dejavu ttf-dejavu-core ttf-dejavu-extra xml-core xml2 zlib1g-dev zlibc unzip zip

cd /etc/mysql
mv -f my.cnf my.cnf.bak.copy
wget http://omega8.cc/dev/my.cnf.txt
mv my.cnf.txt my.cnf
invoke-rc.d mysql restart

#
# we need libevent-1.4.12
#
cd /var/opt
wget http://www.monkey.org/~provos/libevent-1.4.12-stable.tar.gz
tar -xzf libevent-1.4.12-stable.tar.gz &&
cd libevent-1.4.12-stable &&
./configure --prefix=/usr &&
make &&
make install
cd /var/opt

Install Nginx

cd /var/opt
git clone git://github.com/masterzen/nginx-upload-progress-module.git &&
wget http://sysoev.ru/nginx/nginx-0.8.45.tar.gz &&
tar -xzf nginx-0.8.45.tar.gz &&
cd nginx-0.8.45 &&
./configure --prefix=/usr \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=www-data \
--group=www-data \
--with-http_realip_module \
--with-rtsig_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--without-mail_pop3_module \
--without-mail_imap_module \
--without-mail_smtp_module \
--add-module=/var/opt/nginx-upload-progress-module/ \
--http-client-body-temp-path=/var/cache/nginx/client_body_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp &&
make &&
make install
cd ./../
update-rc.d nginx defaults; invoke-rc.d nginx start

Install PHP-FPM

cd /var/opt
wget http://www.php.net/distributions/php-5.2.11.tar.gz
wget http://download.suhosin.org/suhosin-patch-5.2.11-0.9.7.patch.gz
wget http://launchpad.net/php-fpm/master/0.6/+download/php-fpm-0.6~5.2.11.tar.gz
tar -xzf php-fpm-0.6~5.2.11.tar.gz
tar -xzf php-5.2.11.tar.gz
sh php-fpm-0.6-5.2.11/generate-fpm-patch
gzip -d suhosin-patch-5.2.11-0.9.7.patch.gz
cd /var/opt/php-5.2.11
patch -p 1 -i ../suhosin-patch-5.2.11-0.9.7.patch
patch -p1 < ../fpm.patch
./buildconf --force
mkdir fpm-build
cd fpm-build
../configure --with-fpm \
--enable-fastcgi \
--with-mysql \
--with-mysqli \
--enable-force-cgi-redirect \
--enable-discard-path \
--with-zlib \
--with-curl \
--with-curlwrappers \
--with-gd \
--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 \
--with-openssl \
--with-pdo-mysql \
--enable-soap \
--enable-ftp \
--enable-mbstring \
--enable-pcntl \
--enable-bcmath \
--with-kerberos \
--with-xsl \
--with-libevent=shared \
--with-mcrypt && make && make install
cd /etc/init.d
wget http://omega8.cc/dev/php-fpm.init.txt
mv php-fpm.init.txt php-fpm
chmod 700 php-fpm
perl -p -i -e "s/(\/usr\/local\/etc\/php\.ini)/\/path\/to\/your\/php\.ini/g" /etc/init.d/php-fpm
update-rc.d php-fpm defaults; invoke-rc.d php-fpm start

Now run Aegir installer
su -s /bin/sh aegir -c "sh install.sh.txt aegir.example.com --http_service_type='nginx' -d"

Enjoy & share your experience!

Comments

Very nice how to. Thank you

vedat.kamer's picture

Very nice how to. Thank you so much. There's two problems with Debian 5.0:

  1. Your my.conf (http://omega8.cc/dev/my.cnf) doesn't start MySQL.
  2. Compiling php-fpm requires libevent-1.4.12. (http://github.com/omega8cc/nginx-for-drupal/blob/master/php-fpm-install.txt)

Thanks for testing and

omega8cc's picture

Thanks for testing and reporting your issues.

My my.cnf works with MariaDB (suggested in the "Install required & useful stuff first" part above), however to get it working with latest dev-nginx / dev-ssl branch of Aegir you will have to comment out the "bind-address" and restart, to allow MariaDB listening on the public IP. It is an important change introduced in the Aegir head to allow multi/remote servers management and can't be avoided. I just modified that example my.cnf to match new requirements.

Yes, php-fpm requires newer libevent, so to make it more complete, I will add the source build how-to above.

Also there is problem with

vedat.kamer's picture

Also there is problem with http://omega8.cc/dev/php-fpm.init.txt on lenny.

This example php-fpm start

omega8cc's picture

This example php-fpm start script allows you to define your php.ini location, so before using it, please replace the -c /usr/local/etc/php.ini with your php.ini custom location.

This is the code I used to

vedat.kamer's picture

This is the code I used to install php-fpm & nginx:

### php-fpm

cd /var/opt
wget http://www.php.net/distributions/php-5.2.13.tar.gz
wget http://download.suhosin.org/suhosin-patch-5.2.13-0.9.7.patch.gz
wget http://launchpad.net/php-fpm/master/0.6/+download/php-fpm-0.6~5.2.patch
tar -xvzf php-5.2.13.tar.gz
gunzip suhosin-patch-5.2.13-0.9.7.patch.gz
cat suhosin-patch-5.2.13-0.9.7.patch | patch -d php-5.2.13 -p1
cat php-fpm-0.6~5.2.patch | patch -d php-5.2.13 -p1
cd php-5.2.13
./buildconf --force
./configure --with-fpm \
--enable-fastcgi \
--with-mysql \
--with-mysqli \
--enable-force-cgi-redirect \
--enable-discard-path \
--with-zlib \
--with-curl \
--with-curlwrappers \
--with-gd \
--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 \
--with-openssl \
--with-pdo-mysql \
--enable-soap \
--enable-ftp \
--enable-mbstring \
--enable-pcntl \
--enable-bcmath \
--with-kerberos \
--with-xsl \
--with-libevent=shared,/usr/local/lib \
--with-mcrypt
make all install
update-rc.d -f php-fpm defaults
mkdir /etc/php
cp php.ini-recommended /etc/php/php.ini
cd ..

### nginx

apt-get install nginx
cd /var/opt
git clone git://github.com/masterzen/nginx-upload-progress-module.git &&
wget http://sysoev.ru/nginx/nginx-0.8.45.tar.gz &&
tar -xzf nginx-0.8.45.tar.gz &&
cd nginx-0.8.45 &&
./configure --prefix=/usr \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=www-data \
--group=www-data \
--with-http_realip_module \
--with-rtsig_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--without-mail_pop3_module \
--without-mail_imap_module \
--without-mail_smtp_module \
--add-module=/var/opt/nginx-upload-progress-module/ \
--http-client-body-temp-path=/var/cache/nginx/client_body_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp &&
make &&
make install
cd ./../
cd /etc/nginx
rm /etc/nginx/nginx.conf
wget http://github.com/omega8cc/provision/raw/master/http/nginx/nginx.conf
ln -s /var/aegir/config/nginx.conf /etc/nginx/conf.d/aegir.conf
ln -s /var/aegir/config/includes/fastcgi_params.conf /etc/nginx/fastcgi_params.conf
update-rc.d nginx defaults; invoke-rc.d nginx start

php-fpm & nginx is working but I'm getting error while installing aegir:

SQLSTATE[HY000] [2005] Unknown MySQL server host 'root' (1) [8.07 sec, 4.12 MB] [error]
Drush command could not be completed. [8.07 sec, 4.13 MB] [error]
Output from failed command : [error]

Fatal error: Call to a member function quote() on a non-object in /var/aegir/.drush/provision/db/db.drush.inc on
line 311
[8.07 sec, 4.13 MB]
An error occurred at function : drush_provision_hostmaster_install [8.07 sec, 4.08 MB] [error]

Any idea?

As I mentioned in this

omega8cc's picture

As I mentioned in this comment http://groups.drupal.org/node/81339#comment-253104 you have to change your MySQL/MariaDB configuration to allow listening on your public IP address/hostname. Make sure you have hostname matching your IP, of course. It seems you have not FQDN hostname "root" only.

I receive 404 for

vedat.kamer's picture

I receive 404 for http://github.com/omega8cc/provision/blob/master/install.sh.txt. And this http://github.com/omega8cc/provision/raw/dev-nginx/install.sh.txt dosn't provide support for nginx. When I try to install with su -s /bin/sh aegir -c "sh install.sh.txt aegir.example.com --http_service_type='nginx' -d". Also there is no file at /var/aegir/config/nginx.conf location.

When I was installing Aegir, sudo asked me password for aegir user. I think this is because of apache defualts of install script:

Running: /var/aegir/drush/drush.php @hostmaster hosting-setup --backend [190.78 sec, 4.19 MB] [command]
[sudo] password for aegir:

Do you have any idea about it?

For the sudo password, double

neokrish's picture

For the sudo password, double check if you have the following done.

5. Remember to add aegir ALL=NOPASSWD: /etc/init.d/nginx to /etc/sudoers.

Only when the above step is skipped, you will be prompted for a password.

It was added. The problem was

vedat.kamer's picture

It was added. The problem was repo is changed. When I used http://github.com/omega8cc/provision-nginx/raw/master/install.sh.txt script, Aegir installed with nginx support without any problem.

In the meantime I have

omega8cc's picture

In the meantime I have updated my github repo to keep it in sync with git.aegirproject.org official repo. Now fixed also install.sh.txt file to keep it easy for install from my github instead of Aegir git head until it is included in the git head. I'm sorry for unexpected problems during repo updates.

And I have a question about

vedat.kamer's picture

And I have a question about nginx. When I visit http://localhost/phpinfo.php, nginx gives me phpinfo.php for download. How can I run this php file on nginx? php-fpm is installed.

When I run phpinfo.php from shell, I see that php.ini file is located at "Configuration File (php.ini) Path => /usr/local/lib". But I have php_opts="--fpm-config $php_fpm_CONF -c /etc/php5/cgi/php.ini" line on /etc/init.d/php-fpm.

Aegir is running now :) So

vedat.kamer's picture

Aegir is running now :) So there's no problem with nginx.

When I visit

vedat.kamer's picture

When I visit http://siirden.net/admin/reports/cache, I receive this error:

Fatal error: Class 'CacheEngine' not found in /var/aegir/pressflow/sites/all/modules/cache/engines/xcache.inc on line 12

Do you have any idea about it? Thank you so much. Best regards.

It is not related to this

omega8cc's picture

It is not related to this thread about Nginx and Aegir. But you can try to use this version: http://omega8.cc/dev/cache.tar.gz

I never used Xcache/APC there and always recommend to use Memcache and/or Redis, with failover to standard database. Also, please keep in mind that this module is now broken in Pressflow 6.17 but should work with vanilla Drupal or with Pressflow 6.16.

UPDATE

omega8cc's picture

Now it supports also SSL integration and apt-get Nginx versions, with Boost compatibility, but it should be at least nginx-0.6.36, so with Debian you need backports, and with Ubuntu you need at least Karmic or newer.

This version will be probably included in the upcoming Aegir 0.4-alpha9 release.

UPDATE

omega8cc's picture

Now you can use vanilla nginx.conf file (it comes with standard apt-get install) and you need only one symlink to integrate Aegir config files automatically:

$ ln -s /var/aegir/config/nginx.conf /etc/nginx/conf.d/aegir.conf

which github to use?

IrishGringo's picture

you say above: "
This also means, that previously posted how-to http://github.com/omega8cc/nginx-for-drupal will be considered deprecated,"

but when I look at the details and readme, it looks very well documented. Is this really deprecated?

also, the instructions say that Ubuntu 10.04 is one of the required options. But that is using php5.3. There is a discussion about "pinning back' to php5.2. It seems that perhaps using Umbutu 9.10 would be a better solution to keep things simpler?
so what is the best distro to use for a VPS?