How to host a Django app on VPS via Apache 2...?

Published: Sun Jul 28 2024

Step1:-

Install python and pip using the command:

apt install python3-pip

 

Step2:-

Install virtual environment using the command:

apt install python3-virtualenv

 

Step3:-

Install mod-wsgi using the command:

apt install libapache2-mod-wsgi-py3

 

Step4:-

Create a virtual environment.

 

Step5:-

Solve the MySQL client error using the commands:

sudo apt-get install libmysqlclient-dev

sudo apt-get install pkg-config

 

Step6:-

Run the collectstatic command.

 

Step7:-

Add the following lines to the Apache conf:

WSGIPassAuthorization On

Alias /static /var/www/Deployment/staticfiles
        <Directory /var/www/Deployment/staticfiles>
                Require all granted
        </Directory>
        Alias /media /var/www/Deployment/media
        <Directory /var/www/Deployment/media>
                Require all granted
        </Directory>

        <Directory /var/www/Deployment/visualise_dreams>
                <Files wsgi.py>
                        Require all granted
                </Files>
        </Directory>

 

        WSGIDaemonProcess Deployment python-path=/var/www/Deployment python-home=/var/www/Deployment/env
        WSGIProcessGroup Deployment
        WSGIScriptAlias / /var/www/Deployment/visualise_dreams/wsgi.py

 

Step8:-

Restart the apache server using:

sudo service apache2 restart

 

Step9:-

Run the following command to solve the directory access:

chmod 777 -R media

 

Note: 

Don't forget to set debug to False before pushing your application in production.

 

 

Written by:Falak Kumar