How to Deploy a WordPress Site on AWS Lightsail

Nihal Dias
4 min readSep 15, 2024

--

How to Deploy a WordPress Site on AWS Lightsail

Deploying a WordPress site on AWS Lightsail provides an affordable, easy-to-use, and scalable way to host your website. If you already have the plugins, themes, uploads folders and index.php files from an existing WordPress site, this guide will walk you through deploying them to a fresh Lightsail instance.

Step-by-Step Guide:

1. Set Up AWS Lightsail Instance

  • Log into AWS Lightsail: Visit the AWS Lightsail console and log in to your account.
  • Create a New Instance:
  • Click Create Instance.
  • Under Select a platform, choose Linux/Unix.
  • Under Select a blueprint, choose WordPress. This will launch a pre-configured WordPress environment.
  • Select the instance plan based on your website traffic needs. Start with a basic plan (e.g., $5 or $10) and scale up as required.
  • Name your instance and click Create Instance.
  • Wait for the Instance to Launch: The instance will take a few minutes to launch. Once the instance is ready, you’ll see its status as Running.

2. Access Your Instance via SSH

  • Once the instance is running, click on your instance’s name to access its details.
  • Use the Connect using SSH option provided by Lightsail to open an SSH session in your browser.

3. Install and Configure File Transfer Tools

To upload your WordPress files, you’ll need to transfer your local plugins, themes, uploads, and index.php files to the instance.

Option 1: Using SFTP (Preferred)

  • Install an FTP Client: Use an SFTP client like FileZilla or Cyberduck. These tools allow you to securely transfer your files to your Lightsail instance.
  • Get SFTP Connection Details:
    1.
    On your Lightsail instance’s page, find the Account page to retrieve your SSH key. This key allows you to authenticate securely when connecting via SFTP.
    2. Click Account page > SSH keys > Download the private key (.pem file).
  • Configure SFTP Client (FileZilla Example):
    1.
    Open FileZilla and go to Edit > Settings > SFTP.
    2. Add the private key you downloaded (.pem file).
    3. In FileZilla, connect to your Lightsail instance by entering the following details:
    Host: sftp://<Public_IP_of_Lightsail_instance>
    Username: bitnami (default for Lightsail WordPress)
    Port: 22
    4. Click Quickconnect to establish the connection.

Option 2: Manual Upload via SCP

If you prefer, you can use the scp command in your terminal to manually upload files from your local machine to the Lightsail instance. Use the following syntax:

scp -i /path/to/your-key.pem -r /local/path/to/plugins bitnami@<Public_IP_of_Lightsail_instance>:/opt/bitnami/wordpress/wp-content/plugins
scp -i /path/to/your-key.pem -r /local/path/to/themes bitnami@<Public_IP_of_Lightsail_instance>:/opt/bitnami/wordpress/wp-content/themes
scp -i /path/to/your-key.pem -r /local/path/to/uploads bitnami@<Public_IP_of_Lightsail_instance>:/opt/bitnami/wordpress/wp-content/uploads
scp -i /path/to/your-key.pem /local/path/to/index.php bitnami@<Public_IP_of_Lightsail_instance>:/opt/bitnami/wordpress

4. Upload Your WordPress Files

Now that you have SFTP access, navigate to the relevant directories on the server and upload the existing files from your local WordPress site.

  • Navigate to WordPress Directory: The WordPress installation on your Lightsail instance is located at /opt/bitnami/wordpress.
  • Transfer plugins, themes, uploads, and index.php: Upload the plugins, themes, and uploads folders to /opt/bitnami/wordpress/wp-content/, replacing any existing default folders.
  • Similarly, upload your index.php file to the root directory /opt/bitnami/wordpress, replacing the default file.

5. Configure Database (If Needed)

If your WordPress site relies on a database, you’ll need to import your existing database into the Lightsail instance.

  • Access MySQL Database: Lightsail uses a Bitnami WordPress stack, which comes with MySQL. To access the database:
    1. SSH into your instance and run:
    mysql -u root -p
    2. Enter the MySQL root password. You can find this password by checking the following file:
    cat /home/bitnami/bitnami_application_password
  • Import Database: If you have a backup of your old WordPress database (.sql file), upload it to your Lightsail instance using SFTP and import it into the MySQL database:
mysql -u root -p wordpress < /path/to/your/database_backup.sql

6. Update wp-config.php

After uploading the files and importing the database, you may need to modify your wp-config.php file to ensure the database credentials match the current MySQL setup.

  • Locate wp-config.php: The file is located in /opt/bitnami/wordpress/wp-config.php.
  • Update Database Credentials: Open the file in a text editor and update the following lines to match the MySQL credentials of your Lightsail instance:
define('DB_NAME', 'wordpress'); 
define('DB_USER', 'root');
define('DB_PASSWORD', 'your_root_password');
define('DB_HOST', 'localhost');

7. Update File Permissions

To ensure WordPress can run properly, update the file permissions on your newly uploaded files.

sudo chown -R bitnami:daemon /opt/bitnami/wordpress
sudo find /opt/bitnami/wordpress -type d -exec chmod 755 {} \;
sudo find /opt/bitnami/wordpress -type f -exec chmod 644 {} \;

8. Configure Domain and SSL (Optional)

If you have a domain name, you can point it to the public IP of your Lightsail instance. Additionally, it’s recommended to secure your site with an SSL certificate.

  • Assign a Static IP: In the Lightsail dashboard, go to Networking, assign a static IP to your instance, and point your domain’s DNS to this IP.
  • Install SSL (Let’s Encrypt): Lightsail provides an easy way to install Let’s Encrypt for SSL. Run the following command to generate an SSL certificate:
sudo /opt/bitnami/bncert-tool

Follow the prompts to configure your domain and apply the SSL certificate.

9. Test Your Site

Finally, visit your domain or public IP address in a browser to check if your site is live and fully functional. Verify that all plugins, themes, and media files are in place and working as expected.

--

--

Nihal Dias
Nihal Dias

Written by Nihal Dias

Just your run-of-the-mill Software Developer who's also an anime fanatic. I write about Software Development, Cloud Computing and Machine Learning.

No responses yet