Deploy Django on Apache2

From PedrosBrainDump

Install needed packages

sudo apt-get install python3 python3-pip apache2 libapache2-mod-wsgi-py3 python3-virtualenv snapd -y

Create virtual environment

Go to /var/www/ and create the dir to your project

virtualenv myprojectenv

Then activate the environment

source myprojectenv/bin/activate

Install pip packages and run all migrations

Install Django and all packages needed

pip install django

Configure the Apache web server

<VirtualHost *:80>
       ServerAdmin your@mail.com
       ServerName  yourdomain.com # or remove it
       DocumentRoot /var/www/yourproject

       ErrorLog ${APACHE_LOG_DIR}/error.log
       CustomLog ${APACHE_LOG_DIR}/access.log combined


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

   WSGIDaemonProcess anything python-home=/var/www/yourproject/projectenv python-path=/var/www/yourproject
   WSGIProcessGroup anything
   WSGIScriptAlias / /var/www/yourproject/yourproject/wsgi.py
</VirtualHost>

Configure SSL on Apache

To enable ssl on your site you must to have a domain and the domain must to be pointed to your server ip.

Via snap install the certbot

snap install certbot --classic

Then use the command certbot to configure all your domain.