This tutorial is not a step by step guide for the entire process. It builds on what you learned from following the entire blog series Raspberry Pi Webserver.

To add another domain and website to this existing Apache server, have your domain name bought or grab a free one. Also, add your domain to Cloudflare as you did in a previous tutorial – Link to Cloudflare tutorial.

Starting with the website location. Create a new directory under /var/www. Giving it the name of your website. Throughout this tutorial I will use example.com as the new website I want to create.

cd /var/www
sudo mkdir example.com

Next, you need to create a simple html page so we can test to see if the configurations changes you will make are working. Here is a script to create and add text to a page.

sudo echo '<h1> Example.com testing page </h1>' > index.html

Heading over to the sites-available directory. Create our example.com.conf config file by copying the default config file 000-default.conf. Then edit example.com.conf file.

cd /etc/apache2/sites-available
sudo cp 000-default.conf example.com.conf
sudo nano example.com.conf

Change the default information from this:

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

To this, adding the two top lines and changing the last:

ServerName www.example.com
ServerAlias example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/example.com

That’s it, now you just need to enable the website, reload Apache, and test your domain name.

sudo a2ensite example.com
sudo systemctl reload apache2

Next, create a new database for use with this new domain.

sudo mysql -u root -p <your_password>

Once you have the mysql prompt, follow these commands to create the database. Change wordpressDB to whatever you want to call it.

CREATE DATABASE wordpressDB;
GRANT ALL PRIVILEGES ON wordpressDB.* TO 'root'@'localhost' IDENTIFIED BY 'your_password';
FLUSH PRIVILEGES;

Ctrl+D to exit the sql prompt.

Heading back to /var/www/example.com, remove the index.html you created earlier.

cd /var/www/example.com
sudo rm index.html

Installing WordPress – download and unzip a copy and place it in your new domain location. If you need help, check out the previous tutorial Installation of WordPress. Below are the commands to install it.

cd /var/www
sudo wget http://wordpress.org/latest.tar.gz
sudo tar xzf latest.tar.gz
sudo mv wordpress/* example.com
sudo chown -R www-data: example.com
sudo rm latest.tar.gz
sudo rm -d wordpress

At this point when you hit your domain name in the browser, you should see the WordPress setup screen. Follow along with the previous tutorial for any needed help – Configure WordPress.

Next, let’s do the encryption. Since Let’s Encrypt was install earlier, we will start by turning Proxy Status to off in Cloudflare, as we did in this tutorial – Free Site Encryption With Let’s Encrypt.

Starting the process, enter this command to chose with domain to setup encryption for.

certbot --apache

After the encryption process is complete, head back and turn the Proxies back on.

Then in the menu select SSL/TLS and set your encryption mode to Full(strict).

That’s it, you should now how have a whole new site that is available to the internet and well protected. Enjoy!!

Share this content: