By laviscoacc
I have followed the Django droplet creation steps and create a droplet successfully. Now, I want to put my Django project, that is on Github, live instead of that dummy project that is created on my droplet. I don’t know how to do it. Can anyone guide me how to do this ?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Accepted Answer
ssh to your droplet
connect ssh to github
```ls -la``
[before] root root .ssh Here .ssh is under the root so as the user (let’s say user1) you don’t have Permission
run
sudo chown -R user1:user1 /home/user1
chown is change owner -R is recursive change anything in home user1 change everything in /home/user1 to user1:user1
```ls -la``
[after] user1 user1 .ssh
check github of how on create a ssh key
cat .ssh/id_rsa_github.pub
copy and past to github
ssh-add /home/uers1/.ssh/id_rsa_github
If you got Could not open a connection to your authentication agent run
eval `ssh-agent -s` => to activate the ssh agent
If you got @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ run
sudo chmod 400 id_rsa_github
finally
git clone git@github.com:name/xxx-xxx.git
Heya,
Putting your Django project from GitHub onto your DigitalOcean Droplet in place of the existing dummy project involves several steps. You’ll need to clone your project from GitHub, configure it, and ensure it’s properly served by the web server. Here’s a step-by-step guide:
First, you need to SSH into your Droplet. Open a terminal and use the following command:
ssh username@your_droplet_ip
Replace username
with your Droplet’s username (often root
) and your_droplet_ip
with the IP address of your Droplet.
Once you’re connected to the Droplet, you need to clone your project. If the dummy project is in a specific directory (like /var/www/
), you might want to clone your project into the same directory for consistency.
cd /path/to/your/directory
git clone git@github.com:name/yourproject.git
Navigate into your project directory:
cd yourproject
If your project has a requirements.txt
file, install the required packages:
pip install -r requirements.txt
Your Django project likely needs a database. Update the DATABASES
setting in your settings.py
to connect to the database on your Droplet.
If you’re using PostgreSQL, for example, ensure you have the PostgreSQL client installed:
sudo apt-get install libpq-dev
pip install psycopg2
Then configure the database settings in settings.py
.
Run Django migrations and collect static files:
python manage.py migrate
python manage.py collectstatic
You can test if your Django application is running properly by starting Django’s development server:
python manage.py runserver 0.0.0.0:8000
Then, access your Droplet’s IP address followed by :8000
in a web browser. If everything is set up correctly, your Django project should be visible.
Gunicorn is commonly used to serve Django projects. If it’s not installed:
pip install gunicorn
Test running your Django project with Gunicorn:
gunicorn --bind 0.0.0.0:8000 your_project.wsgi:application
Replace your_project
with the name of your Django project.
Edit your Nginx configuration file to serve your Django application. You can find this file at /etc/nginx/sites-available/
. Replace the proxy pass configuration with the path to your Gunicorn socket or service.
The updated block might look something like:
location / {
proxy_pass http://localhost:8000;
# other required settings...
}
Make sure your firewall settings allow traffic through the web server. For example, if you’re using UFW:
sudo ufw allow 'Nginx Full'
To ensure Gunicorn runs continuously and starts on boot:
/etc/systemd/system/gunicorn.service
).sudo systemctl start gunicorn
sudo systemctl enable gunicorn
Remember, the exact steps might vary slightly based on your specific project setup and server configuration. If you encounter issues, the error logs for Nginx and Gunicorn can be invaluable for troubleshooting.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.