Introduction
To Deploy a WordPress website first you have to understand What is LAMP Stack? A “LAMP” stack is a group of open source software that is typically installed together in order to enable a server to host dynamic websites and web applications written in PHP. The term is an acronym which represents the Linux operating system, Apache web server, MySQL database and PHP.
Prerequisites
In order to use the AWS, you will need to have an Amazon Web Services (AWS) account.
Before proceeding to the first step first click the Security groups under the Network & Security. Then a list of security groups will be opened that are already created. Click on the option Create Security Group at the top right corner of screen.
Fill the above information accordingly and then scroll down.
In the above Image add the inbound rules that should contain the rules listed below:
Type- SSH | port-22 | Source Anywhere from IPv4- 0.0.0.0/0
Type- HTTP | port-80 | Source Anywhere from IPv4- 0.0.0.0/0
Type- HTTPS | port-443 | Source Anywhere from IPv4- 0.0.0.0/0
Step 1:
Search for the EC2 Service at the search bar.
Step 2:
Click on the 'Launch an instance' and enter your server name, secondly select an AMI(Amazon Machine Image) like Linux, macOs, Windows for the configuration of server.
Step 3:
Then select the instance type, this is basically the resources we will use from our cloud. Under Instance type, from the Instance type list, you can select the hardware configuration for your instance. Choose the t2.micro instance type, which is selected by default. The t2.micro instance type is eligible for the free tier. In Regions where t2.micro is unavailable, you can use a t3.micro instance under the free tier.
Step 4:
Under the Key pair (login) click on the link at the bottom right create new key pair
In the above screenshot enter the Key Pair name like 'server-name'. Then select the Encryption technique that is RSA selected by Default & then select the .pem format for the Key File to be downloaded locally in order to access the server locally using SSH Protocol.
At last click the Create Key Pair. After clicking it a file will be downloaded named 'server-name.pem' it is a text file containing the RSA key.
Step 5:
Under the Network Settings select existing Security groups and then select that specific security group you created at the start
Step 6:
Then at last on the right side check the summary of your configuration of instance and after a brief check, click Launch instance.
It will redirect to the page where the instances are listed including your new instance. Here you wait for 2-3 minutes for the initialization of instance and verify that Instance state is Running and status check should be 3/3. Then select the instance you created and click on the connect at the top right corner of screen.
If you want to configure it online using AWS CLI you can simply click connect and a tab will opened showing the CLI for the configuration.
But if you want to access your instance locally then go on the SSH client tab And here copy the command under the Example and paste it in the CLI of your localhost Windows/Linux and remember one thing you should be in the directory/folder where your Security Key file is saved.
I will prefer online AWS CLI for the configuration:
Step 7:
Now you have install the LAMP Stack here.
- Perform a quick software update on your instance:
sudo dnf update -y
- Install the latest versions of Apache web server and PHP packages for Amazon Linux 2023:
sudo dnf install -y httpd wget php-fpm php-mysqli php-json php php-devel
- Install the MariaDB software packages. Use the dnf install command to install multiple software packages and all related dependencies at the same time:
sudo dnf install mariadb105-server
- Start the Apache web server:
sudo systemctl start httpd
- Use the systemctl command to configure the Apache web server to start at each system boot:
sudo systemctl enable httpd
- Secure the MariaDB installation: After the installation, run this command to secure your MariaDB:
sudo mysql_secure_installation
- Download WordPress: Navigate to the web root directory and download the latest version of WordPress:
cd /var/www/html
sudo wget https://wordpress.org/latest.tar.gz
sudo tar -xvzf latest.tar.gz
sudo mv wordpress/* ./
sudo rm -rf wordpress latest.tar.gz
sudo chown -R apache:apache /var/www/html
sudo chmod -R 755 /var/www/html
- Create a Database for WordPress: Log in to MariaDB and create a database for WordPress:
sudo mysql -u root -p
Inside the MariaDB shell, run the following SQL commands:
CREATE DATABASE wordpress;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'your-password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
- Configure Apache: Open the Apache configuration file and add the following configuration:
sudo nano /etc/httpd/conf/httpd.conf
Ensure that the DocumentRoot is set to /var/www/html.
Modify the Directory Permissions for /var/www/html: In the httpd.conf file, look for the section that refers to /var/www/html (or you can add it if it doesn't exist):
<Directory "/var/www/html">
AllowOverride All
Require all granted
</Directory>
Restart Apache to apply changes:
sudo systemctl restart httpd
- Then go on the new tab and type : http://here-enter-public-ip Replace here-enter-public-ip with your actual public IP.
And here your wordPress is successfully deployed on your server.
Step 8:
Update Domain and DNS Settings
Point Domain to AWS: If you're using a custom domain, update the DNS settings with your domain registrar:
Set an A record pointing to your EC2 instance's public IP address.
Step 9:
Secure Your Website with SSL (Optional), So that it can be accessible at HTTPS.
- Install Certbot for SSL: Install Certbot, which is a tool to easily set up SSL for your site:
sudo yum install -y certbot python2-certbot-apache
- Obtain an SSL Certificate: Run Certbot to obtain an SSL certificate:
sudo certbot --apache -d yourdomain.com
- Test SSL Auto-Renewal: Certbot automatically renews SSL certificates, but you can test it by running:
sudo certbot renew --dry-run
At the End Test Your Website
Visit Your Site: Navigate to your domain or your EC2 instance's public IP address. Your website should now be live and functional.
Check SSL (if applied): If you installed SSL, ensure that your site is accessible via https://.
Top comments (0)