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!
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.
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:
1. Connect to Your Droplet
First, you need to SSH into your Droplet. Open a terminal and use the following command:
Replace
username
with your Droplet’s username (oftenroot
) andyour_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.3. Install Project Dependencies
Navigate into your project directory:
If your project has a
requirements.txt
file, install the required packages:4. Configure the Database
Your Django project likely needs a database. Update the
DATABASES
setting in yoursettings.py
to connect to the database on your Droplet.If you’re using PostgreSQL, for example, ensure you have the PostgreSQL client installed:
Then configure the database settings in
settings.py
.5. Apply Migrations and Collect Static Files
Run Django migrations and collect static files:
6. Test Your Django Application
You can test if your Django application is running properly by starting Django’s development server:
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:
Test running your Django project with Gunicorn:
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:
9. Adjust Firewall Settings (If Needed)
Make sure your firewall settings allow traffic through the web server. For example, if you’re using UFW:
10. Enable and Start Gunicorn as a System Service (Optional but Recommended)
To ensure Gunicorn runs continuously and starts on boot:
/etc/systemd/system/gunicorn.service
).11. Final Checks
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.