How to install and configure wordpress and MySQL on AWS Lightsail Ubuntu instance

Step-by-step guide for installing and configuring WordPress and MySQL on an AWS Lightsail Ubuntu instance:

Step 1: Create an AWS Lightsail Instance

  1. Log in to AWS Lightsail: https://lightsail.aws.amazon.com
  2. Click Create Instance.
  3. Choose Linux/Unix as the platform.
  4. Select Ubuntu 22.04 LTS (or latest version).
  5. Choose a plan (at least 1GB RAM for better performance).
  6. Name your instance (e.g., wordpress-server).
  7. Click Create Instance.
  8. Wait for the instance to launch.

Step 2: Connect to the Lightsail Ubuntu Instance

  1. In the Lightsail Dashboard, select your instance.
  2. Click Connect using SSH (or use your terminal: ssh ubuntu@your-instance-ip).

Step 3: Update and Install Required Packages

Run the following commands to update the system and install dependencies:

sudo apt update && sudo apt upgrade -y

sudo apt install apache2 mysql-server php php-mysql php-cli php-curl php-gd php-mbstring php-xml php-zip unzip -y


Step 4: Configure MySQL Database

  1. Secure the MySQL installation:

sudo mysql_secure_installation

  1. Set a root password: Yes
  2. Remove anonymous users: Yes
  3. Disallow remote root login: Yes
  4. Remove test database: Yes
  5. Reload privilege tables: Yes
  6. Log in to MySQL:

sudo mysql -u root -p

  1. Create a database and user for WordPress:

CREATE DATABASE wordpress_db;

CREATE USER ‘wp_user’@’localhost’ IDENTIFIED BY ‘your_password’;

GRANT ALL PRIVILEGES ON wordpress_db.* TO ‘wp_user’@’localhost’;

FLUSH PRIVILEGES;

EXIT;


Step 5: Install WordPress

  1. Download and extract WordPress:

cd /var/www/html

sudo rm -rf index.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

  1. Set correct permissions:

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

sudo chmod -R 755 /var/www/html


Step 6: Configure WordPress

  1. Copy the sample config file:

sudo cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php

  1. Edit the wp-config.php file:

sudo nano /var/www/html/wp-config.php

Update these lines with your database details:

define(‘DB_NAME’, ‘wordpress_db’);

define(‘DB_USER’, ‘wp_user’);

define(‘DB_PASSWORD’, ‘your_password’);

define(‘DB_HOST’, ‘localhost’);

Save and exit (CTRL+X, Y, ENTER).


Step 7: Configure Apache for WordPress

  1. Create a new Virtual Host file:

sudo nano /etc/apache2/sites-available/wordpress.conf

<VirtualHost *:80>

    ServerAdmin admin@yourdomain.com

    DocumentRoot /var/www/html

    ServerName yourdomain.com

    ServerAlias www.yourdomain.com

    <Directory /var/www/html>

        AllowOverride All

    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Save and exit (CTRL+X, Y, ENTER).

  1. Enable the new site and required modules:

sudo a2ensite wordpress.conf

sudo a2enmod rewrite

sudo systemctl restart apache2


Step 8: Complete WordPress Installation

  1. Open your browser and visit:

http://your-instance-public-ip

  1. Follow the WordPress installation wizard:
    • Choose your language.
    • Enter database details.
    • Set up admin username and password.
    • Click Install WordPress.

Step 9: Secure Your WordPress Site (SSL)

To install a Let’s Encrypt SSL certificate:

sudo apt install certbot python3-certbot-apache -y

sudo certbot –apache

  • Enter your domain name when prompted.
  • Certbot will automatically configure SSL.

Renew SSL automatically:

sudo certbot renew –dry-run


Step 10: Enable Firewall (Optional)

Run the following commands to allow traffic:

sudo ufw allow OpenSSH

sudo ufw allow “Apache Full”

sudo ufw enable


Step 11: Access WordPress Admin Panel

Go to:

http://yourdomain.com/wp-admin

Log in with the username and password you set during installation.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *