Setting up your server
Important: Please ensure you have SSH access to your server before proceeding.
- Basics
- sudo apt update (To ensure your server is up to date with the latest version of Python)
- sudo apt install python3-venv python3-dev libpq-dev postgresql postgresql-contrib nginx curl
- sudo apt install supervisor
- Note: Enter Y for any prompts that appear as the server installs updates and packages.
- Setup the Database
- Once the above commands have been executed Run the following: sudo -u postgres psql
- Create a Database for your project with the following command: CREATE DATABASE myproject;
- Create a database user for the app: CREATE USER myprojectuser WITH PASSWORD 'password';
- Execute the following commands:
-
ALTER ROLE myprojectuser SET client_encoding TO 'utf8';
ALTER ROLE myprojectuser SET default_transaction_isolation TO 'read committed';
ALTER ROLE myprojectuser SET timezone TO 'UTC'; - GRANT ALL PRIVILEGES ON DATABASE myproject TO myprojectuser;
- Database Setup complete, execute the following command to exit postgresql: \q
- Configure the Web Server
- Using SSH type: sudo nano /etc/systemd/system/gunicorn.socket
- Copy the lines from the below file and paste them into your SSH editor
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target
- Next Type: sudo nano /etc/systemd/system/gunicorn.service
- Copy the lines from the below file and paste them into your SSH editor
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/home/eventapp/event-platform
ExecStart=/home/eventapp/eventenv/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
app.wsgi:application
[Install]
WantedBy=multi-user.target
- Configuring NGINX
- Execute the following command: sudo nano /etc/nginx/sites-available/eventapp
- Copy the lines from the below file and paste them into your SSH editor
- Note: Change the domain name to your own unser server_name
server {
listen 80;
server_name yourdomaingoeshere.com;
client_max_body_size 120M;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/eventapp/event-platform;
}
location /media/ {
root /home/eventapp/event-platform;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
- Save and exit the editor
- Enter the following command: ln -s /etc/nginx/sites-available/eventapp /etc/nginx/sites-enabled/eventapp
- Lastly, type: service nginx restart