Python Learning Note 13:python + Wsgi + Django configuration. Pit Daddy's Python3 and WSGI incompatible solution

Source: Internet
Author: User
Tags django website

People do not see the ancient months, this month has been according to the ancients. Life is so beautiful and short!

After two months of learning python, Python's syntax has a rudimentary understanding by doing simple grammar questions and looking at Python syntax. But to work or to do other things, so feel very slow to learn. There is a feeling of being in the way.

Basic understanding of the grammar, the next step into the project as soon as possible to combat. In order to quickly encounter problems, and solve problems, quickly improve ability.

The beginning of course is to follow the general steps online, with Django to write a blog site.

The next is the Blood and tears! To configure this Python + Wsgi + Django, the nausea has reached enough to make me vomit dozens of blood levels. View

***********************

Installation Environment:

Centos5.6

Python2.7

mod_wsgi:mod_wsgi-4.4.13

apache:httpd2.2

django:django-1.8.3

***********************

1. Installing python:python2.7

Originally the system has already brought the Python2.6, in order to my pursuit of the ultimate, installed force of perfectionism, I installed the Python3.4. and point/usr/local/bin/python directly to Python3.4. Set it as the main program for Python.

Here is the root of the tragedy. because Python3 and MOD_WSGI are not compatible (note: At least until now I have not found a wsgi that can be installed using Python3), I use it directly when I install it./configure make Makeinstall command, causing the system I chose to set the Python version of Apache to python2.6. (Note: Wsgi: This is the Python Web server Gateway Interface, its role is that Apache can connect to and use Python)

But since my Django was installed with Python3. Eventually led to Apache is not connected to Django, I query httpd under the Error_log back and forth countless times, finally found httpd use is python2.6. So we can only use python2 decisively, but the new problem arises again, because the Django version of the download is too high, python2.6 installed, so the end result is: Install python2.7!

Command:

TAR-XVF Python-2.7.10. TGZCD Python-2.7. /configure--enable-shared

Make

Make install

You may encounter problems: Python:error while loading shared libraries:libpython2.7.so.1.0:
Cannot open shared object File:no such file

Cause: python2.7 's library is missing.

Solution: 1. Enter the/etc/ld.so.conf.d/,

2. New file: Vim python2.7.conf

3. The path of the library where the python2.7 is added:/usr/local/lib

4. Save and exit, then execute the command: Ldconfig

2. Installing django:django-1.8.3

Go directly to the installation package folder using Python installation

Tar xzvf  Django-1.8.3 . tar.gz cd  Django-1.8.3sudo python  setup.py install

3. Installing mod_wsgi:mod_wsgi-4.4.13

: Https://pypi.python.org/pypi/mod_wsgi

installation command:

./configure--with-python=/usr/local/bin/python2.7Makemake Install

You may encounter a problem:

3-1. Apxs:command not Found

Cause: Apache component Httpd-devel not installed

Workaround: Yum Install Httpd-devel

3-2. Compile failed on make. View the first line of error, found: Sorry, Python Developer package does not appear to be installed.

Cause: Python component Python-devel not installed

Workaround: Yum Install Python-devel

Reference Link: http://www.cnblogs.com/bolddream/p/mod_wsgi.html

4. Configure HTTPD (Note: This is important to enable httpd to use Python through Wsgi and access to the Django Web site directory), and is prone to problems:

4-1. Add a link to the Wsgi. So file for httpd:

1. vim/etc/httpd/conf/httpd.conf

2. Add content: LoadModule wsgi_module modules/mod_wsgi.so

3. Save the exit.

4-2. Continue to modify httpd.conf, add the path to the Django project, such as the path of my new Django website:/var/www/html/mysite, then configure as follows:

wsgipythonpath/var/www/html//"/var/www/html/mysite/mysite/wsgi.py" <directory "/var/www/html/mysite/ MySite ">                order allow,deny        allow from all <files wsgi.py>                order Allow,deny                allow         from all </Files></Directory>

4-3. Configuring the Wsgi file

The general Django build project automatically configures the wsgi.py file for you. Do not need to match, if your WSGI must be installed. My/var/www/html/mysite/mysite/wsgi.py content is as follows:

Import Osos.environ.setdefault ("Django_settings_module", "mysite.settings"import= Get_wsgi_application ()

5. Restart httpd service:service httpd restart

At least the configuration problem is basically resolved. If you encounter a new problem, you have to go to the StackOverflow and check it out.

The next article is about how to build a blog site with Django.

Python Learning Note 13:python + Wsgi + Django configuration. Pit Daddy's Python3 and WSGI incompatible solution

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.