Install and Setup WordPress Site using AWS

.COM domain for only $6.5/1st year on Alibaba Cloud! Limited time offer! Buy Now!
.COM domain for only $6.5/1st year on Alibaba Cloud! Limited time offer! Buy Now!

WordPress ( is a free and open source content management system (CMS) based on PHP & MYSQL. It is a software designed for everyone, emphasizing accessibility, performance, security, and ease of use. WordPress is free to install, deploy, and upgrade. Thousands of plugins and templates power a flexible and simple interface, which reduces development costs and deployment time.

WordPress has to be installed on a web server either part of an Internet hosting service like or a computer running the software package in order to serve as a network host  in its own right. A local computer may be used for single-user testing and learning purposes.


Visit Amazon Web Services ,Login into your AWS console and Create an EC2 Instance. You can use this guide to Create your Instance .

Steps for setting up wordPress on AWS :

Step – 1 Connecting to AWS EC2 Instance

  • Click on the Instances, You can view the state of your instance it is running.

  • You can find Public DNS or Public IP both on the same page , it will be used to connect to your instance.

  • Connect from Mac or Linux Using an SSH Client. Your Mac or Linux computer most likely includes an SSH client by default.
  • Open your command line shell and change the directory to the location of the private key file that you created when you launched the instance.
  • Use the chmod command to make sure your private key file isn’t publicly viewable.
$ chmod 400 my-key-pair.pem
  • Use SSH command to connect to the instance
$ ssh -i  my-key-pair.pem ec2-user@public_dns_name
  • Update softwares on your instance. The -y option installs the updates without asking for confirmation.
$ sudo yum update -y
  • Install the lamp-mariadb10.2-php7.2 and php7.2 Amazon Linux Extras repositories to get the latest versions of the LAMP MariaDB and PHP packages for Amazon Linux 2.
$ sudo amazon-linux-extras install -y lamp-mariadb10.2-php7.2 php7.2

Step -2 Install and Configure LAMP Server

LAMP is an archetypal model of web service stacks, named as an acronym of the names of its original four open source components: the Linux Operating System, the Apache HTTP Server, the MySQL relational database management system (RDBMS) and the PHP Programming Language.

1. Install MariaDB and Apache Webserver

  • To install Maria Db server :
$ sudo yum install -y httpd mariadb-server
  • Start the Apache web server :
$ sudo systemctl start httpd
  • systemctl command is used to configure the Apache web server to start at each system boot.
$ sudo systemctl enable httpd
  • Check status of httpd if it is running or not :
$ sudo systemctl status httpd
  • To test your Web Server, open a browser and access your web site using your Public IP or Public DNS.

Set file permissions

  • Add user (ec2-user) to the apache group :
$ sudo usermod -a -G apache ec2-user
  • To verify your membership, log out and reconnect to your instance, and then run the following command:
$ groups
  • Change the group ownership of /var/www and its contents to the apache group.
$ sudo chown -R ec2-user:apache /var/www
  • To add group write permissions and to set the group ID on future subdirectories, change the directory permissions of /var/www and its subdirectories.
$ sudo chmod 2775 /var/www && find /var/www -type d -exec sudo chmod 2775 {} \;
  • To add group write permissions, recursively change the file permissions of /var/www and its subdirectories:
$ find /var/www -type f -exec sudo chmod 0664 {} \;

2 : Check PHP Information page

  • Create a PHP file in the Apache document root :
$ echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.phpe
  • To test your PHP installation, open a browser and access your web site using your Public IP or Public DNS.

  • Delete the phpinfo.php file, it should not be broadcasted on internet, due to security issues.
$ rm /var/www/html/phpinfo.php

3 : Install MySQL

  • To secure MariaDb Server :
$ sudo systemctl start mariadb
  • Install mysql :
$ sudo mysql_secure_installation

Type the current root password. By default, the root account does not have a password set, Press Enter. When prompted, type a password for the root account. Type Y to set a password, and type a secure password twice.

a ) Type Y to remove the anonymous user accounts.

b) Type Y to disable the remote root login.

c) Type Y to remove the test database.

d) Type Y to reload the privilege tables and save your changes.

  • To start mariadb at every boot :
$ sudo systemctl enable mariadb

Step – 3

Install Word Press

  • To install WordPress :
$ wget
  • To uncompress WordPress in its own “wordpress” directory :
$ tar -xzvf latest.tar.gz
  • WordPress installation needs to store information, such as blog posts and user comments, in a database. We need to start database server :
$ sudo systemctl start mariadb
  • Create a user and password for your MySQL database. 
$ mysql -u root -p

CREATE USER 'word-user'@'localhost' IDENTIFIED BY 'my-password';
  • Create your database, write a meaningful name, such as word-db :
  • Grant full privileges for your database to the WordPress user.
GRANT ALL PRIVILAGES ON `wordpress-db`.* TO "word-user"@"localhost";
  • Flush the database privileges to pick up all of your changes.
  • Exit the mysql client.

To create and edit the wp-config.php file

  • The WordPress installation folder contains a sample configuration file called wp-config-sample.php. We need to copy the file and edit according to our specific configuration.
  • To copy the wp-config-sample.php file to a file wp-config.php :
$ cp wordpress/wp-config-sample.php wordpress/wp-config.php
  • Edit the wp-config.php file with text editor (such as nano or vim) and enter values for your installation. 
$ vi wp-config.php
  1. define(‘DB_NAME’, ‘word-db‘)
  2. define('DB_USER', 'word-user');
  3. define(‘DB_PASSWORD’, ‘my-password‘);
  4. Find the section called Authentication Unique Keys and Salts. These KEY and SALT values provide a layer of encryption to the browser cookies that WordPress users store on their local machines.

Visit to randomly generate a set of key values that you can copy and paste into your wp-config.php file.

To install your WordPress files under the Apache document root

  • To run WordPress at your document root, copy the contents of the WordPress installation directory :
$ cp -r wordpress/* /var/www/html/

To allow WordPress to use permalinks

  • WordPress permalinks need to use Apache .htaccess files to work properly, but this is not enabled by default on Amazon Linux. Open the httpd.conf file with a text editor and change the AllowOverride lines in this file, be sure you change the line in the <Directory "/var/www/html"> section.
$ sudo vim /etc/httpd/conf/httpd.conf
  • Save the file and exit your text editor.

To run the WordPress installation script with Amazon Linux 2

  • Use the systemctl command to ensure that the httpd and database services start at every system boot.
$ sudo systemctl enable httpd && sudo systemctl enable mariadb
  • Verify that the database server is running, if not then start:
$ sudo systemctl status mariadb
$ sudo systemctl start mariadb
  • Verify that your Apache web server (httpd) is running, if not then start :
$ sudo systemctl status httpd
$ sudo systemctl start httpd
  • To test your WordPress installation, open a browser and access your web site using your Public IP or Public DNS. You should see the WordPress installation page, provide the information required and choose Install WordPress to complete the installation.