Deploy additional WordPress on Google Cloud with SSL

deploy additional wordpress on google cloud

Have you started your WordPress website with one click deployment using google cloud? And now want to host another WordPress on the same VM? If yes then this tutorial is a great fit for you. See how we can deploy additional WordPress on Google Cloud with an SSL certificate.
This tutorial will explain the shortest way to add an extra WordPress on the VM.

Disclaimer: For following this post intermediate level of knowledge is required of Linux and Google Cloud. Please take a backup of existing WordPress before going further. Also, read the Disclaimer first.

Note: In this tutorial, it is assumed that there is already a WordPress running with SSL and it is for adding another WordPress with SSL.

Please make sure you have SSH access and know, how to use putty or other SSH client to run commands on the server.

If you are running a WordPress on Google Cloud VM then the directory /etc/apache2/sites-available will contain the following files.
1 – 000-default.conf
2 – default-ssl.conf
3 – wordpress.conf

The default WordPress folder is /var/www/html

Deploy additional WordPress

Deploy additional WordPress on google cloud is not too hard just follow the instructions carefully.

Step 1 – Create an extra folder for our another WordPress in www folder. I call it html1. Just navigate to /var/www and create a directory with sudo mkdir html1

Step 2 – After that give the appropriate permissions to the folder. The commands are given below.
sudo chown -R www-data:www-data /var/www/html1/
sudo chmod -R www-data /var/www/html1/

For additional help go to the following URL – Deploy WordPress.

Step 3 – Make an empty database in PHPMyAdmin with any name like wordpress1 by the following query.
CREATE DATABASE wordpress1;
Step 4 – Make a new user for this database e.g. wpuser.
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'new_password_here';

Then give permissions to this user by the following commands.

GRANT ALL ON wordpress1.* TO 'wpuser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;

FLUSH PRIVILEGES;

Step 5 – Download and extract the latest WordPress from the official website.

cd /tmp && wget https://wordpress.org/latest.tar.gz 
tar -zxvf latest.tar.gz 
sudo mv wordpress/* /var/www/html1/

Now edit the wp-config.php file and set the database username and passwords by sudo nano wp-config.php

Note: If you have your files in WordPress folder then move them to html1 directory and delete the WordPress directory. So the html1 directory will be the root of the new WordPress.

Now before going further kindly note that example.com is already running WordPress and we are adding another WordPress example.org to the existing VM.

Edits in 000-default.conf

Open 000-default.conf and add an extra Virtual Host in it. The example is given below. The file is minimized by removing the comments from it.

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName example.com
        ServerAlias www.example.com
        DocumentRoot /var/www/html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName example.org
        ServerAlias www.example.org
        DocumentRoot /var/www/html1
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Edits in default-ssl.conf

Add the second virtual host in “default-ssl.conf” file and set the paths for the SSL certificate files. The example is given below.

<IfModule mod_ssl.c>
        NameVirtualHost *.443
        <VirtualHost *:443>
                ServerAdmin webmaster@localhost
                ServerName example.com
                ServerAlias www.example.com
                DocumentRoot /var/www/html
                ErrorLog ${APACHE_LOG_DIR}/error.log
                CustomLog ${APACHE_LOG_DIR}/access.log combined
                SSLEngine on
                SSLCertificateFile      /var/www/html/certificatefiles/certificate.crt
                SSLCertificateKeyFile /var/www/html/certificatefiles/privatekey.pem
                SSLCACertificateFile /var/www/html/certificatefiles/cabundle.crt
                <FilesMatch "\.(cgi|shtml|phtml|php)$">
                    SSLOptions +StdEnvVars
                </FilesMatch>
                <Directory /usr/lib/cgi-bin>
                    SSLOptions +StdEnvVars
                </Directory>
        </VirtualHost>
        <VirtualHost *:443>
                ServerAdmin webmaster@localhost
                ServerName example.org
                ServerAlias www.example.org
                DocumentRoot /var/www/html1
                ErrorLog ${APACHE_LOG_DIR}/error.log
                CustomLog ${APACHE_LOG_DIR}/access.log combined
                SSLEngine on
                SSLCertificateFile      /var/www/html1/certificatefiles/certificate.crt
                SSLCertificateKeyFile /var/www/html1/certificatefiles/privatekey.pem
                SSLCACertificateFile /var/www/html1/certificatefiles/cabundle.crt
                <FilesMatch "\.(cgi|shtml|phtml|php)$">
                    SSLOptions +StdEnvVars
                </FilesMatch>
                <Directory /usr/lib/cgi-bin>
                    SSLOptions +StdEnvVars
                </Directory>

        </VirtualHost>
</IfModule>

Edits in wordpress.conf

Add the second directory for the another wordpress and disable the index options on that directory. The example is given below

<Directory /var/www/html>
  Options -Indexes
</Directory>
<Directory /var/www/html1>
 Options -Indexes
</Directory>

Now reload and restart the apache2 service by the following commands.
sudo systemctl reload apache2
sudo service restart apache2

After that you will be able to see your website with the url example.org.

Don’t forget to add A record with the IP of VM on the new domain’s DNS for pointing it to the existing VM.
Use “Really Simple SSL” Plugin to migrate your site from http to https after doing all.

Thanks for reading the tutorial for deploying additional wordpress on google cloud. Also read, Get Free SSL .

Related posts

Leave a Comment