Create an AWS EC2 instance 🔅 Configure the instance with Apache Webserver. 🔅
To create an AWS EC2 instance, configure it with Apache Webserver, and set up a MySQL server using AWS RDS, follow the steps below:
Step 1: Launch an AWS EC2 Instance
- Log in to your AWS account.
- Go to the AWS Management Console and navigate to the EC2 service.
- Click on "Launch Instance."
- Choose an Amazon Machine Image (AMI) that suits your requirements. For example, you can select an Amazon Linux 2 AMI.
- Select an instance type. You can choose a t2.micro instance type, which is eligible for the Free Tier.
- Configure the instance details as per your needs (e.g., network settings, security groups).
- Add storage as required. The default size is usually sufficient for testing purposes.
- Review the configurations and click "Launch."
Step 2: Connect to the EC2 Instance and Install Apache Webserver
- Once the instance is launched, you'll receive a key pair to connect to the instance. Download and keep it secure.
- Use SSH to connect to the instance using the command:bash
ssh -i /path/to/your/keypair.pem ec2-user@your-instance-public-ip
- Update the package list and install Apache Webserver:bash
sudo yum update -y sudo yum install httpd -y
Step 3: Download and Install PHP and WordPress
- Install PHP and other required dependencies:bash
sudo amazon-linux-extras install -y lamp-mariadb10.2-php7.2 php7.2 sudo yum install php-mbstring -y
- Start and enable the Apache web server:bash
sudo systemctl start httpd sudo systemctl enable httpd
- Download and extract WordPress into the Apache webserver's document root (e.g., /var/www/html/):bash
cd /var/www/html sudo curl -O https://wordpress.org/latest.tar.gz sudo tar -xvf latest.tar.gz sudo mv wordpress/* . sudo rm -rf wordpress latest.tar.gz
Step 4: Set Up AWS RDS MySQL Database
- Go to the AWS Management Console and navigate to the RDS service.
- Click on "Create database."
- Choose "Standard Create" and select "MySQL" as the database engine.
- In the "Templates" section, choose "Free tier."
- Configure the database settings, including the DB instance identifier, username, and password.
- Choose appropriate connectivity settings, VPC, and subnet group.
- Click "Create database."
Step 5: Provide Endpoint/Connection String to WordPress
- Once the RDS MySQL instance is created and available, go to the RDS dashboard, select your instance, and note down the "Endpoint" under the "Connectivity & security" tab.
- Edit the WordPress configuration file to update the database connection settings:bash
cd /var/www/html sudo cp wp-config-sample.php wp-config.php sudo nano wp-config.php
- Find the following lines in the wp-config.php file and update them with your RDS database details:
Replacephpdefine('DB_NAME', 'your_db_name'); define('DB_USER', 'your_db_username'); define('DB_PASSWORD', 'your_db_password'); define('DB_HOST', 'your_rds_endpoint');
your_db_name
,your_db_username
,your_db_password
, andyour_rds_endpoint
with your actual RDS database details. - Save and close the wp-config.php file (in Nano, press Ctrl+X, Y, and Enter).
Step 6: Complete WordPress Installation
- Visit your EC2 instance's public IP address in a web browser.
- Follow the WordPress installation wizard to set up your site, create an admin account, and complete the installation.
Now, your WordPress application is connected to the MySQL database hosted on the AWS RDS service using the provided endpoint/connection string.
Comments
Post a Comment