Your SlideShare is downloading. ×

Make your cheap VM fly


Published on

Greg Harvey from Code Enigma presented their server configuration - our recipe for super-fast, robust and reliable performance from cheap virtual hardware.

Greg Harvey from Code Enigma presented their server configuration - our recipe for super-fast, robust and reliable performance from cheap virtual hardware.

  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. professional services for the web consultancy design development hosting training supportSaturday, March 2, 13
  • 2. Making your cheap VM fly!Saturday, March 2, 13
  • 3. The slides Download them here: blog-uploads/vm.pdfSaturday, 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 VirtualBoxSaturday, March 2, 13
  • 5. Why would you do that?!Saturday, March 2, 13
  • 6. VirtualBox because... One reason: VAGRANT! It makes setting up a VM on your computer very easy http://www.vagrantbox.esSaturday, March 2, 13
  • 7. VirtualBox because... Quick plug: 16:30 Room BG104 Vagrant: A Crash Course with Marcus DeglosSaturday, 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
  • 9. THAT’S IT! I’M LEAVING!!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 rpm -ivh 2. Remi rpm --import rpm -ivh, March 2, 13
  • 13. OK, let’s go... See also this excellent HOWTO which, though modified, is the basis for what I am demonstrating: and-php-fpm-and-mysql-support-on-centos-6.3Saturday, 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 rpm -ivh release-0.0-1.x86_64.rpmSaturday, 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 onSaturday, 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 configurationSaturday, 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/htmlSaturday, 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’ repositorySaturday, 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 -ySaturday, 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 onSaturday, 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 ACCEPTSaturday, March 2, 13
  • 22. Configuration time 2. PHP configuration: APC needs 128M RAM (shm_size) to be effective 3. Nginx configuration: - Drupal .htaccess file rules - FastCGI configuration - We have a consolidated configuration fileSaturday, 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 # location ~ .php$ { root /usr/share/nginx/html; try_files $uri =404; fastcgi_pass; 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 Apaches document root # concurs with nginxs one # location ~ /.ht { deny all; }Saturday, March 2, 13
  • 26. Let’s Drupal! Create a database, then: wget tar -zxvf drupal-7.20.tar.gz sudo mv drupal-7.20 /usr/share/nginx/ sudo mv /usr/share/nginx/html /usr/share/nginx/html_old sudo mv /usr/share/nginx/drupal-7.20 /usr/share/nginx/html sudo mkdir /usr/share/nginx/html/sites/default/files sudo cp /usr/share/nginx/html/sites/default/default.settings.php /usr/share/nginx/ html/sites/default/settings.phpSaturday, March 2, 13
  • 27. Let’s Drupal! REMEMBER there are some very specific Nginx configurations for Drupal:, 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? What about Ubuntu / Debian? All of these packages are available in the ‘dotdeb’ repo:, March 2, 13
  • 30. Other bits Don’t forget memcached! Highly recommended as a replacement cache back-end Available in all ‘major’ Linux repositories We usually give memcached 512M RAMSaturday, March 2, 13
  • 31. questions?Saturday, March 2, 13
  • 32. Those slides again blog-uploads/vm.pdfSaturday, March 2, 13
  • 33. professional services for the web consultancy design development hosting training supportSaturday, March 2, 13