Greg Harvey from Code Enigma presented their server configuration - our recipe for super-fast, robust and reliable performance from cheap virtual hardware. http://hosting.codeenigma.com/
1. professional services for the web
consultancy design development hosting training support
Saturday, March 2, 13
2. Making your
cheap VM fly!
Saturday, March 2, 13
3. The slides
Download them here:
http://www.codeenigma.com/sites/default/files/field/
blog-uploads/vm.pdf
Saturday, March 2, 13
4. Getting started
What do you need?
A virtual server - you can buy one (e.g. Linode, Rackspace)
or you can run one on your computer (e.g. VMWare)
I’m using VirtualBox
Saturday, March 2, 13
6. VirtualBox because...
One reason:
VAGRANT!
It makes setting up a VM on your computer very easy
http://vagrantup.com
http://www.vagrantbox.es
Saturday, March 2, 13
7. VirtualBox because...
Quick plug:
16:30
Room BG104
Vagrant: A Crash Course
with Marcus Deglos
Saturday, March 2, 13
8. Choose a base OS
Assuming Linux here
You could use Ubuntu, Redhat, Debian, Mint, blah blah blah
We’re using CentOS...
Saturday, March 2, 13
10. Don’t go, here’s why...
I’m lazy
It doesn’t really matter
I’ll do a quick Ubuntu / Debian run through at the end
Please stay!
Saturday, March 2, 13
11. OK, let’s go...
To prepare, we have:
1. Downloaded a basic CentOS base box for Vagrant
2. Brought up the network interface
3. Installed yum-priorities
4. Installed nano (I know, but I hate vim!)
Saturday, March 2, 13
12. OK, let’s go...
We also installed a couple of repositories for CentOS:
(Note, order is important.)
1. EPEL
rpm --import https://fedoraproject.org/static/0608B895.txt
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
2. Remi
rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
Saturday, March 2, 13
13. OK, let’s go...
See also this excellent HOWTO which, though modified, is
the basis for what I am demonstrating:
http://www.howtoforge.com/installing-nginx-with-php5-
and-php-fpm-and-mysql-support-on-centos-6.3
Saturday, March 2, 13
14. The database
At Code Enigma we use Percona, because it’s fully MySQL
compatible but significantly quicker.
Percona keep their own Linux repositories:
rpm --import http://www.percona.com/downloads/RPM-GPG-KEY-percona
rpm -ivh http://www.percona.com/downloads/percona-release/percona-
release-0.0-1.x86_64.rpm
Saturday, March 2, 13
15. The database
Don’t forget to assign the new Percona repo a priority!
Then we can install and start the database server:
yum install Percona-Server-client-55 Percona-Server-server-55 -y
service mysql start
Secure it and make sure it comes back after reboot:
mysql_secure_installation
chkconfig --levels 235 mysql on
Saturday, March 2, 13
16. The web server
Here we use Nginx, which is much faster than Apache but
there is one important thing you should know:
• No .htaccess files!
All that stuff that comes with Drupal - it needs to go in
your Nginx server configuration
Saturday, March 2, 13
17. The web server
Nginx is in the EPEL repository, so install away!
yum install nginx -y
Yup, that’s it!
Note, in CentOS the web root directory is in an odd place:
/usr/share/nginx/html
Saturday, March 2, 13
18. But what about PHP?
Indeed, there is no PHP ‘module’ equivalent for Nginx.
Instead we use PHP-FPM, a packaged version of FastCGI
This is available for CentOS in the ‘Remi’ repository
Saturday, March 2, 13
19. But what about PHP?
The standard set of packages needs a slight tweak:
DON’T use php-mysql
DO use php-mysqlnd instead
yum install php-fpm php-cli php-mysqlnd php-gd php-imap php-ldap php-odbc php-pear
php-xml php-xmlrpc php-magickwand php-magpierss php-mbstring php-mcrypt php-mssql
php-shout php-snmp php-soap php-tidy -y
Saturday, March 2, 13
20. But what about PHP?
Then there’s APC, opcode caching for PHP
yum install php-pecl-apc -y
And finally, let’s make sure these services start!
chkconfig --levels 235 nginx on
chkconfig --levels 235 php-fpm on
Saturday, March 2, 13
21. Configuration time
With all the building blocks in place, it’s time to configure!
1. The firewall - let’s allow HTTP traffic:
/etc/sysconfig/iptables
-A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -p tcp --dport 443 -j ACCEPT
Saturday, March 2, 13
22. Configuration time
2. PHP configuration:
APC needs 128M RAM (shm_size) to be effective
http://2bits.com/articles/importance-tuning-apc-sites-high-number-drupal-modules.html
3. Nginx configuration:
- Drupal .htaccess file rules
- FastCGI configuration
- We have a consolidated configuration file
Saturday, March 2, 13
23. Configuration time
/etc/php.d/apc.ini
[...]
; The size of each shared memory segment, with M/G suffixe
apc.shm_size=128M
[...]
/etc/nginx/nginx.conf
[...]
worker_processes 4;
[...]
keepalive_timeout 2;
[...]
Saturday, March 2, 13
24. Configuration time
/etc/nginx/conf.d/default.conf
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
root /usr/share/nginx/html;
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Saturday, March 2, 13
25. Configuration time
/etc/nginx/conf.d/default.conf
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /.ht {
deny all;
}
Saturday, March 2, 13
27. Let’s Drupal!
REMEMBER there are some very specific Nginx
configurations for Drupal:
http://wiki.nginx.org/Drupal
Saturday, March 2, 13
28. OK, but where’s Varnish?
Good question!
Less than 4GB RAM
Varnish does more harm than good!
Saturday, March 2, 13
29. Other bits
What about drush?
http://packages.codeenigma.com/debian/pool/main/
What about Ubuntu / Debian?
All of these packages are available in the ‘dotdeb’ repo:
http://www.dotdeb.org/
http://www.webhostingtalk.com/showthread.php?t=1025286
Saturday, March 2, 13
30. Other bits
Don’t forget memcached!
http://drupal.org/project/memcache
Highly recommended as a replacement cache back-end
Available in all ‘major’ Linux repositories
We usually give memcached 512M RAM
Saturday, March 2, 13