Deploy WordPress on AWS EC2: Quick and Easy Setup!

Deploy WordPress on AWS EC2: Quick and Easy Setup!

It is essential to understand the importance of writing this blog and to grasp the significance of deploying WordPress on AWS.

In 2024, over 810 million websites are using WordPress, accounting for 43.2% of all live websites, essentially 2 out of every 5 sites you visit. WordPress holds a 63.3% market share in the CMS market and powers over a third of the world’s top websites. Impressively, more than 500 new sites are built daily on the platform. WordPress’s growth has grown substantially, from just 12% of all sites in 2011 to now powering 36% of the top 1 million websites, including major names like The New York Times, Bloomberg, and Nike.



Setting up a LAMP (Linux, Apache, MySQL/ MariaDB, PHP) server on an AWS EC2 instance is essential for hosting dynamic websites. In this guide, I will explain the process of launching an EC2 instance, installing the necessary components, and configuring a WordPress site.

Launch an EC2 Instance

Here are the basic steps to launch an EC2 instance on AWS

Login to the AWS Management Console

Go to the AWS Management Console.

Sign in using your AWS account credentials.

Navigate to EC2 Dashboard

In the AWS Management Console, search for “EC2” in the search bar and select “EC2” from the results.


This will take you to the EC2 Dashboard.

Launch Instance

Click on the “Launch Instance” button on the EC2 Dashboard.

Name of the instance

Could you write the name of your choice for the instance you will launch in the name field?

Choose an Amazon Machine Image (AMI)

Select an AMI (e.g., Amazon Linux 2, Ubuntu, etc.) based on your requirements.


AMIs are pre-configured templates that provide the operating system and software stack.

I am choosing Ubuntu for this you can choose any AMI according to your use case.

Choose an Instance Type

Select an instance type based on the CPU, memory, and networking capacity you need.


For example, t2.micro is a common choice for a small application.

Choose or Create a Key Pair

Select an existing key pair or create a new one to securely connect to your instance.


Download the private key file (.pem file) and store it securely.

Or also you can move with “Proceed without a key pair” but it is not recommended.

Configure Security Group

A Security Group acts as a virtual firewall for your instance.

Configure the security group to allow the necessary ports (e.g., SSH, HTTP, etc.).

For now, you have to do this type of configuration which you can see below.


You can leave the rest of the configuration as Default.

Add Storage

Configure the storage attached to your instance. By default, an EBS (Elastic Block Store) volume is provided.

You can increase the storage size or add additional volumes if needed.

Review and Launch

Review all your configurations.

Click on “Launch instance” to start your instance.

After a few minutes, your instance will be up and running.

You can see your instance in the instances you can see below.


Access the Instance

Select the instance and click on the “Connect” button then you will reach this screen that you can see below.


Then click on the Connect button to connect to your server.


Update the Server

It’s crucial to keep your server up to date. Run the following command to update and upgrade the packages:

sudo apt update && sudo apt upgrade -y

Set Up the LAMP Server

Install Apache

Install Apache, the web server that will serve your website:

sudo apt install apache2 -y

Ensure Apache is running by checking its status:

sudo systemctl status apache2

If Apache isn’t running, verify that port 80 is open in your EC2 security group.

Start the Apache service:

sudo systemctl start apache2

Enable Apache to Start on the Boot

Ensure Apache starts automatically if the server reboots:

sudo systemctl enable apache2

Install MySql

Install MySql Server and Client

MySql will serve as your database server:

sudo apt install mysql-server mysql-client -y

Start and Check MySql Status

Start the MySql service:

sudo systemctl start mysql

Setup the MYSQL Server

Set up the root password and secure your database by running:

sudo mysql_secure_installation

Follow the prompts to remove anonymous users, disallow remote login, and remove the test database.

Install PHP

Install PHP and necessary extensions to work with Apache and MySql:

sudo apt install php php-mysql php-gd php-cli php-common -y

Prepare for WordPress Installation

Install required packages:

sudo apt install wget unzip -y

Download and Set Up WordPress

Download WordPress

Download the latest version of WordPress from the official site:

sudo wget https://wordpress.org/latest.zip

Unzip the Downloaded File

Unzip the WordPress package:

sudo unzip latest.zip

Copy WordPress Files

Move the WordPress files to the Apache root directory:

sudo cp -r wordpress/* /var/www/html/

Set Permissions and Clean-Up

Change Ownership of WordPress Files

Ensure that the web server owns the WordPress files:

sudo chown www-data:www-data -R /var/www/html/

Remove the Default Apache Index File

Remove the default Apache index file

sudo rm -rf /var/www/html/index.html

Configure the Database for WordPress

Log into MySql

Log into MySql as root:

sudo mysql -u root -p

Create a WordPress Database and User

Run the following commands to create a database and user for WordPress:

CREATE DATABASE wordpress;
CREATE USER ‘wpadmin’@’%’ IDENTIFIED BY ‘wpadminpass’;
GRANT ALL PRIVILEGES ON wordpress.* TO ‘wpadmin’@’%’;
EXIT;

Complete WordPress Installation

Visit your server’s public IP address in your web browser to complete the WordPress installation. Enter the database details, site title, and admin credentials.

Once these steps are complete, you’ll be redirected to the WordPress dashboard, and your WordPress site will be live.


#wordpress #aws #ec2 #lampstack #serversetup #cloudhosting #webdevelopment #linux #cms #wordpressinstallation #techguide #webhosting #php #mysql #apache #devops #devopsengineer #cloud #cloudengineer #learning #growth #muhammadmuzammil

Abdul Waheed Mahar

IT & Networks Support Executive | Technical Support Engineer | IT Managed Services MSP | AWS Cloud Computing | Desktop Support

6 个月

Great effort

Mahnoor Wahid

Project Manager@Wiga Tech Solutions || Manual Tester || NED-UIT '24

6 个月

Nice?

Waleed Ghori

Software Engineer | Web Developer | Frontend Developer | MERN/MEAN Developer

6 个月

great

要查看或添加评论,请登录

Muhammad Muzammil的更多文章

  • EC2 Backup Configuration and Restoration

    EC2 Backup Configuration and Restoration

    INTRODUCTION AWS Backup is a fully managed service that simplifies data backup and restoration across AWS services…

  • Building Scalable ML Models on AWS SageMake

    Building Scalable ML Models on AWS SageMake

    In my "previous blog," I talked about the ML services on AWS. I mentioned that I would discuss each service in separate…

    6 条评论
  • Scale Your ML Projects with AWS

    Scale Your ML Projects with AWS

    As we all know, the world is advancing at a rapid pace. AI plays a crucial role in this quest for rapid growth and…

    6 条评论

社区洞察