WordPress with SSL on Amazon Lightsail

How to run a wordpress blog on Amazon Lightsail

Amazon Lightsail offers VPS instances, databases, storage, and more at low monthly prices. With Amazon Lightsail, you can create websites with just a few clicks and automatically configure various things including server, networking, and security. Launching and running a wordpress website is very easy with lightsail since it offers a prebuilt image that allows you to run a wordpress blog with a single click. All you need to do is to create an Amazon Lightsail wordpress instance and it will have everything preconfigured including the server, wordpress, database and the latest version of php. Not just wordpress, but Lightsail allows you to launch other preconfigured applications also like Joomla, Prestoshop, and Magento.

Create a WordPress Lightsail Instance

To run a wordpress blog using Amazon Lightsaill, you will first need to create a wordpress instance.

Login to your AWS management console and then search for Lightsail. Once inside the Lightsail dashboard click on create instances on the right at the top.

In the first step, you will need to select the location of your instance and then the platform and OS. For platform, select Linux/Unix (default selection) and for App and OS Select wordpress. The preconfigured wordpress image in lightsail is brought to you by Bitnami..

Let me tell you a few things about this official wordpress image. The preconfigured WordPress package includes everything you need to run wordpress including the latest versions of wordpress and php, and the mariadb database. The Apache server is also a part of this image. Generally, if you want to install wordpress manually on an instance (like EC2 or Azure VM instance), you will first need to install a webserver on it (Apache or Nginx) and then you will need to download the latest version of wordpress to the server and extract it. You will also need to install the mariadb or mysql database and php. Apart from installing these things, you will need to configure the database manually including adding a user, password and creating a new database and then you will need to set the wp-config.php file which includes all the wordpress configurations required by wordpress to connect with the database.  

 However, when you launch wordpress using the preconfigured official wordpress image on AWS for lightsail, you do not need to do any of the above, but you can directly jump to login and start using your wordpress website. The only thing that you will need to add to your website is the custom domain name and you can access your blog online which is otherwise available at the instance ip.

So, once you have selected wordpress image, choose the right plan for your instance. Lightsail plans start from $3.5 and go up to $160. After selecting the right instance size and adding tags, you can click on create instance. In a few minutes the instance will be ready. Once you have created the wordpress instance, you can connect to it using SSH. Now, if you check the ip assigned to your instance, you will see a wordpress blog there. It is a brand new wordpress blog without a custom domain and only the hello world post. The blog is named user’s blog. It is so because when you create a wordpress instance, the username assigned to you is simply ‘user’.

After instance creation, your first step is to obtain the password and then login to the wordpress dashboard, which is available at: http://your_public_ip/wp-login.php

To connect to your lightsail instance using SSH, just click on the instance and it will take you to the page with a button “connect using SSH”. Click on it.

Now, to obtain the password created by the system, connect to the lightsail instance using ssh and run the following command:

$ cat $HOME/bitnami_application_password

 

Copy the password provided by the system and then go to your wordpress installation using your public_ip.

http://public_ip/wp-login.php

You can login with the username ‘user’ and the password you just copied.

When you login, you will find yourself on the admin dashboard, from where you can check out the plugins and themes and add new posts.

However, this is not how you are going to run your wordpress blog. To do that, you need to add a custom domain, which is very easy. You can add a custom domain to your blog by just adding a DNS zone to Amazon Lightsail. If you prefer otherwise, you can use another DNS host too like Route53. However, if you manage your DNS in Lightsail, it is routed through Amazon’s Route53 only. If you use a different DNS provider like Godaddy or Cloudflare, you will need to change A records there. Just create an A record for your domain and one for the www subdomain and point them to the public ip of your instance. That’s all. Now, if you launch your domain in a browser, you will land on your wordpress blog page. Now, you can login to your wordpress blog using your domain name. Go to ‘http://your_domain/wp-login.php’ and login again using the same username and password.

The default wordpress installation on Lightsail comes with some preinstalled plugins which you can check out by going to the plugins section from the wp-admin dashboard. They include Jetpack, AIOSEO, W3TC and other plugins. You can configure the plugins first since you will need to activate at least the SEO and cache plugins for your brand new wordpress site. Otherwise, you can do it later after configuring ssl for your website. The process to enable free ssl from Letsencrypt on Birnami wordpress application is slightly different from the regular method where you use certbot to install SSL certificates.

To install ssl certificates for your website, you will need to run the following command:

$ sudo /opt/bitnami/bncert-tool

You will see an output like the following:

bitnami@ip-17x-xx-x-xxx:~$ sudo /opt/bitnami/bncert-tool

—————————————————————————-

Welcome to the Bitnami HTTPS Configuration tool.

—————————————————————————-

Domains

Please provide a valid space-separated list of domains for which you wish to

configure your web server.

Domain List []:

—-

You need to add the domains that you want to install ssl for separated by a comma like:

Domain List []: example.com, www.example.com

The system will also prompt you to select the type of redirections you want to enable on your website like www to non-www or vice versa. Select the one you want to add and then proceed.

At the end, the system will ask you if you want to redirect the traffic from http to https. Reply yes by entering ‘y’. When you have responded, the system will output a list of changes to be made to the server.

Take a look at the list below. You may see a similar but slightly longer list if you have also included the www version:

Changes to perform

The following changes will be performed to your Bitnami installation:

  1. Stop web server
  2. Configure web server to use a free Let’s Encrypt certificate for the domains:

example.com

  1. Configure a cron job to automatically renew the certificate each month
  2. Configure web server name to: example.com
  3. Enable HTTP to HTTPS redirection (example: redirect

to https://example.com)

  1. Start web server once all changes have been performed

——————————-

Reply in affirmative for the system to carry out the changes. Provide your email address when asked to and then agree to the terms of agreement.

SSL configuration for your blog may take a little time. So, wait patiently and once it is over, you can access your blog on https. At the end, you will receive a success message if the installation is successful. You have successfully started your wordpress blog on an Amazon Lightsail instance with ssl enabled.

Accessing WP configuration and Apache configuration file

Now, in case you need to make changes to your wp-config.php file which is the main configuration file for wordpress, you can open it using the following command:

$ sudo nano /opt/bitnami/wordpress/wp-config.php

You will see the database credentials inside this file. The default database created by the system is named bitnami_wordpress and the default user is bn_wordpress.

The document root file for your wordpress blog is : /opt/bitnami/apache/htdocs

The default Apache configuration file for your bitnami wordpress site can be checked using :

$ sudo nano /opt/bitnami/apache/conf/httpd.conf

More configurations are found here: /opt/bitnami/apache/conf/bitnami/bitnami.conf 

Inside the main Apache configuration file for your bitnami wordpress application, you will also see a list of enabled and disabled modules. If you want to enable a module just uncomment it and to disable a module just comment it out. The default MPM enabled for your wordpress instance is MPM Event.

Accessing phpMyAdmin

If you try to access your website database using ‘https://your_domain/phpmyadmin’, you will not see the phpMyAdmin dashboard but the following message. “For security reasons, this URL is only accessible using localhost (127.0.0.1) as the hostname.”

To access the phpMyAdmin dashboard, you can make the following changes. Run the following command to open phpMyAdmin configuration:

$ sudo nano /opt/bitnami/apache/conf/bitnami/phpmyadmin.conf

Inside this file, scroll down until you see the following:

“Require local

ErrorDocument 403 “For security reasons, this URL is only accessible using localhost 127.0.0.1 as the hostname.”

Replace the above with – ‘Require all granted’

After making these changes, you will need to restart Apache. To do that run the following command:

$  sudo /opt/bitnami/ctlscript.sh restart apache

Now, if you try to access phpMyAdmin using ‘https://your_domain/phpmyadmin’, you will find yourself on the phpMyAdmin login page.

You will need the database credentials to login to the database. The default user is bn_wordpress and the password is available inside the wp-config.php file. Copy the password from there and login to your mariadb database with the user and password listed inside wp-config file.

$ sudo nano /opt/bitnami/wordpress/wp-config.php

Copy the password provided in DB_Password and then login to phpMyAdmin.

Once you are logged in, you will see the bitnami wordpress database listed on the left in the sidebar. Click on it to expand it and you can check out the tables. The details related to your database and version can be found on the right.

So, you now have an active wordpress blog running on Lightsail with mariadb database and ssl enabled. You hardly had to configure anything and your blog was ready to go within minutes.

To learn about your PHP and apache webserver versions, just run the following commands:

$ php -v

$ httpd -v

The output will look like the following:

bitnami@ip-17x-xx-x-xxx:~$ php -v

PHP 8.1.17 (cli) (built: Mar 21 2023 18:33:02) (NTS)

Copyright (c) The PHP Group

Zend Engine v4.1.17, Copyright (c) Zend Technologies

with Zend OPcache v8.1.17, Copyright (c), by Zend Technologies

bitnami@ip-17x-xx-x-xxx:~$ httpd -v

Server version: Apache/2.4.56 (Unix)

Server built:   Mar 16 2023 18:04:22

However, before we end this tutorial, there are a few more important things that you might need to know. For example, Opcache is enabled by default on Bitnami wordpress installation. It speeds up your wordpress blog. You can also enable Memcached or Redis for more speed. The mariadb database server that comes with the Bitnami installation is also faster. There is one more file that you want to know about and which contains some important configurations including those related to Opcache. It is the php.ini file. This file can be opened using the following command:

$ sudo nano /opt/bitnami/php/etc/php.ini

So, this was how you can easily install and run a wordpress blog on lightsail. There is nothing else to be done and you can just start adding content and modifying your blog’s look according to your choice.

Thanks for reading!