LINUX+DJANGO+PYTHON+WSGI configuration Process

Source: Internet
Author: User

Configuring the Apache+mod_wsgi+django environment under Linux

(YBW 2011-09-23)

A Installation Environment

Operating system: CentOS release 5.5

Kernel version: Linux svn-168-1-11 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:14 EDT (x86_64 x86_64 x86_64 gnu/linux

Python version:python 2.4.3

Apche version:httpd-2.2.3

Mod_wsgi version:mod_wsgi-3.2-1.el5.x86_64.rpm

Django version:Django-1.2.4

Two Software Installation

Python uses the default rpm installation path

Install Apache:

Yum–y install httpd (httpd-2.2.3-53.el5.centos.1.x86_64.rpm)

Install mod_wsgi:

RPM–IVH mod_wsgi-3.2-1.el5.x86_64.rpm

To install Django:

TAR–ZXVF django-1.2.4.tar.gz

CD Django-1.2.4

Python setup.py Install

Installing MYSQLDB

Wget-q http://peak.telecommunity.com/dist/ez_setup.py

wget Http://pypi.python.org/packages/2.4/s/setuptools/setuptools-0.6c11-py2.4.egg

Python ez_setup.py

TAR–ZXVF mysql-python-1.2.3.tar.gz

CD mysql-python-1.2.3

Python setup.py Build

Python setup.py Install

Successful Installation verification:

Shell> python

Python 2.4.3 (#1, May 5 2011, 16:39:10)

[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2

Type "Help", "copyright", "credits" or "license" for more information.

>>> Import Django

>>> Django. VERSION

(1, 2, 4, ' final ', 0)

>>> Import MySQLdb

>>>

Shell>ls/etc/httpd/conf.d

proxy_ajp.conf README welcome.conf wsgi.conf

Shell> ls/etc/httpd/modules/| grep Mod_wsgi

Mod_wsgi.so

Three Project deployment

1. Packaging Compression Development code :d ajie.zip

2. upload to server and unzip to directory /var/www/html

Shell> ls/var/www/html/

Dajie

3. Modify The apche configuration file httpd.conf

Shell> vi/etc/httpd/conf/httpd.conf

# # # at the end add the following content

<virtualhost *:80>

ServerName mice.operation.dajie-inc.com

Documentroot/var/www/html/dajie

Wsgiscriptalias//var/www/html/dajie/apache/django.wsgi

<directory/>

Order Deny,allow

Allow from all

</Directory>

<Directory/apache>

Allow from all

</Directory>

</VirtualHost>

4. Create and configure the wsgi configuration file:

Shell>cd/var/www/html/dajie

Shell>mkdir Apache

Shell>touch Django.wsgi

Shell>cat Django.wsgi

Import OS, sys

#Calculate the path based on the WSGI script.

apache_configuration= Os.path.dirname (__file__)

Project = Os.path.dirname (apache_configuration)

Workspace = Os.path.dirname (Project)

Sys.path.append (Workspace)

os.environ[' django_settings_module '] = ' dajie.settings '

os.environ[' python_egg_cache ' = '/tmp '

Import Django.core.handlers.wsgi

application = Django.core.handlers.wsgi.WSGIHandler ()

Print >> Sys.stderr, Sys.path

Shell>chmod a+x Django.wsgi

5. Modify The configuration file for the Django Project /var/www/html/dajie/settings.py, mainly in the following two places:

DATABASES = {

' Default ': {

' ENGINE ': ' Django.db.backends.mysql ',

' NAME ': ' Dajieod ',

' USER ': ' Dajieod ',

' PASSWORD ': ' dajieod123 ',

' HOST ': ' 127.0.0.1 ',

' PORT ': ' 3306 ',}

}

Template_dirs = (

# Put strings here, like "/home/html/django_templates" or "c:/www/django/templates".

# Always use forward slashes, even on Windows.

# Don ' t forget to the use of absolute paths, not relative paths.

'/var/www/html/dajie/templates ',

)

Four Start Project

Shell>service httpd Restart

Access test:

http://192.168.1.11

Project Deployment ok~

Five Problem set

1. Install mysql-python execution:python setup.py build error: Environmenterror:mysql_config not found

Method Solution: Ln-s/usr/local/mysql/bin/mysql_config/usr/local/bin/mysql_config
Link mysql_confi from your installation directory to the /usr/local/bin directory, so you can access it in any directory (or you can put it in /usr/bin )

2. Import MYSQLDB Error: Importerror:libmysqlclient_r.so.16:cannot open Shared object file:no such file or directory

Workaround: mysql/lib all so files about libmysqlclient to /usr/lib the next.
Ln-s/usr/local/mysql/lib/mysql/libmysqlclient*/usr/lib
Ldconfig
So when import MySQLdb , it won't go wrong.

3. After installing Django,mysqldb in the system environment , it is no problem to execute import , but start Apache when the browser accesses the error:

Error loading MYSQLDB module:importerror:libmysqlclient_r.so.16:cannot Open shared object file:permission denied

WORKAROUND: Here Apache Permission denied problem is caused by SELinux, close selinux can be. Close Selinux:vi/etc/selinux/config===selinux=disabled, then restart the system

(Do not restart settings Selinux:setenforce 0 view selinux:getenforce)

LINUX+DJANGO+PYTHON+WSGI configuration Process

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.