Step by Step Guide : Host Wordpress on Amazon Linux AMI EC2 Instance

Wordpress on Amazon Linux AMI EC2
Wordpress on Amazon Linux AMI EC2

ear friends,

If you have landed here to find out how you can host wordpress on Amazon Linux AMI EC2 Instance, you are absolutely at the right place and you will find the detailed instructions here. This guide will be so detailed that even a newbie and novice could also follow it and get the thing done.

NOTE : At the time of writing this guide I used my Macbook air. So there might be few places where there might be instruction differences for other systems (Example - Windows).

I will be very precise and to the point. Though I will elaborate all the important things in deep but will not waste anyone's time explaining useless stuff.

Step 1 : Create an EC2 Instance and Choose Linux AMI as your instance. You will asked to create Key Pair. Do create and download it and keep at a safe place to be accessible at later stage.

Step 2 : Use Console , (In case of Windows, use putty) to ssh into your EC2 instance. Before using SSH command, you need to provide necessary permission and security to the folder containing your Security Key (.pem file). To provide this permission you need to execute this command :

chmod 400    {Replace with your actual keypair name}

Now use SSH command which will look like this -

ssh -i "" [email protected]

Installing LAMP web server on Amazon Linux AMI.

Step 3 : Before you can install wordpress on your AWS EC2 instance, you need to create a server environment where you can create and host your wordpress installation.

3.1 -> Execute this command after your ssh login. sudo yum update -y 

This command will install and update few necessary softwares on your server to create LAMP.

3.2 -> Now you need to install Apache server, MySQL, and PHP software packages on your instance. To do this, you need to run this command : sudo yum install -y httpd24 php70 mysql56-server php70-mysqlnd

3.3 -> Start the apache server using this command : sudo service httpd start

3.4 -> Run the following command for your apache server to start every time your system boots : sudo chkconfig httpd on

3.5 -> For your EC2 instance to be publicly viewable using it's public ip, you need to create a inbound security rule in the security group. To do this, you need to visit your EC2 dashboard. Choose your instance and go to the last column with name " Security Group ". Click on the security group linked with your EC2 instance.

Visit the inbound tab and click on Edit. Click Add rule and then put the following details.

  • Type: HTTP
  • Protocol: TCP
  • Port Range: 80
  • Source: Custom

3.6 -> Now you need to test whether your EC2 instance is publicly accessible on http port or not. To test this, you need to copy your public ip and paste the same in your browser. If everything will be correct, you should see the default test page for apache server.

Step 4 : Give proper set of permissions to your EC2 user to edit your apache server. To do so, run the following commands :

[ec2-user ~]$sudo usermod -a -G apache ec2-user

[ec2-user ~]$exit

4.1 -> Reconnect to your instance using ssh login and then run following command.

[ec2-user ~]$sudo chown -R ec2-user:apache /var/www

[ec2-user ~]$sudo chmod 2775 /var/www

[ec2-user ~]$find /var/www -type d -exec sudo chmod 2775 {} \;

After all these commands executed above, the EC2 user is now able to add, delete and edit in the apache root.


Step 5 : Now test your LAMP web server.

5.1 -> Create a test php file in your apache root. To do this, you need to run this command : [ec2-user ~]$echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php

5.2 -> Open this test file created in above step. To do this, you simply need to paste your public ip along with file name. The correct format is http://publicIP/phpinfo.php . If things are okay as yet, you must see the test page like shown below :

5.3 -> Now that you have tested the existence of this file, you must delete it for security reasons. To do so, run this command : [ec2-user ~]$rm /var/www/html/phpinfo.php

Step 6 : Secure your database. Setup password for the same.

[ec2-user ~]$sudo service mysqld start

Initializing MySQL database:


Starting mysqld: [ OK ]

Step 6 : Install mysql on your server. To do this execute this command : [ec2-user ~]$sudo mysql_secure_installation

Note that by default there's no password, so just press enter. And now you will be prompted to create a new password. Do that and then remove anonymous user, remote root login, test database, reload privilege table. All this can be done by following on screen instructions.

6.1 -> You should stop the server now using this command : [ec2-user ~]$sudo service mysqld stop

6.2 -> For your mysql server to start at every boot, you must execute this command : [ec2-user ~]$sudo chkconfig mysqld on

Step 7 : Install phpmyadmin. Though this is an optional step but it's helpful in handling databases and grating permissions using user interface.

7.1 -> If your logged out from your instance, ssh into your ec2 instance.

7.2 -> Run the following command to install the required dependencies : sudo yum install php70-mbstring.x86_64 php70-zip.x86_64 -y

7.3 -> Restart your apache server using this command : sudo service httpd restart

7.4 -> Go to apache root using the command : cd /var/www/html

7.5 -> Download and install the phpmyadmin latest release from the official website. Execute the following command to do this : wget

mkdir phpMyAdmin && tar -xvzf phpMyAdmin-latest-all-languages.tar.gz -C phpMyAdmin --strip-components 1

rm phpMyAdmin-latest-all-languages.tar.gz

7.6 -> Start your mysql server using this command : [ec2-user ~]$sudo service mysqld start

7.7 -> Finally you have installed the phpmyadmin on your server and you can access it via : http://publicIP/phpMyAdmin/ . Enter the user "root" and password that you have created in the above steps.


Step 8 : Finally you have created proper server environment for your wordpress installation to run on. Now you just need to download and install wordpress on your server.

8.1 -> Download wordpress using : [ec2-user ~]$wget

8.2 -> Unzip the downloaded file : [ec2-user ~]$tar -xzf latest.tar.gz

8.3 -> Create Database and it's respective user for your wordpress. You can do it via command or via phpyadmin. Before this start your SQL server : sudo service mysqld start

[ec2-user ~]$mysql -u root -p

CREATE USER 'wordpress-user'@'localhost' IDENTIFIED BY 'your_strong_password';

CREATE DATABASE `wordpress-db`;

GRANT ALL PRIVILEGES ON `wordpress-db`.* TO "wordpress-user"@"localhost";



8.4 -> Create wp-config.php file and edit it with relevant database details. We will do so by copying existing wp-confog-sample.php and pasting it's content in wp-config.php

cp wordpress/wp-config-sample.php wordpress/wp-config.php

nano wordpress/wp-config.php  {I am using Macbook air, so nano command works pretty good on it. You can use any other editor also that you are comfortable with }

Move on to the section where Database details are mentioned. Just edit those details with your own created details in the above steps.

define('DB_NAME', 'wordpress-db');

define('DB_USER', 'wordpress-user');

define('DB_PASSWORD', 'your_strong_password');

After editing these details save the file and exit the editor.

8.5 -> Now move this wordpress folder to your apache root so that it can be publicly accessible via your public ip.

8.6 -> Now we shall write few security permission for wordpress to access apache server.

[ec2-user ~]$sudo nano /etc/httpd/conf/httpd.conf

Find the section that starts with <Directory "/var/www/html">.

<Directory "/var/www/html">
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    # The Options directive is both complicated and important.  Please see
    # for more information.
    Options Indexes FollowSymLinks

    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    AllowOverride None # # Controls who can get stuff from this server. # Require all granted </Directory>

In this section, you need to edit "AllowOverride None" with "AllowOverride All"

Save the file and exit your editor.

8.7 -> Now we need to run few commands to fix File permission for apache web server.

[ec2-user ~]$sudo chown -R apache /var/www

[ec2-user ~]$sudo chgrp -R apache /var/www

[ec2-user ~]$sudo chmod 2775 /var/www

[ec2-user ~]$find /var/www -type d -exec sudo chmod 2775 {} \;

Restart the webserver : sudo service httpd restart

8.8 -> Now you need to visit to your public ip address through your web browser to proceed with wordpress installation. You will be able to see the basic wordpress installation page. Just follow the onscreen instructions and you will be able to install wordpress on that ip.

Finally you are done with all the steps of Wordpress installation on Amazon Linux AMI. In case, something doesn't make sense to you, you can simply email me at ankit @ editsoftdigital[.]in or leave your comments below. I shall be quick in solving your problem.