Wordpress install on AWS

Adi Sar
4 min readJun 24, 2023

--

Step 1: Create new instance of ubuntu.

# select t4g.micro we can lower it to nano later on. but its will make the process faster

# select ubuntu

# save the .pem file you create with keyring.

Step 2: Start a mariaDB on RDS

# go to https://eu-west-1.console.aws.amazon.com/rds/home?region=eu-west-1#launch-dbinstance:gdb=false;s3-import=false

# select MariaDB

# set a password

# Enable connection to ec2

# select the ec2 instance you done at step1

Step 3: Login to yours server

# Go to the EC2 instances dashboard: https://eu-west-1.console.aws.amazon.com/ec2/

press on “Connect” -> “SSH client”

run at terminal the connection

# login into server

# install Php

sudo apt update 
sudo apt upgrade -y
sudo apt install -y --no-install-recommends php8.1
sudo apt-get install -y php8.1-cli php8.1-common php8.1-mysql php8.1-zip php8.1-gd php8.1-mbstring php8.1-curl php8.1-xml php8.1-bcmath
sudo apt install -y php8.1-fpm php-mysql

# install nginx

sudo apt install nginx -y

Test connection

copy from the instance page the public dns address

Change the address from https into http then you should see

Configure Nginx

Wordpress install

cd /var/www/html
sudo wget -c http://wordpress.org/latest.tar.gz
sudo tar -xzvf latest.tar.gz
sudo rm latest.tar.gz
sudo chmod -R 777 wordpress/
cd wordpress/
#fill up salt
SALT=$(curl -L https://api.wordpress.org/secret-key/1.1/salt/)
STRING='put your unique phrase here'
printf '%s\n' "g/$STRING/d" a "$SALT" . w | ed -s wp-config.php

sudo mv wp-config-sample.php wp-config.php
nano wp-config.php

Fillup the DB RDS we open data

MultiSite on Nginx

Nginx comes with a default server block that’s ready to serve documents from the /var/www/html directory. It’s fine for a single website, but managing multiple sites can be a hassle. So, instead of messing with /var/www/html, we’ll set up a new directory structure within /var/www for your_domain website. Don’t worry, /var/www/html will still be there as the default directory if a client request doesn’t match any other sites.

export your_domain domain-name.com
sudo mkdir /var/www/$your_domain
sudo chown -R $USER:$USER /var/www/$your_domain
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/$your_domain
sudo sed -e "s/example.com/$your_domain/g" /etc/nginx/sites-available/$your_domain
sudo ln -s /etc/nginx/sites-available/$your_domain /etc/nginx/sites-enabled/
sudo unlink /etc/nginx/sites-enabled/default

Test:

sudo nginx -t
sudo systemctl reload nginx
#fill yours page
nano /var/www/$your_domain/index.html

Connect DNS to AWS

I bought my domain at NameCheap.

go to the Dashboard then “Advances DNS”

Enter a new record make sure to pick

  1. type=“A record” (ipv4 target)
  2. Host=”@” tell it to use yours domain name
  3. Value=Yours IPv4 public IP you get from AWS instance page
get yours ipv4 address

Go to broswer and test yours domain http://domainname.fillme

Connect EC2 to RDS

When you set up a connection between an EC2 instance and an RDS database automatically, RDS configures the VPC security group for your EC2 instance and for your RDS database.

To connect an EC2 instance and an RDS database automatically

  1. Sign in to the AWS Management Console and open the Amazon RDS console at https://console.aws.amazon.com/rds/.
  2. In the navigation pane, choose Databases, and then choose the name of the RDS database.
  3. On the Connectivity & security tab, view the compute resources in the Connected compute resources.

To be continue…

--

--