| DJC | Django | Production Deployment |
Django Deployment on Heroku, AWS, and DigitalOcean - DJC
Deployment on Heroku
Initial Setup
-
Create a new project on Heroku:
-
Create an app on Heroku and select a database (PostgreSQL is recommended).
-
Install Heroku CLI:
-
Make sure
heroku-cli
is installed and authenticated on your local machine.
Environment Preparation
-
Create a
Procfile
: -
This file tells Heroku how to run your application:
web: gunicorn project_name.wsgi
-
Install dependencies:
-
Include Gunicorn and any other dependencies in your
requirements.txt
.
Deployment
- Use the following command to deploy your application:
git push heroku main
- After deployment, run database migrations:
heroku run python manage.py migrate
Deployment on AWS
Elastic Beanstalk Setup
-
Create a new application:
-
Log in to the AWS Management Console and create a new Elastic Beanstalk application.
-
Choose the platform:
-
Select the Python platform and configure your instances according to your needs.
Database Configuration
- Use Amazon RDS to manage the database. Be sure to choose PostgreSQL or MySQL and configure it properly.
Deployment
- Use the AWS CLI to package and deploy your application:
eb create your_environment_name
- Once the environment is created, run migrations if needed:
eb ssh
python manage.py migrate
Deployment on DigitalOcean
Droplet Setup
-
Create a new Droplet:
-
Choose an Ubuntu image and make sure it has internet access.
Installing Dependencies
- Connect to the server and run the following commands to install Gunicorn and Nginx:
sudo apt update
sudo apt install nginx
sudo apt install python3-gunicorn
Deployment
- Upload your code to the server using Git or SCP and configure Gunicorn and Nginx to serve your application.
| DJC | Django | Production Deployment |