Question

How to clone Github Django project to my droplet ?

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 ?

Show comments

Submit an answer


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!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer
  1. ssh to your droplet

  2. 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

KFSys
Site Moderator
Site Moderator badge
December 4, 2023

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:

1. Connect to Your Droplet

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.

2. Clone Your Django Project from GitHub

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

3. Install Project Dependencies

Navigate into your project directory:

cd yourproject

If your project has a requirements.txt file, install the required packages:

pip install -r requirements.txt

4. Configure the Database

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.

5. Apply Migrations and Collect Static Files

Run Django migrations and collect static files:

python manage.py migrate
python manage.py collectstatic

6. Test Your Django Application

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.

7. Configure Gunicorn

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.

8. Update the Nginx Configuration

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...
}

9. Adjust Firewall Settings (If Needed)

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:

  • Create a Gunicorn systemd service file (/etc/systemd/system/gunicorn.service).
  • Configure it for your project.
  • Enable and start the service:
sudo systemctl start gunicorn
sudo systemctl enable gunicorn

11. Final Checks

  • Double-check all configurations.
  • Ensure all services are running.
  • Visit your Droplet’s IP address in a browser to see if your Django project is live.

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.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.