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?
The same issue is happening to me… everything worked correctly, except that after associating the IP with my instance and going to “/blog” makes the browser spin for awhile, then gives me the blog page without any CSS. Attempting to login (wp-login) doesn’t work at all – spins for awhile then times out.
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!
I had this problem as well. It is necessary to go into the AWS console and click ‘Security Groups’ and then create a new rule: HTTP and ‘Add Rule’.
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!
Thanks for a great article – just worked through it and all worked out perfectly…
My question is, how do I configure my server for multiple domains ?
Is there a management tool I can install to do this ?
TIA, Dave
mysql_secure_Installation under the “Secure your database” step should be mysql_secure_installation. It’s apparently case sensitive and didn’t work until I lowercased the “i”.
Thanks for this guide, Cristophe, very helpful!
Can you comment on any differences that might exist if you were looking to have this wordpress site at conraets.org as opposed the /blog subdirectory? I have followed your instructions up until the end, but am not sure how to point the domain due to the fact that I’d like the blog to exist on the root domain.
Thanks again!
Jeff
Thanks so much – straight forward and clear …
2 small corrections –
mysql_secure_Installation should be mysql_secure_installation
and
tar -xzvf latest.tar.gzcd should be tar -xzvf latest.tar.gz
chrs
I really should have read the other comments .
chrs
I created the stack, the WP installation…now how do I connect to SFTP using a program such as Transmit. Can you help on this? I created a key pair but the key is not associated to the existing stack. Don’t know if this is the problem and how to solve it. Thanks
So helpful. Restored my faith in how mankind is dealing with technology :)
After installing wordpress if you are being prompted for ftp credentials when you try to add or delete plugins or themes try changing the ownership of the web files to apache which is the username that the Apache server runs under. Many thanks to Christopher Coenraiets for this great page of instructions. There is another good instructional post at http://compositecode.com/2011/03/29/aws-linux-ec2-wordpress-free/ that was very helpful.
chown -R apache /var/www/html
chmod -R 755 /var/www/html
This is a brilliant tutorial, it all worked perfectly…and I’m anything but a developper !
I’ve started with the micro version as i’m just launching the site…we’ll see
Regards
Paul
Christophe, is there a way to get a php site on ec2 that is not a wordpress blog? I’ve been trying to make it work on s3 but so far my site seems to be displaying more or less okay on Firefox -with minor details – but when I try to access the url on IE or Chrome I get a download message. From what I have learned so far about php driven sites I need ec2 and I spent some time learning how to create an instance but then the option presented is to launch a WP blog which I don’t want.
Johanna
Found this post extremely helpful when migrating my blog to Self Host WordPress on EC2. I recently had to deal with a big traffic spike and wrote a quick blog post about it, thought some of the other folks reading this post and getting started might find it helpful: http://www.etherealbits.com/?p=97.
Christophe- awesome, thanks so much for this, it was INCREDIBLY useful! FYI, the “quick-start-1″ security choice only enabled SSH for me. I had to go back into it and manually add HTTP and HTTPS.
Everything worked as far as installing WordPress , but when I tried to update a plugin and was asked about FTP username and password, well that is when my world began to unravel =[
Hi Christophe – thanks again for this great write up. I have one follow up question, if you don’t mind. I see that EC2 assigns a new public DNS when you restart the instance. but WordPress seems to use absolute paths in their urls, so when i restart the instance all of the links point to the old DNS and consequently fail. I’ve read the two solutions to this are to: 1) manually change the links; or 2) use a redirect plugin. Is there a way to address avoid this issue when installing WordPress after creating the instance – such as have WordPress use an elastic IP when it sets up its absolute paths?
Some quick tips for first-timers/corrections:
1. In Step 5 before typing ‘:wq’ you must hit the ‘esc’ key in terminal
2. In Step 6
mysql_secure_Installation
should read (notice the ‘i’ in installation is lower-case):
mysql_secure_installation
Very good info. Have you experience to make cluster for wordpress to avoid failure due bursting of single instance? In such case how to share files and database? How to routinely backup files? Any help
A great articles! Now time to move Tekkish over onto EC2! :-)
Hi Chris,
Thanks for the tutorial, but I am having trouble increasing the max_upload size, my theme is exceeding the limit
Cheers
Hello. Thanks so much for this blog entry. I was able to get up and running quickly. However I think I have discovered something that may be out of order in your steps. When you create an Elastic IP in step 8, you are given a different IP address than when you first set up the EC2 instance. If you install WordPress first, then create and use an Elastic IP, you will end up with a WordPress installation with broken links. This happened to me. I followed your steps to the letter and when WordPress installed, the domain was that long Public DNS assigned to me. WordPress must have stored this in the DB somewhere. After I created the Elastic IP, the DNS is now a single ip for the hostname and WordPress would try to load then I would get ugly unstyled broken pages. To test, I deleted my EC2 and followed your tutorial over again but this time, before installing WordPress, I added the Elastic IP. This time it worked. To prove myself, I did this 2 more times, one following your to the letter and the second by swapping the Elastic IP/Wordpress install steps and same perfect results. Hope this help someone with the same issue. Thanks again for this post!!!!!
IT IS AS SQUASHBRAIN SAYS– you MUST get an elastic IP and then associate the elastic IP with the amazon instance BEFORE doing the install, otherwise bad things. Another helpful thing — the security group the instance belongs to needs to have a lot of inbound services allowed, I allowed pretty much everything, such as HTTP, SSH, SFTP, HTTPS, ICMP (for pinging), MYSQL (not MS SQL). Works great. Thanks for the instructions Christophe, I could not have done it without you. Thanks also to Squashbrain for the fix.
Hi, I have just downloaded the Amazon free bundle and I am looking to put upload wordpress onto the amazon server – are you just referring to the blog side? as i want to do the full website?? thanks k
is this going to be a better option then paying for VPS or even dedicated server??
I have NEVER touch any server that isnt windows, this was my first commandline install, you made it so easy, working perfectly, thank you!
Thank you very much, realy good tutorial, it works perfect.
Im currently running a working wordpress blog on an EC2 instance also.
Im just on the “Small” size instance and it seems to be working fine. This is one of the cheaper instances.
I was able to cut a lot of time out cause i used plesk. That put php and apache an stuff on there for me.
If you interested to see it you can have a look at:
http://www.system-administration.net/step-by-step-tutorials/how-do-i-get-the-cloud/
Cheers guys!
Your comment is awaiting moderation.
Great article! I’m migrating my site from inmotion hosting to Amazon Web Services. I had some truble with inmotion some time ago with wp-cron using a lot of resources so I disabled wp-cron and created a custom cron job for my site using this tutorial http://wp.tutsplus.com/articles/insights-into-wp-cron-an-introduction-to-scheduling-tasks-in-wordpress/ which helped a lot. Any idea on how I can do the same (create a custom cron job) in order to save resources within Amazon Web Services pleas??
Hi thanks for this useful info.
Im trying to setup phpmyadmin but I am being denied permission to edit the files.
Im trying to edit the file: phpmyadmin.conf
Im presuming I need to chmod, I tired chmod o+w phpmyadmin with no luck.
Any tips?
Thank you very much for these useful tipps, I will soon migrate my blog to AWS.
What is a .pem file and how do I get one?
Hi there. this has all been easy enough but the trickier step for me seems to be explained with the phrase “and a path to your .pem file”
I’ve got the .pem file on my desktop but the terminal cant find it there. This much is clear.
Could you help guide me through how to put it into the right file so that terminal can find it and i can therefore ssh in?
any help really really really appreciated!
cheers
christian
Fantastic article! would have never figured it out with this!!!!!
Hello and thanks for the clear tutorial. :)
Do you have any information/experience on how much an average WordPress website costs you on AWS? I’m juggling between shared/semi-shared hosting and using AWS for a few websites.
I saw several comments that some of them are facing problem after associating the Elastic IP address.
To fix this problem, you need to update the new IP address in the database. The steps are here.
Login into MySQL db.
1. SELECT option_value FROM `wp_options` WHERE option_name = ‘siteurl’
You should see the old address.
Now run the below update statement by adding you Elastic IP address.
2. UPDATE option_value SET option_value = your_new_elastic_ip_address_goes_here
Thats should solve the problem. I used PHPMyAdmin to do the changes from browser itself with executing the SQL and it worked for me.
Thank you! Very good!
I’m only need to add http rule in Security but always perfect!
Hello.
Thanks for this guide. I am unable to ssh into the instance I have built. The error message I am receiving is “permission denied public key” I have set the local permissions for the key to read only. Any ideas why I am still receiving this message?
Thanks
Ira
Just fixed the issue: this information is correct: http://stackoverflow.com/questions/1454629/aws-ssh-access-permission-denied-publickey-issue
If experiencing the same issue as I noted in my question, and you are running Ubuntu 10.04 or later, then scroll down the above page to note a comment from “delinquentme” which fixes it. I am now logged in.
Ira
very thanks
you are my hero. I spent hours trying to do this. Then I found you tutorial. thank you.
Hello,
I work in SEO.
I’ve been visiting your site and found it very interesting.
I’m currently working on a website in a similar field, and I am interested in placing a text link on your site, in exchange for a monthly payment.
Does it sound interesting to you?
If so, I would be glad to get an email from you.
All the best,
Moran
Hi, my first time here, and a huge fun of yours already.
Here’s my case, recently I’ve transferred a website to my regular host that I would like to move and use the domain only to build a new website through Amazon EC2 from scratch. Meanwhile, how do I move this:”Index of /
jo/
oldfolder/
Apache Server at mydomain.com Port 80″
oldfolder safely onto my hard drive? At this point, I am only interested in the domain name.
Further, is it possible to move an existing wordpress website to Amazon EC2?
Your help is very much appreciated in advance.
Kindest regards,
Jo
Cheers for the info mate,
Is the micro instance you initially setup the free for the initial 12 months deal?
I’m getting the permission denied (publickey) error when I try and ssh in step 3. i’ve followed the instruction letter for letter up to that point.
Very good and well written information, Christophe. It might be helpful to add a section that explains how to install a ssl certificate such that access to the admin login screen and dashboard requires https. The objective being to encrypt the admin’s credentials and subsequent configuration activities in the dashboard.
WARNING: NOOB QUESTION AHEAD
Hello,
I am getting hung up at
Step 5: Install PHP
I get all the way down to the last line about :wg to write the file and quit vi.
I do it, but it doesn’t do anything. I don’t know how to get out without disconnecting.
When I go to …/test.php, there is nothing there. I have done the same thing with test2.php and test3.php
I would just skip over it, but I see that the next part about installing Word Press involves the same :wq command.
Little help ?
Great post. quick step by step guide, how do we connect ftp client for uploading files?
Hi my loved one! I want to say that this article is awesome, nice written and come with almost all vital infos. I’d like to peer extra posts like this .
This is really interesting, You are an overly skilled blogger.
I have joined your rss feed and look ahead to in search of
more of your wonderful post. Additionally, I have shared your website in my social networks
Hi! I’ve been following your web site for a while now and finally got the courage to go ahead and give you a shout out from Kingwood Tx! Just wanted to mention keep up the great work!
Good stuff! One thing that you might want to add is that with wp 3.5.1 it is good to change the ownership of wp-content to the apache group.
All things being equal to the instructions above, just type
sudo chown -R apache:apache /var/www/html/blog
This will keep one from getting annoying file permission errors when attempting to upload media, resulting in a bitter outlook and eventual angry-robot-spewing-sarin-gas-upon-mine-enemies rants on that same, imageless blog.
It is truly a nice and helpful piece of information. I am happy that you shared this useful information with us. Please keep us up to date like this. Thanks for sharing.
Thanks for the tip
I have only one problem
I setup everything as you said.
But I can only access my blog if I use my ip address.
Not my domain.
The domain said page not found.
is there any other thing I need to do other than associate a instance to my ip and set the NS and A records?
Thanks
I’ve written a detailed post on optimizing WordPress on AWS EC2 with Varnish Cache, Apache and W3 Total Cache.
http://jeffreifman.com/detailed-wordpress-guide-for-aws/
I was able to login using winscp with sftp mode, but how do I run the shell to type those commands?
Hi,
Brilliant tutorial, I am just left with a problem, .htaccess files are needed by wordpress and not matter how many tutorials I go through it doesn’t seem to be as simple as updating httpd.conf, I have set every AllowOverride ALL and restarted by have no luck at all.
Is there any chance you could point me in the right direction I feel so close to having a working install.
Many thanks.
I get this error.
Failure To Connect To Web Server
Any ideas?
Thanks for scripting this excellent put up..Beloved your content. You should do hold writing
Can someone please help. Whenever I navigate to my ip address I just get a tomcat installation page and when I navigate to my blog it gives me a 404 error. Some help please.
FYI: I had to also install php-xml on the AWS Amazon Linux install so WordPress could parse import files from other WordPress sites. Otherwise you get a blank page on import an an error in your httpd log. Thanks for the walkthrough! Saved me a lot of time.
Thanks for this guide, I found it to be quite helpful! However I am encountering an error “HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfil the request.” I renamed the database to ‘showcase’ instead of blog, at my site http://ken.mosaict.com/showcase/ I am not sure why this is so?
Just want to tell if you want a working controlpanel at ec2 there is a good guide here http://www.smarchsoft.com/virtualmin_on_centos6.html#preinstall since it’s pretty hard to get centos to work
Hi there everybody, here every person is sharing such know-how, thus it’s fastidious to read this webpage, and I used to pay a quick visit this blog all the time.
Loved this article. Simple and effective. Tho, with all the steps laid out for me, I have no idea what I’ve done. :/
What’s up, I would like to subscribe for this blog to get latest updates, therefore where can i do it please assist.