Here's a holiday recipe for infrastructure nerds like me: how to build a working Drupal install on an EC2 machine. I build Drupal on my Amazon Basic Linux micro-instance, and not the more popular Ubuntu-flavoured AMIs. I'll cut straight to the action here, then explain why I've done it this way in a later post.
Below are the couple dozen commands required to make Drupal go, in the form of a cheat sheet. I have included very few explanations of the commands, config or anything else to make it easy to learn. This is all CLI voodoo, only understood by Linux sysadmins and other computer nerds.
The three key ingredients are PHP, MySQL, and Drupal. It should not be followed by anyone unwilling to spend time researching what on earth is going on and to waste time troubleshooting. In fact, a web developer could spend his entire career getting to know these ingredients.
Time taken to complete is wildly variable. If everything goes smoothly, this process can take minutes. If something goes wrong there is no end to the time that can get sucked up in troubleshooting. There is a huge amount that can go wrong here. I have made one simple mistake and wasted days trying to find it. Computers are unforgiving.
The first thing to cook up is a PHP processor. Follow these four steps (I often use four steps to build an enterprise application).
- Install. The command is yum install php
- Configure. The most common change is tweaking the memory limit.
- Run. The web server needs a restart to pick up the new PHP processor module.
- Check. php -v
- The next thing to do is spice up PHP with a selection of optional extras:
yum install php-mysql php-xml php-mcrypt php-mbstring php-gdEach of these packages depends on other packages. Installing php-mysql also installs mysql-libs and php-pdo; php-xml depends on libxslt; and php-mcrypt needs libmcrypt and libtool-ltdl. The yum package install system takes care of working all this out automatically.
- I need a few tools to help me get even more PHP extras: PEAR (PHP Extension and Application Repository), PECL (PHP Extension Community Library) and files needed for building PHP extensions:
yum install php-pearyum install php-devel
- Drupal can seem a little slow. I can speed it up with APC (Alternative PHP Cache): yum install php-pecl-apc
- Install. yum install mysql-server
- Run. /etc/init.d/mysqld start
- Configure. mysqladmin -u root password 'Pa55word'
- Check. mysql -u root -p
Install a compiler
A compiler is used to build tools from source code. Not every optional extra is available as a binary installation package in Amazon's repository. Sometimes I need to compile code.
Security experts don't like the taste of a compiler on a production machine. They will not allow a compiler near the general public because of a history of abuse: in the right hands, it could give full system privileges.
yum install gcc
- wget http://ftp.drupal.org/files/projects/drupal-7.10.tar.gz
- gunzip drupal-7.10.tar.gz
- tar xf drupal-7.10.tar
- mv drupal-7.10/* /var/www/html/
- mv drupal-7.10/.* /var/www/html/
- cd /var/www/html/sites/default/
- cp default.settings.php settings.php
- chmod 666 settings.php
- vi settings.php (this is where I tell Drupal where the database is)
- chmod 777 .
- rm -rf drupal-7.10/
- gzip drupal-7.10.tar
Create a database and user
These are SQL commands, not shell commands.
- GRANT usage ON *.* TO drupal7user@localhost IDENTIFIED BY 'Pa55w0rd';
- CREATE DATABASE drupal7db;
- GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES ON `drupal7db`.* TO 'drupal7user'@'localhost' IDENTIFIED BY ‘Pa55w0rd';
The final piece of command line work is a restart of the Apache HTTP Server.
- /etc/init.d/httpd stop
- /etc/init.d/httpd start
The next part involves configuring Drupal using a web browser.
The last part of the install process takes place in the new Drupal web site so it's time to stop using the command line and start using a web browser. The URL to use is along the lines of 'http://ec2-1-2-3-4.eu-west-1.compute.amazonaws.com/install.php". Typing this URL into a web browser instructs the web server to run a script named "install.php". This script guides you through the final steps.
Note: This install URL is an example, not a real one. The DNS name for your EC2 machine will definitely not contain the text "1-2-3-4", and it may not have "eu-west-1" either. If you copy this example URL into a web browser, it will fail to find the web site and display an error along the lines of "can't find ec2-1-2-3-4.eu-west-1.compute.amazonaws.com".
View the resulting example homepage at http://ec2-1-2-3-4.eu-west-1.compute.amazonaws.com/.
Cool and serve
I've built it. Now the editors need to add content and I need to maintain it.
System administration will be ongoing. For instance, my Drupal site does not have much memory to play with, so if the site gets popular, that will need to be managed. If customers perceive my site as slow, I can speed it up by adding a cache, optimising the database, and complaining to editors about their page sizes.
Nick Hardiman builds and maintains the infrastructure required to run Internet services. Nick deals with the lower layers of the Internet - the machines, networks, operating systems, and applications. Nick's job stops there, and he hands over to the designers and developers who build the top layer that customers use.