Here we are going install a basic django application using apache2 mod_python module. Requirements:
- server dns: web01.dev.local
- django code location: /usr/local/lib
- django project: hello
Let install few packages we need:
apt-get -y install apache2 libapache2-mod-python \
python-django
Once you ensure apache is up and running. Let create a simple django application:
cd /usr/local/lib
django-admin startproject hello
Add apache site configuration that will serve the django site. Add the following to
/etc/apache2/sites-available/django-hello:
<VirtualHost *:80>
ServerName web01.dev.local
DocumentRoot /var/www/
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice,
# warn, error, crit, alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE hello.settings
PythonDebug On
PythonPath "['/usr/local/lib'] + sys.path"
</VirtualHost>
Now we are going disable default apache site and enable django-hello site:
a2dissite default
a2ensite django-hello
/etc/init.d/apache2 restart
Once you navigate to http://web01.dev.local/ you should be able to see the default django welcome screen.
Troubleshooting
If you unable navigate to the apache this could be related to ipv6 support (that is turned on by default). You can verify that issuing the following command:
netstat -tunlp | grep :80
If the apache process is not listening on ipv4 address (e.g. 0.0.0.0:80) just follow the following
post to disable ipv6 in apache.
No comments :
Post a Comment