Local Enviornment Setup
Prerequisities & Required Packages
First, install python, pip, and git on your system.
- Python is the programming language used for Django, the web framework used by Go.
- 'Pip' is the python package manager.
- Git is the version control system used for SRCT projects.
Open a terminal and run the following command:
$ sudo apt update
$ sudo apt install python3 python3-dev python3-pip
Install these packages from the standard repositories:
$ sudo apt install libldap2-dev mysql-server mysql-client libmysqlclient-dev python-mysqldb libsasl2-dev libjpeg-dev
If prompted to install additional required packages, install those as well.
When prompted to set your mysql password, it's advisable to set it as the same as your normal superuser password.
First, install Homebrew if you haven't already by running the following command in your terminal:
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Next, install Python and MySQL:
$ brew install python mysql
Download the latest Python 3 for Windows installer here: https://www.python.org/downloads/windows/ Select the "Windows x86-64 executable installer" option.
Download the MySQL installer here: https://dev.mysql.com/downloads/installer/
NOTE For Windows users, replace
python in all following commands.
The Virtual Environment
Virtual environments are used to keep separate project packages from the main computer, so you can use different versions of packages across different projects and ease deployment server setup.
$ pip3 install virtualenv
to install virtualenv system-wide.
Then in your Go directory run:
$ virtualenv -p python3 .venv
to create your virtual environment in the
Activate it by typing:
$ source .venv/bin/activate (Linux/Mac) or
If you ever need to exit your virtual environment, simply run:
Now, the packages you need to install for Go are in in the top level of the project's directory structure(go/).
$ pip3 install -r requirements.txt
to install all of the packages needed for the project.
Go is configured for use with a mysql database.
Load up the mysql shell by running
$ mysql -u root -p
and putting in your mysql password.
Create the database by running:
> CREATE DATABASE go;
You can choose a different name for your database if you desire.
Double check your database was created by running:
> SHOW DATABASES;
Though you can use an existing user to access this database, here's how to create a new user and give them the necessary permissions to your newly created database:
> CREATE USER 'go'@'localhost' IDENTIFIED WITH mysql_native_password BY 'go';
Run to give the
go user permission to the
> GRANT ALL ON go.* TO 'go'@'localhost';
This allows your database user to create all the tables it needs on the Go database. (Each model in each app's models.py is a separate table, and each attribute a column, and each instance a row.)
> GRANT ALL ON test_go.* TO 'go'@'localhost'; FLUSH PRIVILEGES;
When running test cases, django creates a test database so your 'real' database doesn't get screwed up. This database is called 'test_' + whatever your normal database is named. Note that for permissions it doesn't matter that this database hasn't yet been created.
The .* is to grant access all tables in the database, and 'flush privileges' reloads privileges to ensure that your user is ready to go.
Exit the mysql shell by typing:
Change directory into go/go/ and run:
$ python3 manage.py makemigrations
to create the tables and rows and columns for your database. This command generates sql code based on your database models.
$ python3 manage.py migrate
to execute that sql code and set up your database. Migrations also track how you've changed your models over the life of your database, which allows you to make changes to your tables without screwing up existing information.
$ python3 manage.py createsuperuser
to create an admin account, using the same username and email as you'll access through CAS. This means your 'full' email address, for instance email@example.com. Your password will be handled through CAS, so you can just use 'password' here.
(If you accidentally skip this step, you can run python manage.py shell and edit your user from there. Select your user, and set .is_staff and .is_superuser to True, then save.)
Finally, within 'go/go' run:
$ python3 manage.py runserver
to start the site. Open your preferred web browser and navigate to 127.0.0.1:8000/ to see the site!