Linode is a great and old cloud hosting provider, which offers wide range of cloud services including VMs, managed databases, object storage and more.
In this article you will see how to deploy your Django application on Linode VM. If you are looking for tutorial for another cloud provider checkout out one of these:
- Deploy Django on Hetzner Cloud
- Deploy Django to Digital Ocean Droplet
- Deploy Django to AWS Lightsail
- Deploy Django to AWS EC2
- Deploy Django on Azure
- Deploy Django to Google Cloud Platform
Table of contents¶
Requirements¶
- An application to deploy
- Appliku Account
- Linode Account
Django Application¶
The application used for this tutorial can be found here: https://github.com/appliku/djangotutorial
Your app should be pushed into a git repository. You can use GitHub, GitLab.
For ease of deployment we have the following recommendations:
- have the
requirements.txt
file in the root of your git repository. Don't forget to addgunicorn
(or alternative) andpsycopg2-binary==2.9.5
for Postgres support (orpsycopg[binary]
) - Your app needs to respect environment variables like
DATABASE_URL
for the database credentials,ALLOWED_HOSTS
for the list of allowed domains,SECRET_KEY
andREDIS_URL
if applicable. - Please, don't forget to have DEBUG turned off when you deploy to a publicly accessible environment.
We have a full How to Start and Deploy a Django Project if you want to learn more
Also: check our SpeedPy.com SaaS boilerplate
Appliku Account¶
If you don't already have an Appliku Account create it by going here: https://app.appliku.com/
Click on "Add a server"
Pick a Custom Server:
Select this key, we will need it at server creation step.
Linode Account¶
If you don't already have a Linode account go here to sign up: Linode.com
Log in your account and go to the list of linodes: https://cloud.linode.com/linodes
Click on "Create Linode"
Select a Distribution:
Ubuntu 20.04 LTS
Select Region: Pick the closest to you or your target audience
Linode Plan: In this tutorial we will use the smallest available plan with 1 GB of RAM.
Scroll down and click "Add An SSH Key"
Paste the key you copied from the Appliku Dashboard earlier and give it some name.
Click "Add Key"
Select the key
Set a root password for server.
Scroll down and check the box that you accept terms of service and policies and click "Create Linode"
You will be taken to the server detail page, you can see that server is being provisioned.
When the status is "Running" it is time to add the server to Appliku.
Copy the IP address and switch back to Appliku Dashbord and paste it into IP field
Click on "Check credentials and add server"
You will be taken to the server detail page. Wait for Setup Status to say "Finished". If it becomes "Failed" go to the Setup Logs tab to see for errors.
Server setup is complete and stats are displayed:
Deploy Django Project on Linode¶
Click on the "Applications" menu link
You will get to the Git Provider selection.
Creating application from GitHub¶
Select the "Setup Credentials" for GitHub.
You need to get a personal token from GitHub.
Go to this link to create a token: https://github.com/settings/tokens
Click on Generate new token -> Generate new token(Classic) Fill in the note, select expiration date, check the "repo" checkbox and "user:email"
And click "Generate token".
Copy the token from the next page.
Go back to Appliku dashboard and paste the GitHub Token, and click Test Credentials and Save
Status must change to "Active".
Click on the logo in top left corner to get back to your team and go to Applications again and create an app, select GitHub.
Fill the form with the app name, select the repository with your application, branch and select the server, click on "Create Application".
You will see your app has been created, but not yet deployed.
Creating application from GitLab¶
Alternatively if you use GitLab you should add credentials for GitLab and create an app from GitLab.
Go to Applications menu link, Click "Add Application" and Setup credentials for GitLab.
You need to create a Personal Access Token here: https://gitlab.com/-/profile/personal_access_tokens
Give the key a name, set or clear expiration date, select "api" checkbox and click "Create Personal Access token"
Copy the token and paste it in Appliku dashboard.
After you click "Test Credentials and Save" the Status should turn green and say "Active".
Click on the logo to go back to your team, go to Applications, Add Application and select GitLab
Give your application a name, pick repository and the branch, select the server and click "Create Application"
Setup the app¶
Databases¶
First, create a Postgres Database. Click on Add Database on the right
Select the Postgres 16 option and click "Create database"
Your database will start deploying, wait for the deployment status to become "deployed".
Define processes¶
Let's tell Appliku how to run your app
On the Application Overview page you will see a red triangle saying "No processes found". Click on the "Add Processes" button.
Add two processes:
- one MUST be called
web
to answer to HTTP requests and command should begunicorn project.wsgi --log-file -
(pay attention to the last dash). It can be slightly different for your project - second one MUST be called
release
and this is the command that will be executed after each successful deployment. If not specified it will default topython manage.py migrate
. I recommend to create a bash script if your app needs to run several commands executed on each release. In our example, the command isbash release.sh
Click save and deploy button, a deployment will start.
Environment variables¶
Go to the "Environment Variables" tab and add env vars needed for your project.
At least specify the SECRET_KEY
and ALLOWED_HOSTS
.
These variables should be used by your app you can check here how to do that: https://github.com/appliku/djangotutorial/blob/master/project/settings.py
The SECRET_KEY
variable value should be some long hard to guess string.
The ALLOWED_HOSTS
variable should be a list of domains on which your app is accessible. As I already mentioned above, don't hardcode this, but make your app respect this environment variable.
By default, each app in Appliku receives a subdomain APPNAME.applikuapp.com
, so in our example it should be mydjangoapp.applikuapp.com
. If you add custom domains, make a comma-separated list like this mydjangoapp.applikuapp.com,example.com,www.example.com
.
You can disable the default subdomain in build settings.
When you are finished with environment variables click the "Save and deploy" button and deployment will start.
Reviewing application logs¶
From the Application Overview page you can go to App Logs to check if there are any errors.
Open your application¶
To access your app click on "Open App" and click on the domain name. It will open your app in a new window.