How to install WordPress on Amazon EC2

Last evening I signed up for Amazon Web Services (AWS) free usage tier to test the features and available services. Another reason was to use Amazon Simple Storage Service (Amazon S3) for storing my site’s backups.

The services are available at fairly reasonable price. Especially, if you are using S3 then you are making a very good deal.

Since, the free usage tier comes with 750 free hours of Amazon EC2 for each month for a year I thought of giving it a try and running WordPress.

Here is a step-by-step guide to setting up and running WordPress on Amazon EC2.

Sign up / Log in to your AWS Account:

If you do not have an AWS account then you can signup for the free usage tier and login to your account.

Setting up our server:

After you have logged in to AWS account, click “My Account / Console”  in top right corner of the screen and then click on “AWS Management Console”. You will be presented with something like this :

Click on “EC2” link and you will be taken to the EC2 Dashboard. Click on “Launch Instance” button to create a new instance. Follow the “Classic Wizard” as shown below :


Click “Continue” and on the next screen select “Ubuntu Server 12.04.1 LTS”

Quick-StartOn the next screen, you can proceed with the default settings. Make sure that “Instance Type” is set to “Micro” because that comes free with AWS Free Usage Tier. Click “Continue”

Instance-DetailsClick “Continue” on the next screen :

Instance-Details-1Again, click continue on the next screen.

After that you can add a “Name” for your instance for better organization. I have named it as “WordPress”.

Add-TagNow, you need to create a “Key Pair” so that you can connect easily with your server via SSH. Give an easy to remember name to your key pair and download the file. Keep the file in a place that you can remember. As you will need this file to connect with your server.

key-pairNext step is to configure the Firewall and make sure that only required ports are open for our server. Create a new security group. I have named it as “WP”. Now, click the dropdown for “Create a new rule” select SSH and click “Add Rule”. Repeat it for HTTP.


And we are done, setting up our instance. Click “Launch”.


Go to “Instances” page and you will see your new server being initialized and in some time it will be up and running. But, it’s not yet ready to run a WordPress site.

We need to setup the essential services to run WP : Apache, PHP and MySQL.

Connect via Terminal

Select the instance which we created above and click “Instance Actions”, in the pop-up menu click on “Connect”


Here you will need to enter the path of key file that you saved to your computer while creating the instance. Once that’s done you can click “Launch SSH Client”. If you wish you can also store key location in browser cache so that you won’t need to re-enter it every time you connect.


Setting up Apache :

Now, we are connected to our server. Next step is to setup Apache. By default, you will be logged in as user : ubuntu. Let’s switch the user to “root” so that we can get complete access. Use the following command to do so:

Use the following command in terminal to install Apache on your server:

After the installation is complete, look for Public DNS of your instance as shown below:


Copy this Public DNS and paste it in browser’s address bar. You will see a test page for Apache like below :


Installing PHP5

Our Apache is working and now we will install PHP5. For installing PHP5 use following commands in your terminal:

Note: If your PHP installation fails with a message such as “Unable to fetch some archives…” then run the following command and repeat the above process:

apt-get update

Now, your web files placed in /var/www/ can be accessed in the browser via Public DNS.

Let’s create a test PHP file to make sure that we have PHP running properly. Use the following command to do so :

This will create a new PHP file and open editor. Follow the following steps to add content to file :

  1. Press i to switch to insert mode.
  2. Type <?php phpinfo() ?>
  3. Hit escape key
  4. Type :wq to write the contents to file and quit the editor.


After creating the file run the file in your browser using the address as your-public-dns/mytest.php and it will show a page like below :


Now that PHP is running perfectly on our Apache. We need MySQL for creating database.

Install MySQL

Process for installing MySQL is similar to the process we followed for installing PHP. Use the following command in terminal to install MySQL :

During installation process you will be asked to create a password for “root” user. Keep this password safe in your memory or computer because this will be required to access the database later on.


Since we need to run PHP5 with MySQL, we will also install PHP module for MySQL using the following command

After this we can create database and continue with setting up WordPress. But, it will be nice to setup phpMyAdmin visual interface. So, let’s go ahead with it.

Installing phpMyAdmin

Use the following command to install phpMyAdmin and make sure you configure it for “Apache2” web server :


Follow the instructions on screen and remember the password that you enter in each field. After the installation of phpMyAdmin is complete we need to configure our Apache to make phpMyAdmin accessible via browser.

Use the following command for configuring Apache:

We restart the apache web server so that it picks up our changes.

That’s all done. Now, you can access phpMyAdmin in browser via your-public-dns/phpmyadmin

Enter username : root and the password which you created while installing MySQL.


Login to the admin and create a new database that we will use later for installing WordPress.

Now, we have all essential elements on our virtual server for running WordPress and everything is working perfectly. So, let’s install WordPress.

Downloading WordPresss

First  we will navigate to the home directory of our server and then download the latest copy of WordPress and extract it to /var/www directory by using the following command :

By default, all the files will be extracted in a directory “wordpress” so your files are at /var/www/wordpress/ to move the files to root of web server and then remove the “wordpress” directory we will use:

Before we install WordPress we need to map our domain name with the virtual server so that the site is accessible easily.

Mapping Domain Name :

Now we have everything ready in place and all we need to do is map our domain with our virtual server. For this you will have to associate an IP with the instance and map the domain name to that IP.

Head back to EC2 console and click “Elastic IPs” in the left pane. Click “Allocate New Address”


Now, you will see a new IP address in the console. Click “Associate Address” to associate this IP with your instance.


Now, switch to back to “Instances” panel and you can check the attachment status.


You will need to connect to your server by IP address now. Your hostname (public DNS) will no longer work, and if you detach the IP, your instance will be assigned a different hostname (public DNS). So, it’s best to not to change IP or detach it.

You can map your domain name to this elastic IP and it will work perfectly.

For now, I am using IP to access and setup the site. I entered elastic IP in address bar followed by /index.php and it came up with WordPress installation page.


That’s all! Now, you can use follow the steps of WordPress installation, enter required details and setup the site.

Oh but wait! I came up with this :


This is because our current apache user doesn’t have rights to write to the file. To fix this error we will grant access rights to our current apache user. First connect to the server via terminal as we did in the beginning and then execute following commands :

Here, www-datais the default apache user.

There is another issue left to be fixed. That is use of htaccess file and Pretty Permalinks in WordPrses. We will enable use of htaccess file and then enable the rewrite engine for Pretty Permalinks.

Enable htaccess and URL Rewrite

To make .htaccess files work as expected, you need to edit default apache file :

Look for :

Press i to enable insert mode and replace AllowOverride None to AllowOverride All. Now hit escape key and type :wq to write the changes to file and exit the editor.


Restart the apache web server for changes to take effect.

Continue with WP installation

Finally! You are all set to run WordPress site on Amazon EC2. Proceed with the installation process and it will work.

Like I have it here:


Here comes the end to my tutorial. I am not a server administrator or a linux expert. This was a result of my hit-and-trial experiments. So, if you have any suggestions for improvement then please feel free to share your comments.



  1. says

    Hi Puneet
    Just dropped in to say that I love the site running on Minimum 2.0.
    Your header graphic is outstanding.

    Looks as though Studiopress have really hit the spot with this one.

    BTW – how are you finding the Jetpack comment system?
    I’ve looked at it a few times.

    • says

      Hi Keith!

      Thanks for your kind words. Glad that you liked the header :-)

      Definitely, StudioPress has got the right theme for all minimalism lovers.
      It has got everything, perfect typography, layout, responsive design. I think, I would even get a Typekit account to use “Proxima Nova”.

      I am trying out Jetpack for the first time. It’s good as it comes packed with stats, post and comment subscriptions, custom css, lightbox gallery and many other features. All-in-one pack instead of using multiple plugins.

  2. says

    This is the best WordPress/EC2 tutorial I’ve seen so far. Great job!

    I think more and more people would use EC2 if they knew how to install everything. Unfortunately AWS’ documentation is not very user friendly for the average blogger, so it’s great that you did this.

    I love the speed of EC2, and that fact that it’s free for one year is awesome!

  3. Brendan says

    the following command doesn’t seem to be working for me.

    sudo chown -R www-data /var/www

    sudo chmod -R 755 www-data /var/www.

    I have tried it a few times but always returns the following error

    chmod: cannot access `www-data’: No such file or directory

    • puneet says

      You might need to change \”www-data\” to username for your system. Usually www-data is default username so I have used that for demo

      • chris says

        I had the same issue. I just went to my site, where it said “should we make a config.php flle?” I entered my database information, and the issue was solved. thanks Puneet!

    • /dev/nall says

      The 2nd command should be “sudo chmod -R 755 /var/www”; the “www-data” shouldn’t be in there.

  4. annurigved says

    Hi Puneet I have installed my wordpress on amzon using this tutorial, and I added a post in my wordpress.
    but when I visited my website it is still showing
    “It works!

    This is the default web page for this server.

    The web server software is running but no content has been added, yet.”
    Kindly assist

  5. rajendra says

    hi ,

    After i have copied the contents from wordpress directory to /var/www/ should i remove xyz.html page.

    the reason that prompted me to ask this wuestion is that i see

    “It works!

    This is the default web page for this server.

    The web server software is running but no content has been added, yet.”

    when i give my ip address i associated with the wordpress installation.

  6. Joe says


    Thanks for the blog. I found it really helpful. Do you know how much it will cost you to continue running your set up when the free year runs out ?

  7. Swapnil V. Patil says

    I am unable to connect to the instance..i get the following error…

    Error connecting to, reason:
    -> Error in ssh2: I/O error in version negotiation{com.mindbright.ssh2.SSH2VersionNegotiationException: I/O error in version negotiation}

    any idea why?

    should i create a new instance and start over again?

  8. Swapnil V. Patil says

    I installed WordPress successfully, but could not find how to delete the default index.php file from the instance.

    pls help

  9. says

    Thanks for the detailed instructions – very helpful.
    Can you please provide two more clarifications
    a) How do I enable cgi scripts ?
    b) When taking an existing wordpress blog from shared hosting to EC2, is there any other step to factor in?

      • zc says

        Migration of a site (roughly)

        1) Export your database
        2) Export your wordpress files
        3) Upload wordpress files to EC2

        (this is difficult! Took me while to get filezilla to connect. Once you are in, ubuntu user can only upload to its /home directory so you have to use putty or the SSH client provided by EC2 to then copy the files from /home to /var/www and then do chmod on them using the command on this page)

        4) Import database to EC2 via phpmyadmin
        5) Do search and replace on your database to update to the new site address:


        UPDATE wp_posts SET post_content = REPLACE (

        …but also on wp_options etc.

        • puneet says

          I understand it could be a pain to export/import the files. So, easier way could be to use a plugin like BackupBuddy or InfiniteWP.
          Install a fresh copy of WP and then use any backup plugin to get your files and database in place.
          I will give it a try sometime and may be write a tutorial. :)

  10. Dale says

    THANKS for this post!! I am a complete rookie with AWS, not to mention apache,php & Mysql. Even I was able to follow your instructions to a T with SUCCESS

  11. Carmen Ibarra says

    Thank you for a most informative blog. Your step-by-step process was spot-on. You’re my hero.

  12. says

    Hi, great tutorial … I still have some trouble when I try to install a new theme or a new plugin.

    Seems that WP is trying to connect to my server trough FTP or SFTP … but, first … my EC2 firewall has not port 21 open (like yours) and second .. I didn’t install any ftp server on my machine.

    Any ideas?


  13. zc says

    THANK YOU FOR THIS GUIDE! I managed to get EC2 running really easily.

    But, wordpress is unable to connect to the internet. It cannot search for new plugins or updates etc. I have searched in WP forums but cant find any discussions about this. I guess it is an apache config issue? Any idea how to fix this?

    • puneet says

      I haven’t tried that. But, enabling multi-site requires changes to wp-config.php that’s all you need to do.

  14. Victor Rodriguez says

    Very helpful tuto, thank you, you could add the final step to delete the default index,html file from /var/www directory to get the wordpress index.php working.

  15. says

    Hi Puneet,

    Thanks for this great tutorial. I’ve got WP up and running, however am having trouble activating themes/plugins without server errors.

    What FTP access do you use to edit WP files/themes?



    • puneet says

      Hi Angela
      Please make sure that you have enabled FTP port 21 or SFTP port 22 on your instance and then you can use any FTP client like File Zilla to access your site.

  16. Sanjeev says

    No Doubt Perfect Tutorials. I’m newbie, did installed wordpress and login with IP wordpress dashboard. Pls guide.

    1. Unable to see wordpress home page
    2. Unable to restart [sudo /etc/init.d/apache2 restart]
    apache2: Syntax error on line 237 of /etc/apache2/apache2.conf: Syntax error on line 41 of /etc/apache2/sites-enabled/000-default: Expected but saw
    Action ‘configtest’ failed.
    The Apache error log may have more information.

  17. says

    hi, first of all thank you for this excellent tutorial, its the best one on the web for sure,
    the only problem I have is after installing everything, It seems I need to delete index.html
    but here`s what happens when I try to do this

    root@ip-10-250-51-225:~# rm index.html
    rm: cannot remove `index.html’: No such file or directory

    • puneet says

      Please make sure that you are in the correct directory. Also, you can try accessing SFTP so that you don’t need to fiddle with the command line.

  18. Veeral says

    Thanks for this tutorial as it made a big difference. However, I am having problems when you specified this command to be executed: sudo chmod -R 755 www-data /var/www. In my case it doesn’t know the user www-data even though www-data is a valid apacher user in my instance of Ubuntu.

    Second problem I am facing is the permalinks. Again I followed your instructions, I got WordPress to create the .htaccess file why accessing the permalinks option inside WordPress and ensuring “default” was selected and hit saved. Then selected the “post name” permalink option and hit saved. Do I need to perform a chmod 777 on the .htaccess file ?

    At the moment, accessing the post or page via a pretty permalink is resulting in 404 Error. So I am not sure how to resolve this.

  19. kunalce4u says

    Everything worked fine. I am facing another issue here now. I have domain from goDaddy and I added my elastic IP there. When I try to visit website using my “” only landing page shows that “” url. All other pages show “elasticIP/post-name” url.

    • puneet says

      Did you remove the default index.html file from root folder?
      Make sure, you delete that and try clearing browser cache as well.

  20. says

    I spent an entire weekend in doing the above steps. I am no geek and know nothing about AWS or linux etc. Everything I did was from Googling and some guess work. Wish I had read this blog before *sighs*!

    And thanks. Your site + Nick’s comment above helped me fix permalink issue!

  21. tabularasaindia says

    these steps helped me to setup my site finally. Thanks. But there are issues I still face – plugings and themes show a ftp login page! Any idea how to get rid of it? I am thus never able to istall or update plugins. I use the client ssh to upload themes and plugins as a workaround (Bitvise). But I would definately want to not use this and be able to upload and install plugins and themes directly. Help needed.

      • tabularasaindia says

        Thanks Puneet. The problem does seem to be rights to folder wp-content. I am able to add content – posts and pages with text. The moment I try to add photos… it is unable to upload. To test, I change the permission to this folder to 777, successfully upload images and return to 755. This works. But this is not really the way to use wordpress! All attempts beat me. Any other method?

        • Nick says

          I think this has to do with the user running apache. The site folder is probably owned by your user and not the apache user www-data. To fix this you’ll need to chmod the folder to be owned by the www-data user and then add your user to the www-data group so you can still have write permissions to the web folders.

          • tabularasaindia says

            Hi Nik. I am kind of able to get what you say. But being a non-programmer, and following steps as-is from blogs as this, to fulfill my goal (to set up my wp sites), I will need help. Let me write what I understand: 1. in ssh, my user is “ubuntu”, with sudo su, it changes to “root”. So to fix things, I must… chmod -R 755 should the folder var/www/wordpress or something else? And how do I deal with groups?… Now www-data is somethign I never caem accross in my setup except mention in blogs. I understood this to be a kind fo variable/placeholder for blog text to be replaced by my user name (=”root” or “ubuntu”). I may sound confused, well, because I am :) In a nutshell, can you guide me to groups or wrtie down the exact commands I must use in ssh? All help appreciated. Thanks, Nikhil

          • tabularasaindia says

            Wow! Nick I just did this (what you said to do). IT HAS WORKED
            Tested a new post with image. It worked.
            Tested a new theme. It installed and activated. So, is there something about groups I still need to do?

            This is what I did in my ssh client (Bitvise)
            – did NOT do sudo su
            (the user stayed as “ubuntu” in prompt)
            – sudo chown -R www-data /var/www
            – sudo chmod -R 755 /var/www

            Thats it. All works fine now. My “wordpress” is installed in /var/www (as per this blog it was moved to the /var/www to map to the domain and not a “wordpress” sub folder)

            Thanks. But do confirm if this is all fine and nothign else needs to be done. – Nikhil

          • says

            The last thing you might need to do is ass the ubuntu user to the www-data group. This is if you want to access the site via SFTP or SSH and have write permissions without a sudo;

            usermod -a -G www-data ubuntu

  22. says

    My site was working fine. It was under /www/blog in EC2. Then I tried adding a new directory in /www. I now see that none of my sites work (not sure if the new directory addition is related to this). I get 403 Forbidden. Can someone suggest possible cause/ solution. Do let me know if more info is needed.

  23. Sam says

    This was an awesome walk through. Thanks so much. Two tweaks to make it smooth in my case, as identified by others above:

    1) leave the “www-data” out of chmod -R 755 ….
    2) navigate to /var/www to remove index.html.

    Then it works.

    Many thanks.

  24. says

    Hi Puneet,
    Thanks for awesome tutorial and with the help of this i successfully installed WordPress. Can you please tell me how can i access root directory files like wp-config.php or other files to make certain changes..

    Thanks again..

  25. kiho says

    Adding the following line in wp-config.php will enable plugin and theme installation without FTP.
    define(‘FS_METHOD’, ‘direct’);

  26. manoj says

    Hello Puneet !! I have install wordpress on Ubuntu 12.04 EC2 instance with the help of your blog but now it’s not working with Ubuntu 14.04 even mytest.php fails !! any solution ?

  27. Salim says

    you need to try current ec2 instance and make necessary changes to your ubuntu commands

    result: failure according to your above post commands


Leave a Reply