In this tutorial, I'll walk you through deploying your Django web application hosted on GitHub to an AWS Lightsail instance using the Bitnami Django stack. Bitnami simplifies deployment by providing a pre-configured, production-ready environment that includes Django, web server (Nginx or Apache), and a database (PostgreSQL or MySQL).
By the end of this tutorial, you’ll have your Django project from GitHub up and running on AWS Lightsail with minimal configuration.
AWS Lightsail is an easy-to-use and affordable cloud service, ideal for hosting Django apps. It provides virtual private servers (instances) with simple management features like static IPs, pre-configured stacks, and predictable pricing. Here's why it's a great choice for Django:
Log in to AWS Lightsail:
Create a New Instance:
Once your Lightsail instance is running, you’ll need to SSH into it.
Obtain the Static IP:
SSH into the Instance:
ssh -i /path/to/your/ssh-key.pem bitnami@<your_instance_ip>
Now that you're connected to your Lightsail instance, you can clone your Django project from GitHub.
Install Git:
First, ensure that Git is installed on your Lightsail instance:
sudo apt update sudo apt install git
Clone Your GitHub Repository:
Now, navigate to the directory where you want to store your project (e.g., /home/bitnami/) and clone your repository:
cd /home/bitnami git clone https://github.com/yourusername/your-django-app.git
Replace https://github.com/yourusername/your-django-app.git with the actual URL of your GitHub repository.
Once you’ve cloned your Django project, you need to configure the settings.py file to ensure it works in the production environment.
Access the Django Application:
cd /home/bitnami/your-django-app
Edit the settings.py File:
Use a text editor like nano or vi to modify your settings.py:
sudo nano your-django-app/yourproject/settings.py
Change the following settings:
ALLOWED_HOSTS = ['<your_instance_ip>', 'yourdomain.com']
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'bitnami_django', 'USER': 'bn_django', 'PASSWORD': 'yourpassword', 'HOST': 'localhost', 'PORT': '5432', } }
STATIC_URL = '/static/' STATIC_ROOT = '/home/bitnami/your-django-app/static'
After configuring your settings, run migrations and collect static files.
Run Django Migrations:
Apply any database migrations:
sudo python3 manage.py migrate
Collect Static Files:
Run the following command to collect all static files into a central location:
ssh -i /path/to/your/ssh-key.pem bitnami@<your_instance_ip>
Once you’ve completed the above setup, your Django application should be accessible via your Lightsail instance’s static IP.
sudo apt update sudo apt install git
You should see the Django welcome page or your application if you already have code deployed.
Clone my Simple To-Do List Django App and follow these steps to deploy it on AWS Lightsail.
You’ve successfully deployed your Django application from GitHub on AWS Lightsail using the Bitnami Django stack. With this setup, you have:
AWS Lightsail with Bitnami provides a simple, cost-effective solution for hosting Django applications. Whether you're deploying a small personal project or a production application, this solution ensures that your Django application runs smoothly.
The above is the detailed content of Deploy a Django App from GitHub on AWS Lightsail Using the Bitnami Django Stack. For more information, please follow other related articles on the PHP Chinese website!