Easy Installation and Configuration of WordPress on AWS Lightsail

Today I want to share how to install and configure wordpress on AWS lightsail. In this scenario I used Ubuntu 24.04, MySQL for database and wordpress version 6.8.3.
The first thing I create Lightsail and use ubuntu 24.04.

I chose operating system ( OS ) only. You don’t need to select Apps + OS. If you want to get automatic wordpress installed on Lightsail you can chose in Apps + OS section. But in this scenario I only select OS only and deploy wordpress on this lightsail.

In this place you can chose many options, base upon your use cases. Your server workload is depend on high memory cosume you need to chose memory selection. CPU is also same like that. But for this now I chose only general lightsail type.

For best practice you should define key value for filter the resources.

Now you can see our lightsail is running state. For lightsail installation is end in here. Next step we will install and setup wordpress on this server.



After server is running state go to networking session. You see my public IPv4, that is not static IP in real world production we must need to attach static ip. In this scenario I don’t use static ip. And then I add HTTPS rule in IPv4 firewall because I want to access my wordpress webiste via https. Another thing you need to restrict ssh access. You don’t need to allow ssh access from anywhere. You should define which ip is only access for ssh remote.


After you define firewall rule in network session connect your lightsail. You can access 2 ways the first way is using connect using SSH via web browser. The second way is using ssh key. I this scenario I use ssh key authentication. Below photo is using connect using SSH. You can directly connect yuor lightsail via browser.


I change my tst-svr.pem file’s permission. And then I connect my lightsail via ssh key. After login successful I update the system. And then I download wordpress. And then unzip this file.
sudo chmod 400 tst-svr.pem
ssh -i tst-svr.pem ubuntu@(server ip )
sudo apt update && sudo apt upgrade -y
wget https://wordpress.org/latest.zip
unzip latest.zip


After unzip process install require packages.
sudo apt install nginx mysql-server php-fpm php-mysql php-curl php-gd php-mbstring php-xml pho-xmlrpc pho-soap php-intl php-zip -y

After install packages start and enable service.
sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl start mysql
sudo systemctl enable mysql

After start and enable services configure mysql database.
sudo mysql_secure_installation


After configure mysql database create database for wordpress.
sudo mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER ‘wpuser’@’localhost’ IDENTIFIED BY ‘dbadmin123’;
GRANT ALL PRIVILEGES ON wordpress.* TO ‘wpuser’@’localhost’;
FLUSH PRIVILEGES;
EXIT;

After create database for wordpress let’s configure wordpress. Move wordpress directory to /var/www/html location and change ownership and define permissions.
sudo mv wordpress/ /var/www/html/
sudo chown -R www-data:www-data /var/www/html/wordpress/
sudo chmod -R 755 /var/www/html/wordpress/

copy wp-config-sample.php to wp-config.php and then define DB_NAME, DB_USER, DB_PASSWORD, DB_HOST in this wp-config.php file.
sudo cp wp-config-sample.php wp-config.php
sudo vi wp-config.php


After define DB info in wp-config. Let’s configure ngninx web server side.
sudo vi /etc/nginx/sites-available/wordpress


server {
listen 80;
server_name your-domain;
root /var/www/html/wordpress;
index index.php index.html index.htm;
access_log /var/log/nginx/wordpress_access.log;
error_log /var/log/nginx/wordpress_error.log;
location / {
try_files $uri $uri/ /index.php?$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
expires max;
log_not_found off;
}
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; }
}

After define nginx config file create softlink and restart nginx service.
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
sudo ngninx -s reload
sudo nginx -t

Aftet define and restart nginx service. Bind your server ip with domain. I use cloudflare for domain. Define A record in dns record setting. After binding ip and domain you can check using nslookup command for actually domain is binding or not.

Now you can access your wordpress poral calling with domain name.





Even I’ve finished to setup wordpress settings my website can access only with http not https.

So I setup Let’s encrypt certbot for https access. Install require packages. And run certbot.
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d your domain


Now you can see my website can access via https vaild for 3 months.


Now you can see how to install and setup wordpress on AWS Lightsail with extra Let’s encrypt for SSL/TLS. After you test and run this scenario don’t forget to delete Lightsail. I don’t want to charges any extra cloud costs. Let me stop here and stay tune for another demo and lab. Happy learning. Thanks for giving me your time. If you enjoy and helpful this tutorial please like and share. I would really appreciate your support.




