You are here

How to Install Drupal on Amazon EC2

Create a new instance on you AWS management console. For this how-to I selected 64 bit Amazon Linux (This is the free micro server that amazon offers).

On the Amazon EC2 Console Dashboard click Instances on the sidebar. You will see a list of running instances (you may have to wait for it to start up).

Note the security group that your instance is using and click on Security Groups on the sidebar. Select the security group associated with your instance and add a new rule for http and apply. This will allow web traffic over port 80.


Select the instance you just created and select Instance Actions > Connect. Here you will find instructions on how to connect by ssh.

Once you have connected by ssh run the following installs:

sudo yum -y update
sudo yum -y install httpd mysql mysql-server php php-cli php-gd php-intl php-mbstring php-mysql php-pdo php-pear php-xml php-xmlrpc 

Make sure services automatically start on a reboot:

sudo chkconfig httpd on
sudo chkconfig mysqld on
sudo service httpd start
sudo service mysqld start 

Edit your httpd.conf:

sudo cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.old
sudo vi /etc/httpd/conf/httpd.conf

find <Directory "/var/www/html"> and under that change AllowOverride None to AllowOverride All

Press Ctrl + C and type :wq to save and quit.

Restart apache for changes to take effect:

sudo service httpd restart 

Set your mysql root password

sudo mysqladmin -u root password 'change-password' 

Mysql security:

sudo mysql -u root -p
mysql> DROP DATABASE test; 
mysql> DELETE FROM mysql.user WHERE user = ''; 

Create the database that drupal will use:

mysql> CREATE DATABASE drupal;

Press Ctrl + C to exit mysql.

Now your server is ready for drupal. I'm going to use drush to install:

sudo pear upgrade
sudo pear channel-discover
sudo pear install drush/drush 

Next use drush to download the latest drupal version and then move it to the web root directory (Make sure to substitute the the name of the latest distribution for "drupal-7.x")

cd /var/www/html/
sudo drush dl
sudo mv drupal-7.x/* ./
sudo mv drupal-7.x/.htaccess ./
sudo rm -r drupal-7.x 

Create the files directory and the settings.php file

sudo mkdir sites/default/files
sudo chmod 777 sites/default/files/
sudo cp sites/default/default.settings.php sites/default/settings.php
sudo chmod 777 sites/default/settings.php 

Open your site in a browser and complete drupal install process, your site can be reached at the public DNS listed in your AWS console when you select an instance and should look something like

After that go back to your terminal and set the permissions on the settings.php file.

sudo chmod 644 sites/default/settings.php 

That's it, you should now have the latest version of drupal up and running on your ec2 instance.



When I run:
# sudo yum -y install httpd mysql mysql-server php php-cli php-gd php-intl php-mbstring php-mysql php-pdo php-pear php-xml php-xmlrpc

It says:
etting up Install Process
No package httpd available.
No package mysql available.
No package mysql-server available.
No package php available.
No package php-cli available.
No package php-gd available.
No package php-intl available.
No package php-mbstring available.
No package php-mysql available.
No package php-pdo available.
No package php-pear available.
No package php-xml available.
No package php-xmlrpc available.
Nothing to do

I am running Amazon's Ubuntu 12.04.1

On ubuntu you can try using the apt-get package manager:
# sudo apt-get install httpd mysql mysql-server php php-cli php-gd php-intl php-mbstring php-mysql php-pdo php-pear php-xml php-xmlrpc

This was such a helpful set of instructions--thank you!

According to my terminal, I have successfully followed all these steps. However, when I put the public DNS into my browser URL, the page just times out. Any suggestions?

Make sure your drupal files are in the /var/www/html/ directory and not inside another folder in that directory. Example: The index.php file should be located at /var/www/html/index.php

I just noticed I wasn't clear in the instructions that you should be substituting the name of the current release when you did this "sudo mv drupal-7.x/* ./ ". So if the current release is 7.22 then you should put "sudo mv drupal-7.22/* ./ "

The site files are in the directory you mention, but when I try the public DNS—found on the EC2 Instances page—it just says not found. Everything else installed and changed without incident, just this. Ideas?

Make double sure all your files are in /var/www/html/ so that the index.php is at /var/www/html/index.html also make sure the .htaccess file was moved so that it is at /var/www/html/.htaccess

Thank you sooooo much for this tutorial!!!!! Awesome! The only bit I got stick on was the VIM editing but I managed a work around. Gold star!

Thank you very much for this great tutorial!

ditto! great job.

Just a note about the .pem file. In OS X, the .pem file simply needs to be in the Users home directory, e.g. /Users/<username>. Running "chmod 400 your_file.pem" should work and installation should work as well. Thanks so much for this walk-through!

very helpful!

Setup was a breeze with your directions. Thank you!

if you try this with a red hat instance, kill the iptables firewall or you won't be able to reach the drupal page with your browser

sudo service iptables stop

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.