Skip to content

Instantly share code, notes, and snippets.

@sharmaeklavya2
Last active January 24, 2016 10:04
Show Gist options
  • Save sharmaeklavya2/abbf2499c3d7b77079f0 to your computer and use it in GitHub Desktop.
Save sharmaeklavya2/abbf2499c3d7b77079f0 to your computer and use it in GitHub Desktop.
Deploying a django project on Apache
<VirtualHost *:9000>
WSGIDaemonProcess owliver.com python-path=/srv/owliver:/srv/owliver/myvenv3/lib/python3.4/site-packages
WSGIProcessGroup owliver.com
Alias /media/ /srv/owliver/media/
Alias /static/ /srv/owliver/staticfiles/
<Directory /srv/owliver/staticfiles>
Require all granted
</Directory>
<Directory /srv/owliver/media>
Require all granted
</Directory>
WSGIScriptAlias / /srv/owliver/project_conf/wsgi.py
<Directory /srv/owliver/project_conf>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
This file contains instructions on how to deploy a django project on Apache on Debian-based distributions. I have taken https://github.com/sharmaeklavya2/owliver as an example.
  1. Make a symlink in /srv to the project directory (optional)

     sudo ln -s /mnt/Code/git_repos/owned/owliver /srv/owliver
    
  2. Static file configuration must be correct. Here is an example:

     STATIC_URL = '/static/'
     STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
     STATIC_ROOT = os.path.join(BASE_DIR,'staticfiles')
     MEDIA_URL = '/media/'
     MEDIA_ROOT = os.path.join(BASE_DIR,'media')
    
  3. Collect all static files

     python3 manage.py collectstatic
    
  4. Symlink apache_conf.conf into /etc/apache2/sites-available

     sudo ln -s /srv/owliver/local_conf/apache_conf.conf /etc/apache2/sites-available/owliver.conf
    
  5. If you haven't installed mod_wsgi, you can do so now

     sudo apt-get install libapache2-mod-wsgi-py3
    
  6. Edit /etc/apache2/ports.conf and add the line Listen 9000 (or whatever port number you are using in apache_conf.conf) below Listen 80. You will require superuser access to edit the file.

  7. Enable your site

     sudo a2ensite owliver.conf
    
  8. Reload apache

     sudo service apache2 reload
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment