Ubuntu 14.04 + Apache2 + Django setup

来源:互联网 发布:大数据时代的精准营销 编辑:程序博客网 时间:2024/05/16 14:15

Install dependence

  1. Install apache2
$sudo apt-get install apache2 apache2-dev

Check apxs

$ apxs2
  1. Install python dev
$sudo apt-get install python-dev
  1. Install mod_wsgi
    Download from https://github.com/GrahamDumpleton/mod_wsgi/releases
$ wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.4.21.tar.gz$ tar zxvf 4.4.21.tar.gz$ cd mod_wsgi-4.4.21$ ./configureor$ ./configure --with-apxs=/usr/local/apache/bin/apxs --with-python=/usr/local/bin/python$ make$ sudo make install# Will create a mod_wsgi.so to modules: /usr/lib/apache2/modules/mod_wsgi.so
  1. Install django
$ sudo -E pip install django# Check$ django-admin help# Django docs: https://www.djangoproject.com/start/

Create your Django projects

  1. Create an simple django project
$ django-admin startproject BobServer# Check your project$ cd BobServer$ python manage.py runserver

Setup apache conf for your project

  1. Create django conf for apache2 http://www.rackspace.com/knowledge_center/article/ubuntu-modwsgi-installation
$ cd /etc/apache2/sites-available$ sudo vim django.conf# add below info"""LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.soWSGIScriptAlias /bobserver /home/bob/github/BobServer/BobServer/wsgi.pyWSGIPythonPath /home/bob/github/BobServer/:/usr/local/lib/python2.7/dist-packages/;/usr/local/bin/<Directory /home/bob/github/BobServer>        #Options Indexes FollowSymLinks        AllowOverride None        Require all granted        <Files wsgi.py>                Require all granted        </Files></Directory>ErrorLog ${APACHE_LOG_DIR}/BobServer.log"""# add soft link in sites-enabled$ sudo ln -s django.conf ../sites-available/django.conf# Restart apache2$ sudo service apache2 restart# To check your setup, open browser and go to your server url# xxxxxx.com/bobserver
0 0
原创粉丝点击