Created
May 25, 2021 17:36
-
-
Save rana01645/b14c6d3b9571779313911eab9a43040b to your computer and use it in GitHub Desktop.
Install django on Ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04 | |
#install necessary libs | |
sudo apt update | |
sudo apt install python3-pip python3-dev libpq-dev nginx curl | |
#install mysql | |
sudo apt install mysql-server | |
sudo apt-get install libmysqlclient-dev | |
#install python3 pip | |
sudo apt install python3-pip | |
#install v-env | |
sudo -H pip3 install --upgrade pip | |
sudo -H pip3 install virtualenv | |
mkdir ~/stackerproject | |
cd ~/stackerproject | |
#create env | |
virtualenv stackerenv | |
source stackerenv/bin/activate | |
#install django under environment | |
pip3 install django gunicorn psycopg2-binary | |
//download project from git | |
git clone https://github.com/NasirNobin/YiveStacker.git | |
#cd to project | |
cd YiveStacker | |
#installing requirements | |
pip3 install requirements.txt | |
#----------------------------- | |
#change settings.py as necessary ignoring here | |
#----------------------------- | |
#allowing speciific port for the project | |
sudo ufw allow 4321 | |
#deactivate from django env | |
deactivate | |
#write gunicorn.socket | |
echo '[Unit] | |
Description=gunicorn socket | |
[Socket] | |
ListenStream=/run/gunicorn.sock | |
[Install] | |
WantedBy=sockets.target' > /etc/systemd/system/gunicorn.socket | |
//setup gunicorn service | |
echo '[Unit] | |
Description=gunicorn daemon | |
Requires=gunicorn.socket | |
After=network.target | |
[Service] | |
User=stacker | |
Group=www-data | |
WorkingDirectory=/home/stacker/stackerproject | |
ExecStart=/home/stacker/stackerproject/stackerenv/bin/gunicorn \ | |
--access-logfile - \ | |
--workers 3 \ | |
--bind unix:/run/gunicorn.sock \ | |
--chdir /home/stacker/stackerproject/YiveStacker/RestAPI RestAPI.wsgi:application | |
[Install] | |
WantedBy=multi-user.target' > /etc/systemd/system/gunicorn.service | |
#restart gunicorn | |
sudo systemctl start gunicorn.socket | |
sudo systemctl enable gunicorn.socket | |
//nginx | |
echo 'server { | |
listen 4321; | |
server_name 79.143.190.147; | |
location = /favicon.ico { access_log off; log_not_found off; } | |
location /static/ { | |
root /home/stacker/stackerproject; | |
} | |
location / { | |
include proxy_params; | |
proxy_pass http://unix:/run/gunicorn.sock; | |
} | |
}' >> /etc/nginx/sites-available/stackerproject | |
sudo ln -s /etc/nginx/sites-available/stackerproject /etc/nginx/sites-enabled | |
sudo systemctl restart nginx | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment