In this lab, we will be setting up a virtual computer that we will use for the rest of the labs in this course.
A virtual computer is where we run an isolated operating system, with it’s own storage on an already running host. There are many advantages to this including being able to run many ‘computers’ on a single piece of hardware, the ability to easily duplicate or move a system without access to the physical hardware, and security.
Our virtual machine will run Debian Linux, the same operating system that is used on the lab computers, some of the reasons why you may choose Linux for running your own GIS server is that it is Free (As in Free Speech, and Free Beer) you can customize it however you like and do not need to worry about licensing fees. Linux generally uses fewer system resources than other desktop operating systems, so we can run more virtual machines and still have RAM & CPU for GIS processing. And finally, Linux is generally considered to be very stable and secure, over 2/3’s of the internet run on Linux.
Configuring the Virtual Machine
We will start by logging into a physical machine in the GIS Lab to build our virtual machine. Check your e-mail to see which desktop you have been assigned for the course. First, connect to the VPN (https://vpn.unbc.ca), and then use the remote desktop software available on your computer
- Windows – https://docs.microsoft.com/en-us/windows-server/remote/remote-desktop-services/clients/windowsdesktop
- Linux – https://remmina.org/how-to-install-remmina/
- Mac – https://docs.microsoft.com/en-us/windows-server/remote/remote-desktop-services/clients/remote-desktop-mac
Once you are connected to the desktop open virtual box
//Add path to debian iso
Installing an Operating System
Set username and password
- Desktop Environment
- Web Server
- Standard System Utilities
Installing components on our virtual computer requires us to work as the root user, this can be done in two ways.
1st: Simply log in as root with the password set at install.
2nd: Use the sudo command (Super User Do), by adding sudo in front of a command you tell the computer to execute it as the root user. Before you can use sudo you need to add yourself to the sudo group.
- Log in as root
- Open terminal
- Type command “sudo usermod -aG sudo <username>”
- Log in as yourself and you should be able to use sudo command
Update and Install Packages
Before we can start programming we need to install some tools on our computer, and to do that we are going to use the package managers apt and gdebi
To update the list of software we can install on the system run
>sudo apt update
If you get a message saying some of your packages are out of date you can update all the software on your computer by typing
sudo apt upgrade
The first program we are going to install is gdebi, gdebi is a tool that allows us to install debian files downloaded from places other than the repository, the same as you would a .EXE for windows or .DMG for Mac.
sudo apt install gdebi
Lets try this by installing Visual Studio Code which is a text editor we will be using in later labs, download the .deb file from here https://code.visualstudio.com/download
sudo gdebi code_1.41.1-1576681836_amd64.deb (Your version will be different)
This command has installed Visual studio code, and added an entry in our sources list that will allow apt to perform future updates you can take a look at the file here:
sudo gedit /etc/apt/sources.list.d/vscode.list
The next software we are going to install requires manually adding repositories first we will install QGIS (https://qgis.org/en/site/forusers/alldownloads.html#debian-ubuntu)
We will create a new file in gedit called qgis.list
sudo gedit /etc/apt/sources.list.d/qgis.list
Add the following two lines to the file, then save and close it
deb https://qgis.org/debian buster main deb-src https://qgis.org/debian buster main
In the list file we have a URL to get the software, a codename to indicate which operating system we are using, in this case buster as that is the code name for Debian 10, and then main is the release channel, many software packages allow other options such as unstable, testing, or nightly to allow users to download newer but potentially buggy software.
For those curious about the naming convention here is an old poster that goes up to version 9. https://i.stack.imgur.com/wK5eM.jpg
But there is one more step before we can install qgis, we need to build trust with qgis.org that it is not giving us malicious software, to do this we will add the GPG key from the ubuntu key server, apt will then only install software from qgis if it is signed with the matching private key.
>sudo apt-key adv –keyserver keyserver.ubuntu.com –recv-key 51F523511C7028C3
Now lets install QGIS and QGIS server
sudo apt install qgis qgis-server
The last piece of software we need to install is PostgreSQL and PostGIS the repositories can be found at this link https://www.postgresql.org/download/linux/debian/ add the repositories and then install these 3 packages postgresql postgis pgadmin4.
Install the package named ‘seahorse’ this will allow us to store passwords for safe use later on.
By default Postgre uses ‘peer’ authentication meaning it allows users on the local machine to access the database without credentials. Later in the course we will be accessing our freshly installed database from webservers and GIS applications that will be connecting with a username and password.
sudo -u postgres psql
Read this line as sudo (supper user do), -u (act on behalf of another user) postgres (the user we are acting as) psql (open the postgresql software).
Use the following line of code to update the password, NOTE: This password will end up in plain text files before the end of this class, do not use a password you use for anything else! But worry not you don’t need to remember this password, generate a password from this URL (https://passwordsgenerator.net/?length=24&symbols=1&numbers=1&lowercase=1&uppercase=1&similar=0&ambiguous=1&client=1&autoselect=1), and copy and paste the password.
ALTER USER postgres PASSWORD 'myPassword'; \q;
to save the password for later open sea horse
Finally we need to configure Postgres for password access this is done by changing the hba configuration.
*As we are using modern versions of Postgres this may already be set but lets take a look anyways.
sudo nano /etc/postgresql/12/main/pg_hba.conf
The bottom of your file should look something like this
File >>> New >>> Stored Password, and continue
Give the password a description so you can find it later, and paste in the the box, press OK to save.
If you need to look up this password again, simply open seahorse and find it in the list.
Let’s discuss what this lines mean.
How might you change this file to allow a remote user access to your database?
Set up development environment
Sign up for a JetBrains education acount using your UNBC email herehttps://www.jetbrains.com/shop/eform/students
Once you are set up download the tool box app from https://www.jetbrains.com/toolbox-app/
We will use the toolbox to install the following programs: PyCharm Professional, PHPStorm, WebStorm, and DataGrip.