Friday, April 24, 2015

Apache configuration for Django

Install mod_wsgi:

# yum install mod_wsgi

Edit httpd-vhosts.conf:

# vim /etc/httpd/conf.d/httpd-vhosts.conf

<VirtualHost *:80>
    ServerName myproj.cent-dev.local
    ServerAdmin webmaster@example.com

    DocumentRoot "/var/www/html/django/myproj"

    Alias /media/ /var/www/html/django/myproj/media/
    Alias /static/ /var/www/html/django/myproj/static/

    <Directory "/var/www/html/django/myproj">
        #<Files wsgi.py>
        #Require all granted
        #</Files>
    </Directory>

    WSGIDaemonProcess myproj.cent-dev.local python-path=/var/www/html/django/myproj:/usr/lib64/python2.7/site-packages  processes=2 threads=15 display-name=%{GROUP}
    #WSGIDaemonProcess myproj.cent-dev.local python-path=/var/www/html/django/myproj:/usr/lib64/python2.7/site-packages
    #WSGIDaemonProcess myproj.cent-dev.local python-path=/var/www/html/django/myproj

    WSGIProcessGroup myproj.cent-dev.local

    ### use the following on the production server.
    #WSGIScriptAlias / /var/www/html/django/myproj/myproj/wsgi.py process-group=myproj.cent-dev.local

    ### use the following two lines on the development server.
    ProxyPass / http://127.0.0.1:8000/
    ProxyPassReverse / http://127.0.0.1:8000/

    #SetEnv DJANGO_SETTINGS_MODULE myproj.settings

    ErrorLog "/var/log/httpd/myproj-cent-dev.local-error_log"
    CustomLog "/var/log/httpd/myproj-cent-dev.local-access_log" common
</VirtualHost>

Install pip:

# wget https://bootstrap.pypa.io/get-pip.py

# python get-pip.py

Install django:

# pip install django==1.7.6

To verify that Django can be seen by Python:

# python -c "import django; print(django.get_version())"

1.7.6

To listens on local interface on port 8000:

# python manage.py runserver

0 errors found
March 15, 2015 - 19:56:59
Django version 1.6.2, using settings 'myproj.settings'
Starting development server at http://127.0.0.1:8000/

To listens on every interface on port 8000:

# python manage.py runserver 0.0.0.0:8000

No comments: