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

3 minute read
0

I want to create an additional HTML website in my Amazon Lightsail WordPress instance as a subdomain.

Short description

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

Resolution

Complete the steps for your Bitnami stack installation type.

To identify your 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 Bitnami stack uses native Linux system packages

If your Bitnami stack uses a native Linux system package, then complete the following steps: 

  1. Run the following command to open a new vhost file in the Apache configuration directory. 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. 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/TLS 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. Replace ServerName, DocumentRoot, SSLCertificateFile, and SSLCertificateKeyFile with your values:

    <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. To save the file, press Ctrl+x, press Y, and then press Enter.

  5. Run the following command to restart Apache:

    sudo /opt/bitnami/ctlscript.sh restart apache

The Bitnami stack is a self-contained installation

If your Bitnami stack is a self-contained installation, then complete the following steps:

  1.    Run the following command to open a new vhost file in the Apache configuration directory:

    sudo nano /opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf
  2. Add the following entries in the file. 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 activate HTTPS for the subdomain, purchase and install an SSL/TLS 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. Replace ServerName, DocumentRoot, SSLCertificateFile, and SSLCertificateKeyFile with your values:

    <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. To save the file, press Ctrl+x on the keyboard, press Y, and then press Enter.

  5. Run the following command to restart Apache:

    sudo /opt/bitnami/ctlscript.sh restart apache
AWS OFFICIAL
AWS OFFICIALUpdated 5 months ago