How to Deploy and Run Django only using Screen tool and Access it from Apache Webserver in Linux CentOS

Posted on

Introduction

As in the title of this article, the goal description is very clear. It is to show how to deploy and run django application. In this case, by deploying and running the Django application is only just by using screen tool and Apache Webserver. It is just trying to achieve an easy way to deploy and run Django application in a server.

Deploy and Run Django using Screen and Access it from Apache Webserver

There are several steps for deploying and running Django application in Linux CentOS. This attempt is already a success in Linux CentOS 7. It will more likely to be a success in another version of Linux CentOS such as Linux CentOS 8. So, the following are those steps :

  1. First of all, make sure that the ‘screen’ tool is available. Just type it in the command line. If the ‘screen’ tool is not available yet, just install it by typing ‘yum -y install screen’ or ‘dnf -y install screen’. Look in the article with the title of ‘Using screen in Linux via Command Line’ in this link as a sample reference.

  2. Create a new screen by typing the following command as an example :

    [root@localhost ~]# screen -R django 
    
  3. Continue on the step, inside the new screen, just make sure that the Django application or project can run by typing the normal command as follows in the screen :

    python manage.py runserver
  4. Get off from the screen by typing Ctrl A+D and the following output will appear redirecting back to the main terminal :

    [detached from 1529.django]
    [root@localhost ~]#
    
  5. Next, just make sure that the screen is still available by typing the following command :
    [root@localhost ~]# screen -ls
    There is a screen on:
    1529.django (Detached)
    1 Socket in /var/run/screen/S-root.
    
    [root@localhost ~]#
    
  6. Install Apache Webserver by simply execute ‘yum -y install httpd’ or ‘dnf -y install httpd’. Try to look at this link which is an article for installing Apache Webserver as a reference. It is an article with the title of ‘How to Install Apache Webserver in CentOS 8 Running in VirtualBox Application’.

  7. Do not forget to start the Apache Webserver and check its status as follows :

    [root@localhost conf.d]# systemctl status start
    [root@localhost conf.d]# systemctl status httpd
    ● httpd.service - The Apache HTTP Server
    Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
    Active: active (running) since Fri 2021-11-26 06:49:58 UTC; 5 days ago
    Docs: man:httpd(8)
    man:apachectl(8)
    Process: 3422 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
    Process: 5152 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS)
    Main PID: 3427 (httpd)
    Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
    CGroup: /system.slice/httpd.service
    ├─3427 /usr/sbin/httpd -DFOREGROUND
    ├─5157 /usr/sbin/httpd -DFOREGROUND
    ├─5158 /usr/sbin/httpd -DFOREGROUND
    ├─5159 /usr/sbin/httpd -DFOREGROUND
    ├─5609 /usr/sbin/httpd -DFOREGROUND
    ├─5613 /usr/sbin/httpd -DFOREGROUND
    ├─5614 /usr/sbin/httpd -DFOREGROUND
    ├─5615 /usr/sbin/httpd -DFOREGROUND
    ├─5616 /usr/sbin/httpd -DFOREGROUND
    ├─8384 /usr/sbin/httpd -DFOREGROUND
    └─9079 /usr/sbin/httpd -DFOREGROUND
    
    Nov 26 06:48:58 localhost systemd[1]: Stopped The Apache HTTP Server.
    Nov 26 06:48:58 localhost systemd[1]: Starting The Apache HTTP Server...
    Nov 26 06:49:58 localhost systemd[1]: Started The Apache HTTP Server.
    Nov 28 03:23:01 localhost systemd[1]: Reloading The Apache HTTP Server.
    Nov 28 03:23:16 localhost systemd[1]: Reloaded The Apache HTTP Server.
    [root@localhost conf.d]#
    
  8. Add a new configuration for defining how to access the Django application by creating a new file. In this case for an example the file name is ‘proxypass.conf’ where it exist in ‘/etc/httpd/conf.d/’ as follows :

    [root@localhost conf.d]# ls -al
    total 20
    drwxr-xr-x 2 root root 104 Nov 26 06:45 .
    drwxr-xr-x 5 root root 92 Nov 26 05:55 ..
    -rw-r--r-- 1 root root 2926 Nov 10 14:26 autoindex.conf
    -rw-r--r-- 1 root root 87 Nov 26 06:45 proxypass.conf
    -rw-r--r-- 1 root root 366 Nov 10 14:27 README
    -rw-r--r-- 1 root root 1252 Sep 30 2020 userdir.conf
    -rw-r--r-- 1 root root 824 Sep 30 2020 welcome.conf
    [root@localhost conf.d]#
  9. The following is the content of the ‘proxypass.conf’ file for Django application access definition through Apache Webserver :

    ProxyPass / http://192.168.100.42:8000/
    ProxyPassReverse / http://192.168.100.42:8000/
    
  10. Do not forget to restart the Apache Webserver’s service.

  11. Finally, just try to access it from any Webbrowser application available.

 

One thought on “How to Deploy and Run Django only using Screen tool and Access it from Apache Webserver in Linux CentOS

Leave a Reply