Create A Local Network Development Website (Ubuntu 21.04)

You must have a local network development VirtualBox web server created before you start this process. The local network development web server in this example has a public domain name of:

ld4.mtfs.us

The domain for the development website in this example is:

devs.ld4.mtfs.us

Your website domain should have a DNS CNAME record that points to the main web server domain.

Create Website Directory

Website directories exist inside a "www" directory that is in your home directory on your development workstation that is running the Ubuntu virtual machine that is running one or more web servers that will host the development websites.

In this document that workstation is a Mac. My www directory is "/Users/mattcalkins/www".

  • Start the Terminal app

  • $ cd ~/www

  • $ curl -s https://mattifesto.com/install/ > install.php && php install.php

Option: Create a brand new website

  • choose option 0

  • enter your website domain

Option: Create a website using an existing Git repository

  • choose option 1

  • enter your website domain

  • enter the https Git URL for your website repository

Option: If you are copying another website instance:

  • choose option 2

  • Go to the update admin page for the website you are copying and click on the "Backup Database" button. We will import this backup into the database for this site later.

  • $ cp -r ../copied_website_document_root document_root

Create Database On Web Server

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_webserver4_devs_database" because naming it "devs" or even "devs_mattifesto" would create a name overlap in many places.

  • $ ssh ld4

  • $ sudo mysql

  • mysql> create database <database>;

  • mysql> create user <username>@localhost identified with mysql_native_password BY '<password>';

  • mysql> grant all on <database>.* to <username>@localhost;

  • mysql> flush privileges;

  • mysql> exit;

  • $ mysql -u <username> -p

  • mysql> show databases;

  • mysql> exit;

Share The Website Folder With The Web Server

First Time Setup

I keep all my website folders inside of a "www" directory which is in the "mattcalkins" user directory. We will be sharing the folders through VirtualBox into that directory.

You must create the "www" directory on the web server as your user before sharing the first directory via VirtualBox because VirtualBox will make the directory owned by root if it has to create it.

$ mkdir www

Your user also needs to belong to the group "vboxsf" to be able to view the shared directory.

First see what groups your user currently belongs to:

$ groups

If the list does not include "vboxsf" then:

$ usermod -a -G vboxsf mattcalkins

If you had to add your user to the group you must log out and then log back in again.

Share Directory

  • Open the VirtualBox Manager window.

  • Select the web server virtual machine.

  • Click the "Settings" button in the toolbar.

  • Click the "Shared Folders" button in the toolbar.

  • Click the small folder icon with a green plus on the right side of the panel.

  • Folder Path:
    Select the com_mattifesto_webserver4_devs folder you just created.

  • Check the "Auto-mount" check box.

  • Mount Point:
    /home/mattcalkins/www/com_mattifesto_webserver4_devs

  • Check the "Make Permanent" check box.

  • Click the "OK" button.

  • Click the "OK" button.

  • Verify the the shared folder is present on the web server.

Create Virtual Host On Web Server

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

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

    $ sudo apache2ctl configtest

    $ sudo systemctl reload apache2

    Set Up The Website

    Option: Create a brand new website

    Option: Create a website using an existing Git repository

    • On your workstation browser, navigate to:

      https://devs.ld4.mtfs.us/colby/setup/

    • MySQL Host: localhost

    • MySQL Username: <username>

    • MySQL Password: <password>

    • MySQL Database: us_mtfs_ld4_devs_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.

    Option 2: If you are copying another website instance:

    On ld4:

    • $ cd www/us_mtfs_ld4_devs/document_root/

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

    • $ vi import.sql

    • :%s/<old_database_name>/us_mtfs_ld4_devs_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 <username> -p < import.sql

    • $ vi colby-configuration.php

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

    • On your workstation browser, navigate to:

      https://devs.ld4.mtfs.us/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.