Skip to content

A Step-by-Step Guide to Deploying a WordPress Website on AWS. #AWS_Challenge

Notifications You must be signed in to change notification settings

luciyaroshni/WordPress-Deployment-on-AWS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

WordPress-Deployment-on-AWS

A Step-by-Step Guide to Deploying a WordPress Website on AWS. #AWS_Challenge

Deploying a WordPress website on AWS (Amazon Web Services) is a valuable skill for anyone interested in cloud computing and website management. In this tutorial, I'll guide you through the process of setting up a WordPress site on an AWS EC2 instance, a virtual server in the cloud. We'll take it step by step, making it easy to follow along, even if you're new to these concepts.

Architectural Diagram - Deploying a WordPress website on AWS

image

First things first - you'll need an AWS account to dive into this project. If you don't have one yet, don't worry - signing up is easy peasy! And guess what? All the services we'll use here are part of the free tier, so you can play around without spending a dime.

Step 1: Launch an EC2 Instance

  1. Once you're logged into the AWS console, search for the EC2 service. When you spot it, just click on it to dive right in! You can add EC2 to your favourites by clicking on the star icon next to the service name. And don't forget to check that you're in the right region.

    image

  2. Click on 'Instances' to check out the list of your current instances. If it's looking a bit empty, don't worry - we're about to change that! Hit 'Launch Instances' to start creating your new virtual buddy.

    image

  3. You'll be redirected to a new window where you'll enter your instance details, and AWS will take care of the rest. Let's walk through each step together. Give your server a name - let your creativity flow! I'm choosing 'WordPressServer' for this project, but pick a name that fits your needs perfectly.

    image

  4. I'm going with Ubuntu as my operating system.

    image

  5. In the Instance Type section, select t2.micro (the default option), which is free-tier eligible. Feel free to choose the instance type that best suits your needs.

    image

  6. In the Key pair section, click on 'Create new key pair.' You'll need this if you want to log in to the server using SSH with this key pair. If you've already created a key pair, just select it from your list. Since I haven't made mine yet, I'll go ahead and do that now.

    image

  7. A new window will pop up where you'll need to enter your key pair details. I'm naming mine 'wordpress.' For the rest of the options, I'm sticking with the defaults.

    image

  8. When you click on 'Create pair,' your private key will be downloaded. Be sure to keep this private key super safe - if anyone else gets their hands on it, they can connect to and log in to your virtual machine.

  9. The next step is to configure the network settings. Be sure to enable both of these options:

    -- Allow HTTPS traffic from the internet.
    -- Allow HTTP traffic from the internet.

    image

  10. Finally, configure your storage. I'm sticking with the default settings for simplicity, but you can adjust this based on your needs.

    image

  11. Click on 'Launch Instance,' and voilà - you've just created a virtual computer in the cloud!

    image

  12. Return to your instances page to find your newly created instance listed there.

    image

  13. Once your instance is created, we're ready to connect to it. But first, we need to assign it an Elastic IP address. This is important because, without it, your instance's public IP address will change every time you reboot. By using an Elastic IP, you ensure a static IP address that stays the same even if you restart your instance.

    image

  14. To do this, head over to the EC2 dashboard and click on Elastic IPs.

    image

  15. Select 'Allocate Elastic IP address.'

    image

  16. A new window will open with the Elastic IP address settings. I'm keeping the default settings as is, so just click on 'Allocate.'

    image

  17. As you can see, we've successfully created an Elastic IP address.

    image

  18. The next step is to assign this Elastic IP to your newly created virtual machine. To do this, select the Elastic IP address you've just created. Go to 'Actions' and click on 'Associate Elastic IP address.'

    image

  19. This will open a new window where you need to select the instance you want to associate with this Elastic IP. Select the instance you created from the 'Instance' drop-down menu, and then click 'Associate.'

    image

  20. Return to 'Instances' to verify that the Elastic IP address is successfully associated with your virtual machine. You'll also notice that the public IPv4 address has changed to the newly created Elastic IP address.

    image

  21. Now that your instance has the new public IPv4 address, you can connect to it using this address. To do so via SSH, you'll need an SSH client. For this project, I used MobaXterm to connect to my instance. Open MobaXterm, then click on 'SSH.' In the remote host session, enter the public IPv4 address. Specify the username, select 'Use private key,' and browse to the private key file you downloaded.

    image

  22. You can also connect via a browser. Ensure you enter the correct IP address and username if you are using SSH. As I didn't specify a custom username, the default username 'ubuntu' will be used. Once connected to the server, we can proceed with the next steps.  Install the Apache web server on your instance. Run the following command to install it.

    sudo apt install apache2

    image

  23. To verify that the web server is installed correctly, open your browser and enter http:// into the address bar, then press Enter. If you see a page like the one below, it means the web server is working.

    image

Step 2: Install PHP and MySQL

  1. Next, we'll install the PHP runtime on the instance, as WordPress is built with PHP. We can proceed by installing the PHP runtime and the MySQL connector for PHP using the following command.

    sudo apt install php libapache2-mod-php php-mysql

    image

  2. Next, we need to install the MySQL server to manage the database. To do this, execute the following command:

    sudo apt install mysql-server

    image

  3. Before proceeding to the next step, there is a small configuration required for your MySQL server. You need to change the MySQL authentication plugin to mysql_native_password so you can log in to the MySQL server with a standard password. To change the authentication plugin, first log in to the MySQL prompt as the root user. Use the following command to do so:

    sudo mysql -u root

    image

  4. To change the authentication plugin type, use the following command:

    ALTER USER 'root'@localhost IDENTIFIED WITH mysql_native_password BY '<the password that you want to use for your root account>';

    image

  5. Create a new user, other than root, to use with WordPress. Execute the below command for that:

    CREATE USER 'wp_user'@localhost IDENTIFIED BY '<Your_Password>';

    image

  6. Now, create a separate database for WordPress. Execute the following command:

    CREATE DATABASE <DB_name>;

    image

  7. Next, grant all privileges on the newly created database to the new WordPress user. Execute the following command:

    GRANT ALL PRIVILEGES ON <db_name>.* TO '<user_name>'@localhost;

    image

Step 3: Install WordPress on your server

  1. Next, we'll install WordPress on your server. To get started, navigate to your tmp directory.

    cd tmp

  2. We need to download the latest version of WordPress to install it on our server. You can either search for 'wordpress.org' in your web browser and download the .zip file manually, or, for a quicker option, you can use the following command on your server to download it directly:

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

    image

  3. Unzip the downloaded file, and you'll see a new folder named 'wordpress' has been created.

    image

  4. Let's move the 'wordpress' folder to the /var/www/html directory. If you are facing any permission error then use sudo before the mv command.

    mv wordpress/ /var/www/html

  5. Once the wordpress folder is successfully moved, you can verify it by navigating to the /var/www/html directory. You should see the wordpress folder there. You can use the following command to check:

ls /var/www/html

image

  1. Now, open your web browser and enter the following URL:

    http://<your-public-ipv4-address>/wordpress

    Replace with the actual public IPv4 address of your EC2 instance.

  2. You should see the WordPress setup page. If everything is set up correctly, this means that WordPress is installed and ready for configuration.

    image

  3. Click on the "Let's go" button to start the WordPress setup process.

    • Database Name: Enter the name of the database you created for WordPress.
  • Username: Input the username for the database user you set up.
  • Password: Enter the password for the database user.

Once you've filled in these details, click on the "Submit" button to proceed.

image

  1. After clicking Submit, you'll see a new window prompting you to Run the Installation. This means WordPress has successfully connected to your database - great job, we're almost there! Click on 'Run the installation'.

    image

  2. After you click on Run the Installation, follow the on-screen instructions to set up your site's title and create an admin username and password.

    image

  3. Once you complete these steps, WordPress will be installed, and you can log in to your new site using the credentials you just created.

    image

    image

Step 4: Modifying Apache Configuration

You might notice that WordPress is accessible by adding /wordpress at the end of the IP address. To access it directly with just the IP address, you need to modify the Apache configuration.

  1. Navigate to the directory by running cd /etc/apache2/sites-available/. In this directory, you'll find a file named 000-default.conf.

    image

  2. We need to edit this file. Open it and locate the DocumentRoot section. Then, add wordpress at the end.

    image

  3. Save the file and restart apache2.

    sudo systemctl restart apache2

You should now be able to access your WordPress site directly by typing the IP address into your browser, without needing to include /wordpress in the URL. The changes made to the Apache configuration should ensure that your WordPress site is served correctly from the root of the IP address.

image


Congratulations! 🎉 You've successfully deployed a WordPress website on AWS. Well done! Got questions, comments, or want to share your experience? Feel free to drop a comment below! If this guide helped make your day easier, follow for more cloud adventures and tech tips!

About

A Step-by-Step Guide to Deploying a WordPress Website on AWS. #AWS_Challenge

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published