- Notifications
You must be signed in to change notification settings - Fork24
This tutorial series is all about deploying a Python web application on Ubuntu 18.04 LTS.
License
codingforentrepreneurs/Hello-Linux
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This series is all about deploying a Python web application on Ubuntu 18.04 LTS.
You can spin up a virtual machine with Ubuntu at a variety of places:
Google Cloud Compute Engine (https://cloud.google.com/compute/)
Amazon Web Services EC2 (https://aws.amazon.com/ec2/)
We'll be using Digital Ocean since it's really easy to get started. What you'll learn here can also be applied to deploying Python projects on any Ubuntu server. In some cases, this setup will work with other Linux distributions too albeit different methods of installation (ie not usingapt-get).
Here's the plan:
- Launch a virtual machine (droplet) withDigital Ocean
- Access our droplet via SSH
- Install Updates & Dependancies via bash script which ishere
- Configure & Implement:
- Git (for push, build, & deploy) [docs]
- Supervisor (process manager) [docs]
- Nginx (web server / load balancer) [docs]
- Redis (task queue datastore / message broker) [docs]
- Celery (worker / task queues) [docs]
- Gunicorn (WSGI web server for python) [docs]
- PostgreSQL (database) [docs]
- Django (Python web framework) [docs]
- Let's Encrypt for HTTPs Certificates
After you run the below command, you'll see an endpoint to add to your local git remote.
wget https://raw.githubusercontent.com/codingforentrepreneurs/Hello-Linux/master/setup.shchmod +x setup.sh./setup.sh
We'll be using a bare bones Django project that's mostly ready for production. It's just an example but an important one to get this working.
Go tothis guide to get started.
To create a PostgreSQL database,it's recommended to usesetup.sh on Server.
Another option is to run:
# enable current logged in user as a default user for postgressudo -u postgres createuser$USERsudo -u postgres psql --command="CREATE DATABASE${projectDB};"sudo -u postgres psql --command="CREATE USER${projectDBuser} WITH PASSWORD '${newPassword}';"sudo -u postgres psql --command="ALTER ROLE${projectDBuser} SET client_encoding TO 'utf8';"sudo -u postgres psql --command="ALTER ROLE${projectDBuser} SET default_transaction_isolation TO 'read committed';"sudo -u postgres psql --command="ALTER ROLE${projectDBuser} SET timezone TO 'UTC';"sudo -u postgres psql --command="GRANT ALL PRIVILEGES ON DATABASE${projectDB} TO${projectDBuser};"
Be sure to replace${projectDB},${projectDBuser}, and${newPassword} to the values you want to use. The setup script does this automatically.
DATABASES= {'default': {'ENGINE':'django.db.backends.sqlite3','NAME':os.path.join(BASE_DIR,'db.sqlite3'), }}DATABASES= {'default': {'ENGINE':'django.db.backends.postgresql','NAME':'${projectDB}','USER':'${projectDBuser}','PASSWORD':'{newPassword}','HOST':'localhost','PORT':'', }}
$cd path/to/django/proj$ pipenv shell(venv) $ pipenv install psycopg2-binary# you might need this(venv) $ python manage.py migrate
Our example
$cd /var/www/hello_linux/src/$ pipenv shell(src) $ python manage.py migrateAbout
This tutorial series is all about deploying a Python web application on Ubuntu 18.04 LTS.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.