Create A Private Test Website For An Existing Repository (Ubuntu 20.10)

The scenario I'm using to write this tutorial is that I'm creating a private test website for the mattifesto.com website. Adjust the domains for your situation.

To complete this task you should have already created a private test web server. This web server should have a public domain name which points to the web server's private IP address on your local network. The web server's domain name in this example is:

webserver3.mattifesto.com

You should choose a domain for your private test website by adding one subdomain to this domain, such as:

mattifesto.webserver3.mattifesto.com

This domain should be given a public CNAME record that points to the web server domain.

Setup GitHub SSH

2021_04_04

These instructions may be needed but I do not need them today. They should be reviewed.

If you have private GitHub repositories you will need to authenticate with GitHub using SSH keys. You should generate keys for each server but save them on your development machine so that you can copy them each time you recreate the virtual machine for that server rather than creating new keys every time.

This link tells you more about this process.

https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

If you have your keys on your dev machine but just created a new virtual machine these instructions help you copy them to the new VM.

In MacOS terminal signed in to Mac:

  • $ scp -r <key directory> webserver1:~

In MacOS terminal sign in to server VM:

  • move keys to .ssh directory

  • $ eval "$(ssh-agent -s)"

  • $ ssh-add <key name>

Create The Website Directory On The Web Server

  • $ ssh mattcalkins@webserver3.mattifesto.com

  • Navigate to the folder the contains all your website directories. In my case this is /home/mattcalkins/www .

    $ cd www

  • Create the root website directory and the logs subdirectory. I use the reverse domain name for my root website directories, but you can use whatever naming scheme you like.

    $ mkdir -p com_mattifesto_webserver3_mattifesto/logs

    $ cd com_mattifesto_webserver3_mattifesto

  • Clone the website git repository and create the new document_root directory.

    $ git clone git@github.com:mattifesto/com_mattifesto.git document_root

  • Initialize all the submodules.

    $ cd document_root

    $ git submodule update --init --recursive

Create Database

One of the principles of the Mattifesto Method is using unique identifiers which makes searching and potentially replacing much easier. The database is named "com_mattifesto_webserver3_mattifesto_database" because naming it "mattifesto" would create a name overlap in many places.

  • $ sudo mysql

  • mysql> create database com_mattifesto_webserver3_mattifesto_database;

  • mysql> create user 'web'@'localhost' identified with mysql_native_password BY '********';

  • mysql> grant all on com_mattifesto_webserver3_mattifesto_database.* to 'web'@'localhost';

  • mysql> exit;

  • $ mysql -u web -p

  • mysql> show databases;

  • mysql> exit;

Create Virtual Host

Reference:

https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-20-04#step-4-—-creating-a-virtual-host-for-your-website

  • $ sudo vi /etc/apache2/sites-available/com_mattifesto_webserver3_mattifesto.conf

    <VirtualHost *:80>
    
        ServerName      mattifesto.webserver3.mattifesto.com
    
        ServerAdmin     matt@mattifesto.com
        DocumentRoot    /home/mattcalkins/www/com_mattifesto_webserver3_mattifesto/document_root
        ErrorLog        /home/mattcalkins/www/com_mattifesto_webserver3_mattifesto/logs/error.log
        CustomLog       /home/mattcalkins/www/com_mattifesto_webserver3_mattifesto/logs/access.log combined
    
        <Directory "/home/mattcalkins/www/com_mattifesto_webserver3_mattifesto/document_root">
            AllowOverride   all
            Require         all granted
        </Directory>
    
    </VirtualHost>
    
    <VirtualHost *:443>
    
        ServerName      mattifesto.webserver3.mattifesto.com
    
        ServerAdmin     matt@mattifesto.com
        DocumentRoot    /home/mattcalkins/www/com_mattifesto_webserver3_mattifesto/document_root
        ErrorLog        /home/mattcalkins/www/com_mattifesto_webserver3_mattifesto/logs/error.log
        CustomLog       /home/mattcalkins/www/com_mattifesto_webserver3_mattifesto/logs/access.log combined
    
        SSLEngine               on
        SSLCertificateFile      /home/mattcalkins/.acme.sh/webserver3.mattifesto.com/webserver3.mattifesto.com.cer
        SSLCertificateKeyFile   /home/mattcalkins/.acme.sh/webserver3.mattifesto.com/webserver3.mattifesto.com.key
    
        <Directory "/home/mattcalkins/www/com_mattifesto_webserver3_mattifesto/document_root">
            AllowOverride   all
            Require         all granted
        </Directory>
    
    </VirtualHost>
    
  • $ sudo a2ensite com_mattifesto_webserver3_mattifesto

  • $ sudo apache2ctl configtest

  • $ sudo systemctl restart apache2

Set Up The Website

Option 1: If you are creating a fresh website instance:

  • On your workstation browser, navigate to:

    https://mattifesto.webserver3.mattifesto.com/colby/setup/

  • MySQL Host: localhost

  • MySQL Username: web

  • MySQL Password: <password>

  • MySQL Database: com_mattifesto_webserver3_mattifesto_database

  • Developer Email Address: Use the email address you want to use for your user account on this specific website.

  • Developer Password: Enter the password you want to use for this specific website.

  • Confirm Developer Password: re-enter password

The website will point out a few more steps you will want to take. You will also want to setup an email account so that email services can be used.

2021_04_10 There will be a settings.json file in the document root which should be deleted. There is an issue related to this and the process will be changed to delete this as part of the process.

Option 2: If you are copying another website instance:

On webserver3:

  • $ cd www/com_mattifesto_webserver3_mattifesto/document_root/

  • $ cp tmp/database-backups/<most recent backup file> tmp/database-backups/import.sql

  • $ vi tmp/database-backups/import.sql

  • :%s/<old_database_name>/com_mattifesto_webserver3_mattifesto_database/gc

    This moment is where it really helps if the database names are unique like we mentioned at the beginning of this document.

  • $ mysql -u web -p < tmp/database-backups/import.sql

  • $ vi colby-configuration.php

  • Manually update the constant values for for the new website.

  • On your workstation browser, navigate to:

    https://mattifesto.webserver3.mattifesto.com/admin/

    Your password is the same as it was for the copied site.

    Go to the update admin page for the website you are copying and click on the "Update Site" button to create the tables that aren't exported in database backups.