LINUX COMMAND: sudo apt-getupdate && sudo apt-get upgrade-y
-
Navigate to /etc/netplan/
-
Create a file name “01-netcfg.yaml”
LINUX COMMAND: sudo nano 01-netcfg.yaml
NOTE: nano is a text editor and can be swapped with other text editors such as vi or vim4.
-
Depending on how the static network needs to be setup, there is a variety of variables that can be configured. A good resource for learning what needs to be set can be found on the official website at netplan.io.
-
Save the file once completed and apply the settings.
LINUX COMMAND: sudo netplan apply
NOTE: Ubuntu Server 18.04.1 removed most of the repositories from the “sources.list” file. You will need to modify the file to include a fuller list of repositories and save the file.
LINUX COMMAND: sudo apt-get install -y nginx supervisor postgresql postgresql-contrib postgresql-server-dev-10 libpq-dev python3-dev libxml2-dev libxslt1-dev zlib1g-dev python3-pip python-pip
-
Install virtualenvwrapper using the command below.
LINUX COMMAND: sudo pip install virtualenvwrapper
NOTE: This should install it in the “/usr/local/bin/” directory. If you don’t use sudo it will install elsewhere.
-
Create a directory for the virtual environments under your home directory.
LINUX COMMAND: mkdir ~/envs
-
Create a document name “.bash_aliases” under your home directory .
LINUX COMMAND: nano ~/.bash_aliases
-
Enter the below info into the text editor and then save.
export WORKON_HOME=~/envs source /usr/local/bin/virtualenvwrapper.sh
-
Run the bash script using the command below.
LINUX COMMAND: source ~/.bash_aliases
-
Install virtualenv using the command below.
LINUX COMMAND: pip install vitrualenv
-
Create a virtualenv in your “envs” folder under you home directory.
LINUX COMMAND: mkvirtualenv ~/envs/<virtualenv_name>
-
Test to make sure that it was successful by using the command below.
LINUX COMMAND: workon <virtualenv_name>
-
Exit the virtualenv using the command below.
LINUX COMMAND: deactivate
-
Log into Gitlab, go to profile settings, click the key that says “SSH Keys”, and click “generate one” link.
-
Copy the code at the top and paste it into the terminal. Follow the prompts to leave the directory the same and do not set a passphrase.
-
Enter the command below and copy the whole key.
LINUX COMMAND: cat ~/.ssh/id_rsa.pub
-
Navigate back one page on Gitlab and paste the code into the “Key” section, change the “Title” to something that will make identifying the key in the future easy ,and click “Add Key”
-
Navigate to the project you want to add to the server and copy the “SSH” code.
-
In the terminal create a directory under your home directory.
LINUX COMMAND: mkdir ~/<project folder name>
-
In the terminal navigate to the new directory you just created then paste the “SSH” code from Gitlab after the command below.
LINUX COMMAND: git clone <ssh link to project>
-
Navigate to the “requirements.txt” in the project folder and then run the code below.
LINUX COMMAND: pip install -r requirements.txt
-
Create a copy of the settings file and modify the allowed hosts, the database section to match the database settings, and the static root location.
-
Navigate to “~/envs/<env_name/bin/” and edit “postactivate.py”, then save.
LINUX COMMAND: export DJANGO_SETTINGS_MODULE=’<project_name>.settings.<settings_name>
-
Navigate to “~/envs/<env_name/bin/” and edit “postdeactivate.py”, then save.
LINUX COMMAND: unset DJANGO_SETTINGS_MODULE
-
Login to Postgres using the command below.
LINUX COMMAND: sudo -u postgres psql
-
Create an empty database using the code below.
POSTGRES COMMAND: CREATE DATABASE projectname;
-
Create a database user using the code below.
POSTGRES COMMAND: CREATE USER username WITH PASSWORD ‘password’;
-
Configure the database using the code below.
POSTGRES COMMAND: ALTER ROLE username SET client_encoding TO 'utf8'; POSTGRES COMMAND: ALTER ROLE username SET default_transaction_isolation TO 'read committed'; POSTGRES COMMAND: ALTER ROLE username SET timezone TO 'UTC';
-
Grant all privileges to the database for the user.
POSTGRES COMMAND: GRANT ALL PRIVILEGES ON DATABASE projectname TO username;
-
Login to the project virtualenv and migrate to Postgres.
NOTE: check your project root directory to see if dblite3 file was created, if so the migration to Postgres didn’t work and you’ll need to delete that file and start over.
-
While logged into the project virtualenv create a super user, and test database.
PYTHON COMMAND: python manage.py createsuperuser
-
Check to see if your super user was created and the database is working.
PYTHON COMMAND: python manage.py runserver 0.0.0.0:8000
-
Switch to your virtualenv using the command below.
LINUX COMMAND: workon <virtualenv name>
-
Enter the command below.
LINUX COMMAND: pip install gunicorn
-
Test that the Gunicorn server is running with the command below.
LINUX COMMAND: gunicorn --bind 127.0.0.1:8000 calib_site.wsgi:application
NOTE: Bind to the address in the gunicorn config.
-
Create a folder in the home directory using the command below.
LINUX COMMAND: mkdir ~/supervisor_confs
-
Navigate to “/etc/supervisor/supervisord.conf” and add the config details below next to the other include location and then save the file.
CONFIG: /home/<user name>/supervisor_confs/*.conf
NOTE: Make sure to add a space between the included directories.
-
Navigate to the project’s “conf” folder, make a copy of one of the conf files for the supervisor, move the file to the newly created “supervisor_confs” directory, and modify as needed.
-
Create a folder in the home directory using the command below.
LINUX COMMAND: mkdir ~/nginx_confs
-
Navigate to “/etc/nginx/nginx.conf” and add the config details below next to the other include location and then save the file.
CONFIG: /home/<user name>/nginx_confs/*.conf
NOTE: Make sure to add a space between the included directories.
-
Navigate to the project’s “conf” folder, make a copy of one of the conf files for nginx, move the file to the newly created “nginx_confs” directory, and modify as needed.
-
Navigate to “~/projects/<project_name>/bin/<install_file>”, then copy and modify the install file to mock the project directory. Then run the file using the command below.
LINUX COMMAND: source <install_file>
-
From the same directory as above, copy and modify the “runserver” to mock the project directory. Then run the file using the command below.
LINUX COMMAND: source <runserver>