How can I host an HTML website as a subdomain in my Lightsail WordPress instance?

Last updated: 2021-10-21

I want to create an additional HTML website in my Amazon Lightsail WordPress instance as a subdomain. How can I do that?

Short description

Lightsail WordPress instances have the WordPress application pre-installed. To host a subdomain in addition to your current WordPress website, create an additional virtual host in the Apache configuration file.

Resolution

Note: The file paths in the following resolution steps might change depending on the following:

  • The Bitnami stack uses native Linux system packages (Approach A).
  • The Bitnami stack is a self-contained installation (Approach B).

To identify your Bitnami installation type, run the following command:

test ! -f "/opt/bitnami/common/bin/openssl" && echo "Approach A: Using system packages." || echo "Approach B: Self-contained installation."

The WordPress stack is under Approach A

1.    Open a new vhost file in the Apache configuration directory by running the following command. In the following example command, replace sub.example.com with your subdomain's name.

sudo nano /opt/bitnami/apache2/conf/vhosts/sub.example.com-vhost.conf

2.    Add the following entries to the configuration file. In the following example, replace sub.example with your subdomain's name and /opt/bitnami/wordpress/sub with the directory where you plan to host the subdomain.

<VirtualHost *:80>
    ServerName sub.example.com
    DocumentRoot "/opt/bitnami/wordpress/sub"
    <Directory "/opt/bitnami/wordpress/sub">
    Options +MultiViews +FollowSymLinks
    AllowOverride All
    Require all granted
    </Directory>
</VirtualHost>

3.    To turn on HTTPS for the subdomain, purchase and install an SSL certificate for the subdomain. Then, add the following entries at the end of the vhost file /opt/bitnami/apache2/conf/vhosts/sub.example.com-vhost.conf. In the following example, replace ServerName, DocumentRoot, SSLCertificateFile, and SSLCertificateKeyFile with the correct values for you environment.

<VirtualHost *:443>
    ServerName sub.example.com
    DocumentRoot "/opt/bitnami/wordpress/sub"
    SSLEngine on
    SSLCertificateFile "/opt/bitnami/apache2/conf/bitnami/certs/server.crt"
    SSLCertificateKeyFile "/opt/bitnami/apache2/conf/bitnami/certs/server.key"
    <Directory "/opt/bitnami/wordpress/sub">
    Options +MultiViews +FollowSymLinks
    AllowOverride All
    Require all granted
    </Directory>
</VirtualHost>

4.    Save the file by pressing ctrl+x on the keyboard, then press Y, and then press ENTER.

5.    Run the following command to restart the Apache service:

sudo /opt/bitnami/ctlscript.sh restart apache

The Wordpress stack is under Approach B

1.    Open a new vhost file in the Apache configuration directory by running the following command:

sudo nano /opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf

2.    Add the following entries in the file. In the following example, replace sub.example with your subdomain name and /opt/bitnami/apps/wordpress/htdocs/sub with the directory where you plan to host the subdomain.

<VirtualHost *:80>
    ServerName sub.example.com
    DocumentRoot "/opt/bitnami/apps/wordpress/htdocs/sub"
    <Directory "/opt/bitnami/apps/wordpress/htdocs/sub">
    Options +MultiViews +FollowSymLinks
    AllowOverride All
    Require all granted
    </Directory>
</VirtualHost>

3.    To enable HTTPS for the sub domain, purchase and install an SSL certificate for the subdomain. Then, add the following entries at the end of the vhost file /opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf. In the following example, replace ServerName, DocumentRoot, SSLCertificateFile,and SSLCertificateKeyFile with the correct values for your environment.

<VirtualHost *:443>
    ServerName sub.example.com
    DocumentRoot "/opt/bitnami/apps/wordpress/htdocs/sub"
    SSLEngine on
    SSLCertificateFile "/opt/bitnami/apache2/conf/server.crt"
    SSLCertificateKeyFile "/opt/bitnami/apache2/conf/server.key"
    <Directory "/opt/bitnami/apps/wordpress/htdocs/sub">
    Options +MultiViews +FollowSymLinks
    AllowOverride All
    Require all granted
    </Directory>
</VirtualHost>

4.    Save the file by pressing ctrl+x on the keyboard, then press Y, and then press ENTER.

5.    Run the following command to restart Apache service:

sudo /opt/bitnami/ctlscript.sh restart apache

Did this article help?


Do you need billing or technical support?