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 pre-installed. To host a subdomain in addition to your current WordPress website, create an additional virtual host in the Apache configuration file.
Resolution
The file paths in the following resolution steps might change depending on the following:
- The Bitnami stack uses native Linux system packages.
- The Bitnami stack is a self-contained installation.
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 Bitnami stack uses native Linux system packages
1. Open a new vhost file in the Apache configuration directory with 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 replace /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 your 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 Bitnami stack is a self-contained installation
1. Open a new vhost file in the Apache configuration directory with 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 replace /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 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