Last active
February 25, 2020 10:00
-
-
Save ashishkharcheiu/b728b10c91d78b6f183c2c5cdf16e5ad to your computer and use it in GitHub Desktop.
Revisions
-
ashishkharcheiu revised this gist
Feb 25, 2020 . 1 changed file with 180 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,175 @@ https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04 https://www.digitalocean.com/community/tutorials/how-to-install-the-django-web-framework-on-ubuntu-18-04 https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04 https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-18-04 https://www.digitalocean.com/community/tutorials/how-to-set-up-object-storage-with-django Prerequisites: - MobaXTerm - DigitalOcean Account Steps: - Create a Droplet [ubuntu, 5usd, enable backup, datacenter = Bangalore, authentication = one-time password (later we will enable ssh auth) - Copy IP address generated by DigitalOcean. - Check email send by DigitalOcean - Go to MobaXterm --> session --> ssh --> paste the IP address in "Remote host" field, username = root --> Click OK - Copy password from email --> paste in MobaXterm terminal after root@ipadress password: - Paste again the same password in [current] UNIX password - Enter new password - Close tab and reopen https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04 - after root@hostname:# --> adduser sammy - enter password - provide permissions --> usermod -aG sudo sammy - Open CMD --> ssh-keygen --> rename files to `sammy` in .ssh folder --> repeat same process for `root` user - Copy root.pub key --> in MobaXterm --> go to /root/.ssh/authorized_keys --> edit and paste - Copy mitch.pub key --> in MobaXterm --> go to /home/mitch/.ssh/authorized_keys --> edit and paste (might need to create .ssh and authorized_keys manually) - open CMD --> ssh sammy@ipaddress --> test login - open MobaXterm --> session --> ssh --> Remote host = ipadderss --> username = sammy --> advanced SSH settings --> enable "User private key" --> find/browser for sammy PUBLIC key --> Click OK - now under user sessions --> edit session for root ipaddress and repeat the above setp while selecting root PUBLIC key --> Click OK - in MobaXterm terminal after root@hostname: --> sudo nano /etc/ssh/sshd_config --> set "PasswordAuthentication" to no --> save the file and exit - sudo ufw app list - sudo ufw allow openssh - sudo ufw enable - sudo ufw status - sudo apt update - sudo apt install python3.7 - python3.7 --> to check shell --> exit() - sudo update -alternatives --install /usr/bin/python python /usr/bin/python3.6 2 - sudo update -alternatives --install /usr/bin/python python /usr/bin/python3.7 1 - sudo update-alternatives --config python - set selection to "python3.7" number - sudo apt-get install -y python3-pip - pip3 --> to check - sudo -H pip3 install virtualenv - cd /home/sammy - mkdir djangoprojectdir - cd djangoprojectdir [Inside /djangoprojectdir] - virtualenv djangoprojectenv - source djangoprojectenv/bin/activate - pip3 install gunicorn - pip3 install django==2.2.2 - cd .. [Inside /sammy] - django-admin startproject mysite djangoprojectdir - Edit settings.py --> ALLOWED_HOSTS = localhost, ipaddress --> add OUR apps to INSTALLED_APPS --> then add line AUTH_USER_MODEL = 'account.Account' --> TEMPLATES -> DIRS add os path --> COPY STATIC FILES CODE below from our local to settings.py - Drag all `app` [account, blog, personal, templates, requirements] folders from local to /djangoprojectdir in MobaXterm - Drag urls.py from local to MobaXterm and remove MEDIA root code from below - Create new dir "static" and drag logo from local "static" to MobaXterm "static" - cd djangoprojectdir [Inside /djangoprojectdir] - pip3 install -r requirements.txt - python manage.py makemigrations - python manage.py migrate - python manage.py collectstatic - sudo ufw allow 8000 - python manage.py runserver 0.0.0.0:8000 - Check ipaddress:8000 in browser - gunicorn --bind 0.0.0.0:8000 mysite.wsgi https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04 - deactivate [deactivates virtualenv] - pip3 install -r requirements.txt + pip3 install gunicorn - In MobaXterm sidebar FTP --> go to /etc/systemd/system --> create file 'gunicorn.socket' --> paste the code from digitalocean docs - In MobaXterm sidebar FTP --> go to /etc/systemd/system --> create file 'gunicorn.service' --> paste the code from digitalocean docs --> make appropriate changes --> "mysite.wssgi", user, dir, env... - sudo systemctl start gunicorn.socket - sudo systemctl enable gunicorn.socket - file /run/gunicorn.sock - sudo systemctl status gunicorn.socket [If error --> sudo shutdown -r now] - curl --unix-socket /run/gunicorn.sock localhost --> should get HTML file syntax [If change gunicorn service file --> either shutdown server by sudo shutdown -r now or do --> sudo systemctl daemon-reload --> sudo systemctl restart gunicorn.socket gunicorn.service] - sudo systemctl status gunicorn - sudo apt install nginx - go to /etc/nginx/sites-available --> create new file "djangoproject" --> paste digitalocean docs code --> add ipaddress and change "root" path - sudo ln -s /etc/nginx/sites-available/djangoproject /etc/nginx/sites-enabled - sudo nginx -t - sudo systemctl restart nginx - sudo ufw delete allow 8000 - sudo ufw allow 'Nginx Full' - Go to browser and paste ipaddress --> check - 2 --------------------------------------------------------------------------- - In DigitalOcean --> Create Domain/DNS --> enter domain 'hello.com' - In Hostname add "@" --> 3600 --> create record - In Hostname add "www" --> 3600 --> create record - Namecheap --> Manage --> add Nameservers --> ns1.digitalocean.com --> ns2 and ns3 - In MobaXterm --> settings.py --> add domain with and without "www" both to ALLOWED_HOSTS - service gunicorn restart - go to /etc/nginx/sites-available/djangoproject --> edit file djangoproject --> add domain name to server_name without comma seperation. Add both www and simple version domain name - sudo systemctl restart nginx - sudo systemctl status gunicorn.service - go to domain name eg. hello.com in incognito mode --> check [If error --> sudo shutdown -r now or /sites-available --> copy contents of 'default' file safely, delete the file and create again] - 3 --------------------------------------------------------------------------- https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-18-04 - sudo add-apt repository ppa:certbot/certbot - sudo apt install python-certbot-nginx - sudo nano /etc/nginx/sites-available/djangoproject - sudo ufw status - sudo certbot --nginx -d hello.com -d www.hello.com - enter email - choose 2 - sudo certbot renew --dry-run [If error --> sudo ufw allow https , sudo ufw delete allow '443/tcp' or check the number 442/443] - 4 --------------------------------------------------------------------------- https://www.digitalocean.com/community/tutorials/how-to-set-up-object-storage-with-django - In DigitalOcean --> Create Spaces --> datacenter --> restrict file listing --> hello-space --> create a space - Create New Folder in space named "hello-static" - Go to API section in left side bar --> Generate Key --> Name = hello-space-key --> Secure Secret and hello-static-key - In MobaXterm --> pip3 install boto3 --> pip3 install django-storages [Do in virtual env] - Delete static_cdn folder - In settings.py --> add storages to INSTALLED_APPS --> configure AWS keys and all below settings.py - cd /home/sammy/djangoprojectdir [Inside /djangoprojectdir] - source djangoprojectenv/bin/activate - pip3 install boto3 - pip3 install django-storages - python manage.py collectstatic - sudo nano /etc/nginx/sites-available/djangoproject --> change "root" to "alias" --> save - sudo shutdown -r now - wait 20 sec - relogin @@ -21,3 +192,11 @@ cd djangoprojectdir [If secret key of django in settings.ini has % then concatenate another "%%" - service gunicorn restart - 5 --------------------------------------------------------------------------- - Google Account --> myaccount.google.com --> security --> enable 2-Step verification --> Create App passwords --> other --> any name --> generate - Add email Backend code in settings.py and make relevant changes - service gunicorn restart -
ashishkharcheiu revised this gist
Feb 25, 2020 . 1 changed file with 13 additions and 142 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,152 +1,23 @@ --> change "root" to "alias" --> save - sudo shutdown -r now - wait 20 sec - relogin - python manage.py createsuperuser - cd .. [Inside /sammy] - chown sammy djangoprojectdir/ cd djangoprojectdir [Inside /djangoprojectdir] - chown sammy db.sqlite3 [If you are using sqlite3] - ls -l --> to check - pip3 install python-decouple - Create new file in /djangoprojectdir "settings.ini" --> make releveant changes - make appopriate changes in "settings.py" [If secret key of django in settings.ini has % then concatenate another "%%" - service gunicorn restart -
ashishkharcheiu revised this gist
Feb 25, 2020 . 1 changed file with 20 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,8 @@ https://www.digitalocean.com/community/tutorials/how-to-install-the-django-web-f https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04 https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-18-04 Prerequisites: - MobaXTerm - DigitalOcean Account @@ -130,3 +132,21 @@ https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postg [If error --> sudo shutdown -r now or /sites-available --> copy contents of 'default' file safely, delete the file and create again] - 3 --------------------------------------------------------------------------- https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-18-04 - sudo add-apt repository ppa:certbot/certbot - sudo apt install python-certbot-nginx - sudo nano /etc/nginx/sites-available/djangoproject - sudo ufw status - sudo certbot --nginx -d hello.com -d www.hello.com - enter email - choose 2 - sudo certbot renew --dry-run [If error --> sudo ufw allow https , sudo ufw delete allow '443/tcp' or check the number 442/443] -
ashishkharcheiu revised this gist
Feb 25, 2020 . 1 changed file with 18 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -111,4 +111,22 @@ https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postg - Go to browser and paste ipaddress --> check - 2 --------------------------------------------------------------------------- - In DigitalOcean --> Create Domain/DNS --> enter domain 'hello.com' - In Hostname add "@" --> 3600 --> create record - In Hostname add "www" --> 3600 --> create record - Namecheap --> Manage --> add Nameservers --> ns1.digitalocean.com --> ns2 and ns3 - In MobaXterm --> settings.py --> add domain with and without "www" both to ALLOWED_HOSTS - service gunicorn restart - go to /etc/nginx/sites-available/djangoproject --> edit file djangoproject --> add domain name to server_name without comma seperation. Add both www and simple version domain name - sudo systemctl restart nginx - sudo systemctl status gunicorn.service - go to domain name eg. hello.com in incognito mode --> check [If error --> sudo shutdown -r now or /sites-available --> copy contents of 'default' file safely, delete the file and create again] -
ashishkharcheiu created this gist
Feb 25, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,114 @@ https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04 https://www.digitalocean.com/community/tutorials/how-to-install-the-django-web-framework-on-ubuntu-18-04 https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04 Prerequisites: - MobaXTerm - DigitalOcean Account Steps: - Create a Droplet [ubuntu, 5usd, enable backup, datacenter = Bangalore, authentication = one-time password (later we will enable ssh auth) - Copy IP address generated by DigitalOcean. - Check email send by DigitalOcean - Go to MobaXterm --> session --> ssh --> paste the IP address in "Remote host" field, username = root --> Click OK - Copy password from email --> paste in MobaXterm terminal after root@ipadress password: - Paste again the same password in [current] UNIX password - Enter new password - Close tab and reopen https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04 - after root@hostname:# --> adduser sammy - enter password - provide permissions --> usermod -aG sudo sammy - Open CMD --> ssh-keygen --> rename files to `sammy` in .ssh folder --> repeat same process for `root` user - Copy root.pub key --> in MobaXterm --> go to /root/.ssh/authorized_keys --> edit and paste - Copy mitch.pub key --> in MobaXterm --> go to /home/mitch/.ssh/authorized_keys --> edit and paste (might need to create .ssh and authorized_keys manually) - open CMD --> ssh sammy@ipaddress --> test login - open MobaXterm --> session --> ssh --> Remote host = ipadderss --> username = sammy --> advanced SSH settings --> enable "User private key" --> find/browser for sammy PUBLIC key --> Click OK - now under user sessions --> edit session for root ipaddress and repeat the above setp while selecting root PUBLIC key --> Click OK - in MobaXterm terminal after root@hostname: --> sudo nano /etc/ssh/sshd_config --> set "PasswordAuthentication" to no --> save the file and exit - sudo ufw app list - sudo ufw allow openssh - sudo ufw enable - sudo ufw status - sudo apt update - sudo apt install python3.7 - python3.7 --> to check shell --> exit() - sudo update -alternatives --install /usr/bin/python python /usr/bin/python3.6 2 - sudo update -alternatives --install /usr/bin/python python /usr/bin/python3.7 1 - sudo update-alternatives --config python - set selection to "python3.7" number - sudo apt-get install -y python3-pip - pip3 --> to check - sudo -H pip3 install virtualenv - cd /home/sammy - mkdir djangoprojectdir - cd djangoprojectdir [Inside /djangoprojectdir] - virtualenv djangoprojectenv - source djangoprojectenv/bin/activate - pip3 install gunicorn - pip3 install django==2.2.2 - cd .. [Inside /sammy] - django-admin startproject mysite djangoprojectdir - Edit settings.py --> ALLOWED_HOSTS = localhost, ipaddress --> add OUR apps to INSTALLED_APPS --> then add line AUTH_USER_MODEL = 'account.Account' --> TEMPLATES -> DIRS add os path --> COPY STATIC FILES CODE below from our local to settings.py - Drag all `app` [account, blog, personal, templates, requirements] folders from local to /djangoprojectdir in MobaXterm - Drag urls.py from local to MobaXterm and remove MEDIA root code from below - Create new dir "static" and drag logo from local "static" to MobaXterm "static" - cd djangoprojectdir [Inside /djangoprojectdir] - pip3 install -r requirements.txt - python manage.py makemigrations - python manage.py migrate - python manage.py collectstatic - sudo ufw allow 8000 - python manage.py runserver 0.0.0.0:8000 - Check ipaddress:8000 in browser - gunicorn --bind 0.0.0.0:8000 mysite.wsgi https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04 - deactivate [deactivates virtualenv] - pip3 install -r requirements.txt + pip3 install gunicorn - In MobaXterm sidebar FTP --> go to /etc/systemd/system --> create file 'gunicorn.socket' --> paste the code from digitalocean docs - In MobaXterm sidebar FTP --> go to /etc/systemd/system --> create file 'gunicorn.service' --> paste the code from digitalocean docs --> make appropriate changes --> "mysite.wssgi", user, dir, env... - sudo systemctl start gunicorn.socket - sudo systemctl enable gunicorn.socket - file /run/gunicorn.sock - sudo systemctl status gunicorn.socket [If error --> sudo shutdown -r now] - curl --unix-socket /run/gunicorn.sock localhost --> should get HTML file syntax [If change gunicorn service file --> either shutdown server by sudo shutdown -r now or do --> sudo systemctl daemon-reload --> sudo systemctl restart gunicorn.socket gunicorn.service] - sudo systemctl status gunicorn - sudo apt install nginx - go to /etc/nginx/sites-available --> create new file "djangoproject" --> paste digitalocean docs code --> add ipaddress and change "root" path - sudo ln -s /etc/nginx/sites-available/djangoproject /etc/nginx/sites-enabled - sudo nginx -t - sudo systemctl restart nginx - sudo ufw delete allow 8000 - sudo ufw allow 'Nginx Full' - Go to browser and paste ipaddress --> check