Step 1: Create an AWS Account
First things first: you need to create your AWS account. You can sign up here. You’ll have to provide a credit card and a phone number where you will be called as part of the online registration process for verification purposes. Amazon offers a Free Usage Tier, which is great to explore the services and even host real apps without being charged. Check the details here.
Step 2: Create an Instance
What type of EC2 instance should you use? I started my experiments with a Micro instance because its price structure is very attractive. However, after a few minutes to a couple of hours, my blog systematically became unresponsive and I had to restart Apache and/or MySQL. I did some research, and found out that other people were reporting similar problems. It may depend on your blog traffic. My blog typically gets a few thousand page views a day. It also hosts live sample applications running with a PHP or a Java back-end running on Tomcat. It looks like that combination was too much for a Micro instance. I tried a Small instance and the problems went away. Greg Wilson has a great post on the limitations of the Micro instance.
To create a new instance, access the AWS Management Console and click the EC2 tab:
- Choose an AMI in the classic instance wizard: I chose the Basic 32-bit Amazon Linux AMI.
- Instance details: Select the Instance Type you want to use. I chose Small (m1.small).
- Create a new key pair. Enter a name for your key pair (i.e. christophe) and download your key pair (i.e. christophe.pem).
- Select the quick start security group.
- Launch your instance.
Step 3: SSH into your Instance
Once your instance is running, you can ssh into it. First, you need to identify the address of your instance: Select the instance in the AWS Management Console, and look for the Public DNS in the instance description (bottom part of the screen).
Use that address (and a path to your .pem file) to ssh into your instance:
ssh ec2-user@ec2-50-17-14-16.compute-1.amazonaws.com -i ~/christophe.pem
If you get a message about your .pem file permissions being too open, chmod your .pem file as follows:
chmod 600 ~/christophe.pem
Many of the shell commands below require root access. To avoid having to prefix these commands with sudo, let’s just switch user once and for all:
sudo su
Step 4: Install the Apache Web Server
To install the Apache Web Server, type:
yum install httpd
Start the Apache Web Server:
service httpd start
To test your Web Server, open a browser and access your web site: http://ec2-50-17-14-16.compute-1.amazonaws.com (Use your actual public DNS name). You should see a standard Amazon place holder page.
Step 5: Install PHP
To install PHP, type:
yum install php php-mysql
Restart the Apache Web Server:
service httpd restart
Create a page to test your PHP installation:
cd /var/www/html
vi test.php
- Type i to start the insert mode
- Type <?php phpinfo() ?>
- Type :wq to write the file and quit vi
Open a browser and access test.php to test your PHP installation: http://ec2-50-17-14-16.compute-1.amazonaws.com/test.php (Use your actual public DNS name).
Step 6: Install MySQL
To install MySQL, type:
yum install mysql-server
Start MySQL:
service mysqld start
Create your “blog” database:
mysqladmin -uroot create blog
Secure your database:
mysql_secure_Installation
Answer the wizard questions as follows:
- Enter current password for root: Press return for none
- Change Root Password: Y
- New Password: Enter your new password
- Remove anonymous user: Y
- Disallow root login remotely: Y
- Remove test database and access to it: Y
- Reload privilege tables now: Y
Step 7: Install WordPress
To install WordPress, type:
cd /var/www/html
wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gzcd
This will uncompress WordPress in its own “wordpress” directory. I like having WordPress in a separate directory, but would rather rename it to “blog”:
mv wordpress blog
Create the WordPress wp-config.php file:
cd blog
mv wp-config-sample.php wp-config.php
vi wp-config.php
- Type i to start insert mode.
- Modify the database connection parameters as follows:
define(‘DB_NAME’, ‘blog’);
define(‘DB_USER’, ‘root’);
define(‘DB_PASSWORD’, ‘YOUR_PASSWORD’);
define(‘DB_HOST’, ‘localhost’); - Type :wq to write the file and quit vi
Open a Browser and access your blog: http://ec2-50-17-14-16.compute-1.amazonaws.com/blog (Use your actual public DNS name). This should trigger the WordPress configuration process.
Step 8: Map IP Address and Domain Name
To use your blog in production, you will have to:
- Associate an IP address to your instance
- Map your domain name to that IP address
To associate an IP address to your instance:
- In the AWS Management Console, click Elastic IPs (left navigation bar)
- Click Allocate New Address, and confirm by clicking the “Yes, Allocate” button
- Right-click the newly allocated IP address and select “Associate” in the popup menu. Select the instance you just created and click “Yes, Associate”
To map your domain name to your IP address, you will have to use the tools provided by your domain registrar. If you use GoDaddy, specify NS73.DOMAINCONTROL.COM and NS74.DOMAINCONTROL.COM as the name servers for your domain, and use the DNS Manager to modify the A record and point to your IP address. Documentation is available here.
Once everything is configured and mapped correctly, access the General Settings in the WordPress management console and make sure the WordPress Address and Site Address are specified correctly using your domain name as in the screenshot below.




Thx again Christophe.
I love your tutorials, it’s a great source of inspiration.
Hi Christophe,
Amazon CloudFormation already has an word press template (https://s3.amazonaws.com/cloudformation-templates-us-east-1/WordPress_Single_Instance.template), so if you don’t need some special configuration it is a viable option (and way faster to setup).
Hi
Thanks for the article, wish I had found it 20 mins earlier. This is my first attempt at such a feat! I have installed wordpress on EC2 and want to make it available on blog.mydomain.com.
I’ve made a mistake somewhere (I think by updating the WP general settings before completing all of your steps) and lost the site (I see a plain text version at blog.mydomain.com/wordpress.
When I go to blog.mydomain.com I see the BitNami welcome page.
I’ve registered the subdomain and pointed it at the newly created IP address.
I haven’t changed the name servers with my registrar.
Please help!
Thanks
Alistair
@Alistair: The instructions above do not use BitNami. If you see a BitNami welcome page, you must have followed other instructions or used another AMI. So it’s hard to tell what’s wrong with your specific setup. That being said, if you installed wordpress in its own “wordpress” directory and you want your blog to show up when accessing the root directory, you have to use an .htaccess file with a RewriteRule. I’m using: RewriteRule ^$ /blog.
Thank you for your tutorial! It was really helpful
I am currently having some trouble with associating my IP address with the instance.
After associating with it, I found that I am unable to go to the WordPress management console.
Can you please advise?
Thanks!!
Hi Christophe,
Could you share a bit more info on how to perform backup for wordpress on amazon ec2.
Are there certain information we need to know to avoid that “oppss” moment where the entire wordpress (app, file and db) gone without trace and cannot be recovered.
Thank you
aditya
After associating IP with my instance – SSH stopped working and WordPress is not responding :/
The public DNS changes when you restart the instance. Have you tried SSHing with the ip address you assigned?
Christophe,
I followed your instructions word for word, but unfortunately no matter was I do I cannot get the standard default amazon page to load, or the Public DNS to resolve at all…any advice? I have terminated and restarted from scratch about 3 times now…thanks!
Tyler,
Did the web server start successfully? Can you ping your host?
Christophe
Thanks Christophe, I had to set the HTTP rule in the security settings, everything is fine and dandy now! Thanks!
Great to hear!
Hi there, thanks a lot or this.
The only problem I have is that I can’t upload anything through wordpress. I believe this might have something to do with file and folder ownerships. Do you have any idea?
Thanks!
Same here. I’m running a similar installation, will try to change permissions to /var/www/html folder so that regular user ec2-user can read and write there, then download WordPress as that user and not as root.
What I did was, before downloading/installing WordPress (the wget command), allow reading/writing/executing things to everyone in the /html directory by writing this: chmod 777 var/www/html
Then I exited su mode by writing exit (prompt changes from # to $). Then I did the rest as the regular ec2-user instead of root, wgetting the latest WordPress ZIP, unzipping, renaming, etc. WIll let you know if it works when I’m over!
Nice job. Worked for me! thanks!
Just 2 typos: mysql_secure_Installation should be mysql_secure_installation
tar -xzvf latest.tar.gzcd should be tar -xzvf latest.tar.gz
Also, I was not sure if it was necessary to change:
define(‘DB_HOST’, ‘localhost’);
So I just left it alone. Seems to be working.
Thanks again!