Chapter 6. Deploy Django App

Overview of Django App Deployment (2)

Overview of Django App Deployment (2)
Tag:

In app deployment, there are many choices you need to make. For example:

  • Which hosting service are you going to use?
  • On which OS do you want to deploy your app?
  • Which database are you going to use for production?
  • Which combination of the web server and application server are you going to configure?

In this chapter, we'll explain the app deployment processes with specific case examples addressing the questions above.

Hosting Service

The first choice you need to make is which hosting service you want to use. There are different types of hosting services and providers.

For hosting services, the traditional approach was using a rental server; however, it is getting less popular now. Cloud services or VPS (Virtual Private Server) have recently become more popular as you don't need to worry about technical infrastructure management.

There are further different types of cloud services. For example, PaaS (Platform as a Service) like Vercel, Firebase, or PythonAnywhere provides easy-to-use services. IaaS (Infrastructure as a Service) like AWS, Azure, or GCP (Google Cloud Platform) provides more customizable services. Usually, cloud services use a pay-per-use billing model.

VPS is a service similar to IaaS, but its billing scheme is usually fixed price.

In this chapter, we'll use AWS Lightsail, which is a VPS service provided by AWS. It offers a three-month free trial.

OS

You need an OS (Operating System) to run a Django application. Linux OS is the most popular OS for web servers. Linux OS has many distributions, such as Ubuntu, CentOS, Debian, and Fedora. In this chapter, we use Ubuntu OS (20.04 LTS). You need basic knowledge of Linux OS to deploy your Django app on Linux OS. If you want to learn it, please check our Linux Introduction course.

Database

The default database for Django is SQLite, which is free open-source database software. It is a lightweight and serverless database, mainly used in small to medium-scale applications. It can be used at the production stage, but MySQL or PostgreSQL are more popular for production use. You can also use cloud database services. In this chapter, we use PostgreSQL

Web Server and Application Server

Two types of server functionalities are required for dynamic web applications – web server and application server. The key difference between those two servers is that the web server manages static content while the application server handles dynamic content.

Depending on the server software, the application server functionality can be part of web server software. For example, for Apache, which is popular web server software, the application server functionality is covered by an extended module. On the other hand, another popular web server, Nginx, focuses more on web server functionalities.

In this chapter, we use Nginx for a web server and Gunicorn for an application server.

For the application server functionality, Django supports two standard interfaces: WSGI (Web Server Gateway Interface) and ASGI(Asynchronous Server Gateway Interface). Gunicorn is a WSGI server.

Summary

Here is the summary of software and service choices for our Django app deployment in this chapter.

  • Hosting Service: AWS Lightsail
  • OS: Ubuntu (20.04 LTS)
  • Database: PostgreSQL
  • Application Server: Gunicorn
  • Web Server: Nginx

For the virtualization approach, we continue to use Python venv. Using Docker has recently become an alternative and more popular approach. We'll explain how to deploy a Django app using Dockar in another course.

In app deployment, there are many choices you need to make. For example:

  • Which hosting service are you going to use?
  • On which OS do you want to deploy your app?
  • Which database are you going to use for production?
  • Which combination of the web server and application server are you going to configure?

In this chapter, we'll explain the app deployment processes with specific case examples addressing the questions above.

Hosting Service

The first choice you need to make is which hosting service you want to use. There are different types of hosting services and providers.

For hosting services, the traditional approach was using a rental server; however, it is getting less popular now. Cloud services or VPS (Virtual Private Server) have recently become more popular as you don't need to worry about technical infrastructure management.

There are further different types of cloud services. For example, PaaS (Platform as a Service) like Vercel, Firebase, or PythonAnywhere provides easy-to-use services. IaaS (Infrastructure as a Service) like AWS, Azure, or GCP (Google Cloud Platform) provides more customizable services. Usually, cloud services use a pay-per-use billing model.

VPS is a service similar to IaaS, but its billing scheme is usually fixed price.

In this chapter, we'll use AWS Lightsail, which is a VPS service provided by AWS. It offers a three-month free trial.

OS

You need an OS (Operating System) to run a Django application. Linux OS is the most popular OS for web servers. Linux OS has many distributions, such as Ubuntu, CentOS, Debian, and Fedora. In this chapter, we use Ubuntu OS (20.04 LTS). You need basic knowledge of Linux OS to deploy your Django app on Linux OS. If you want to learn it, please check our Linux Introduction course.

Database

The default database for Django is SQLite, which is free open-source database software. It is a lightweight and serverless database, mainly used in small to medium-scale applications. It can be used at the production stage, but MySQL or PostgreSQL are more popular for production use. You can also use cloud database services. In this chapter, we use PostgreSQL

Web Server and Application Server

Two types of server functionalities are required for dynamic web applications – web server and application server. The key difference between those two servers is that the web server manages static content while the application server handles dynamic content.

Depending on the server software, the application server functionality can be part of web server software. For example, for Apache, which is popular web server software, the application server functionality is covered by an extended module. On the other hand, another popular web server, Nginx, focuses more on web server functionalities.

In this chapter, we use Nginx for a web server and Gunicorn for an application server.

For the application server functionality, Django supports two standard interfaces: WSGI (Web Server Gateway Interface) and ASGI(Asynchronous Server Gateway Interface). Gunicorn is a WSGI server.

Summary

Here is the summary of software and service choices for our Django app deployment in this chapter.

  • Hosting Service: AWS Lightsail
  • OS: Ubuntu (20.04 LTS)
  • Database: PostgreSQL
  • Application Server: Gunicorn
  • Web Server: Nginx

For the virtualization approach, we continue to use Python venv. Using Docker has recently become an alternative and more popular approach. We'll explain how to deploy a Django app using Dockar in another course.

Tag: