make your cheap vm fly

33
professional services for the web consultancy design development hosting training support Saturday, March 2, 13

Upload: code-enigma

Post on 14-Jan-2015

4.958 views

Category:

Documents


1 download

DESCRIPTION

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/

TRANSCRIPT

Page 1: Make your cheap VM fly

professional services for the webconsultancy design development hosting training support

Saturday, March 2, 13

Page 2: Make your cheap VM fly

Making yourcheap VM fly!

Saturday, March 2, 13

Page 4: Make your cheap VM fly

Getting startedWhat 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

Page 5: Make your cheap VM fly

Why would you do that?!

Saturday, March 2, 13

Page 6: Make your cheap VM fly

VirtualBox because...One reason:

VAGRANT!

It makes setting up a VM on your computer very easy

http://vagrantup.comhttp://www.vagrantbox.es

Saturday, March 2, 13

Page 7: Make your cheap VM fly

VirtualBox because...Quick plug:

16:30

Room BG104

Vagrant: A Crash Course with Marcus Deglos

Saturday, March 2, 13

Page 8: Make your cheap VM fly

Choose a base OSAssuming Linux here

You could use Ubuntu, Redhat, Debian, Mint, blah blah blah

We’re using CentOS...

Saturday, March 2, 13

Page 9: Make your cheap VM fly

THAT’S IT! I’M LEAVING!!

Saturday, March 2, 13

Page 10: Make your cheap VM fly

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

Page 11: Make your cheap VM fly

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

Page 12: Make your cheap VM fly

OK, let’s go...We also installed a couple of repositories for CentOS:(Note, order is important.)

1. EPELrpm --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. Remirpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi

rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

Saturday, March 2, 13

Page 14: Make your cheap VM fly

The databaseAt 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

Page 15: Make your cheap VM fly

The databaseDon’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

Page 16: Make your cheap VM fly

The web serverHere 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

Page 17: Make your cheap VM fly

The web serverNginx 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

Page 18: Make your cheap VM fly

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

Page 19: Make your cheap VM fly

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

Page 20: Make your cheap VM fly

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 onchkconfig --levels 235 php-fpm on

Saturday, March 2, 13

Page 21: Make your cheap VM fly

Configuration timeWith 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

Page 22: Make your cheap VM fly

Configuration time2. PHP configuration:APC needs 128M RAM (shm_size) to be effectivehttp://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

Page 23: Make your cheap VM fly

Configuration time/etc/php.d/apc.ini

[...]; The size of each shared memory segment, with M/G suffixeapc.shm_size=128M[...]

/etc/nginx/nginx.conf

[...]worker_processes 4;[...]keepalive_timeout 2;[...]

Saturday, March 2, 13

Page 24: Make your cheap VM fly

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

Page 25: Make your cheap VM fly

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

Page 26: Make your cheap VM fly

Let’s Drupal!Create a database, then:

wget http://ftp.drupal.org/files/projects/drupal-7.20.tar.gztar -zxvf drupal-7.20.tar.gz

sudo mv drupal-7.20 /usr/share/nginx/sudo mv /usr/share/nginx/html /usr/share/nginx/html_oldsudo mv /usr/share/nginx/drupal-7.20 /usr/share/nginx/html

sudo mkdir /usr/share/nginx/html/sites/default/filessudo cp /usr/share/nginx/html/sites/default/default.settings.php /usr/share/nginx/html/sites/default/settings.php

Saturday, March 2, 13

Page 27: Make your cheap VM fly

Let’s Drupal!REMEMBER there are some very specific Nginx configurations for Drupal:

http://wiki.nginx.org/Drupal

Saturday, March 2, 13

Page 28: Make your cheap VM fly

OK, but where’s Varnish?Good question!

Less than 4GB RAMVarnish does more harm than good!

Saturday, March 2, 13

Page 29: Make your cheap VM fly

Other bitsWhat 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

Page 30: Make your cheap VM fly

Other bitsDon’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

Page 31: Make your cheap VM fly

questions?

Saturday, March 2, 13

Page 33: Make your cheap VM fly

professional services for the webconsultancy design development hosting training support

Saturday, March 2, 13