Configure apache to run a django framework based project [solved]

To serve django via apache, using mod_wsgi (recommended option by django documentation), proceed as follow:

  1. install apache mod_wsgi:
    sudo apt-get install libapache2-mod-wsgi-py3
  2. ensure mod_wsgi is indeed into /etc/apache2/mods-enabled:
    ls -l  /etc/apache2/mods-enabled/ | grep "wsgi"
  3. create a python virtualenv for your project (see Run python virtualenv with Ubuntu)
  4. go to /etc/apache2/sites-available and create file myproject.conf:
    sudo vi /etc/apache2/sites-available/myproject.conf
  5. Paste following content:
    <VirtualHost *:80>
    ServerName mydomain.com
    ServerAdmin webmaster@localhost
    DocumentRoot /path/to/myproject
    
    ErrorLog ${APACHE_LOG_DIR}/myproject.error.log
    CustomLog ${APACHE_LOG_DIR}/myproject.access.log combined
    
    Alias /static/ /path/to/myproject/static/
    <Directory /path/to/myproject/static>
    Require all granted
    </Directory>
    
    <Directory /path/to/myproject/myproject>
    <Files wsgi.py>
    Require all granted
    </Files>
    </Directory>
    
    WSGIScriptAlias / /path/to/myproject/myproject/wsgi.py
    WSGIDaemonProcess myproject python-path=/path/to/myproject:/path/to/myproject/virtualenv/lib/python3.4/site-packages
    WSGIProcessGroup myproject
    </VirtualHost>

    Note: update information in red to match your own requirement. In this example, project is called “myproject” and stored under “/path/to/myproject” and virtualenv for this project was created under “/path/to/myproject/virtualenv” using “python3.4”

  6. Activate configuration file:
    cd /etc/apache2/sites-enabled; sudo ln -s ../sites-available/myproject.conf ./
  7. Restart apache:
    sudo apache2ctl restart

Done!

Refresh your webpage and content should now be served

sources

Post a Comment

Your email is never published nor shared. You're allow to say what you want...