CentOS under APACHE+PYTHON+DJANGO+MOD_WSGI environment
Introduction: Because of the Linux system does not understand, install software or something always like to use Yum command, the result of this time in the building environment to eat a big loss. Online articles are mostly used Mod_python to build, this only support to python2.5, now need to use python2.7, had to choose Mod_wsgi, seemingly mod_wsgi processing efficiency is even higher.
1. Installation Environment:
CentOS Version: CentOs5.7
Python version: Python2.7
Apache Version: Httpd2.2
Django Version: Django1.1
Mod_wsgi version: mod_wsgi-3.2-1.el5.x86_64.rpm
2. Software Installation:
2.1 Install Apache:
General server system will bring Apache, if not can be installed with Yum:
Yum–y install httpd (httpd-2.2.3-53.el5.centos.1.x86_64.rpm) |
2.2 Installation Python2.7:
The general Linux system will bring Python, generally 2.4 version, we need to reinstall, here, do not use Yum installation, and to use the source code compiled method to install, otherwise the following in the configuration will be wrong.
TAR-XVF python-2.7.tar.bz2 CD Python-2.7 ./configure --enable-shared Here must note that after the decompression to set the enable-shared Make Make install |
The usual path to install to is:/usr/local/lib/python2.7
After installation you can perform: # python to see if Python is installed successfully, you may encounter errors here:
Error: /usr/local/lib/python2.7/config/libpython2.7.a:could not read Symbols:bad value Collect2:ld returned 1 exit status Apxs:Error:Command failed with rc=65536 This is because when you install Python, there is no./configure--enable-shared Add and then recompile, then run Python, Encountered an error: Python:error while loading shared libraries:libpython2.7.so.1.0: Cannot open shared object File:no such file or Solution: New file below Vim/etc/ld.so.conf.d/python2.7.conf Add Content: /usr/local/lib Run after save exit: Ldconfig Execute Python again and the problem is resolved successfully. |
2.3 Installing Django:
The Django installation is simpler, as is the case with Windows
Tar xzvf django-1.1.tar.gz CD Django-1.1 sudo python setup.py install |
After installation, execute the command:
# python >>>import Django >>>django. VERSION |
You can see the Django version number, the installation is successful.
2.4 Installation Wsgi
Download the Wsgi module and note that you want to download the Linux version
http://code.google.com/p/modwsgi/downloads/detail?name=mod_wsgi-3.3.tar.gz&can=2&q=
Install the Apache APXS extension before installing MOD_WSGI:
Yum Install Httpd_devel This time may find Yum command can not use, hint: no module named Yum The reason is that Yum command relies on python2.4, now after 2.7, the Yum command is not used, the solution is as follows: Vim/usr/bin/yum Modify the #!/usr/bin/python to #!/usr/bin/python2.4 |
After installing Httpd_devel, start installing MOD_WSGI:
./configure--with-python=/usr/local/bin/python2.7 Make Make install |
When installing MOD_WSGI, it is recommended that you do not use Yum installation, because the Yum installation is likely to be unable to find the correct Python version and APXS module, or the APXS module is not installed, yum installation can also be successful, but the actual operation will occur many strange errors, Therefore, it is recommended to compile and install the source code.
3 Configuration
3.1 Configure Apache:
Apache configuration file in:/etc/httpd/conf/httpd.conf
Add to: LoadModule Wsgi_module modules/mod_wsgi.so |
Note: LoadModule wsgi_module modules/mod_wsgi.so should be put together with all LoadModule configurations, and this module will not be found if added to the end.
This is very important, the elder brother is eating this loss to eat big, debugging a afternoon, no results, all kinds of eggs pain ah.
Then in the configuration file, add:
Namevirtualhost *:8080 Listen 192.168.145.139:8080 <virtualhost *:8080> ServerName www.abc.com Wsgiscriptalias//var/www/html/ltfs_vla/setting.wsgi Documentroot/var/www/html/ltfs_vla <directory/> Options FollowSymLinks AllowOverride Order Allow,deny Allow from all </Directory> <Directory/var/www/html/LTFS_VLA/setting.wsgi> AllowOverride None Order Allow,deny Allow from all <files setting.wsgi> Allow from all </Files> </Directory> Alias/ltfs "/var/www/html/ltfs_vla" <directory "/var/www/html/ltfs_vla" > Options FollowSymLinks AllowOverride All Order Allow,deny Allow from all </Directory> Alias/admin_media "/usr/local/lib/python2.7/site-pacages/django/conftrib/admin/media" <directory "/usr/local/lib/python2.7/site-pacages/django/conftrib/admin/media" > Order Allow,deny Options Indexes Allow from all Indexoptions fancyindexing </Directory> </VirtualHost> |
The path and IP ports in the configuration, and so on, are changed on their own, depending on their actual needs.
3.2 Configuration Wsgi:
According to the above configuration, under the/var/www/html/ltfs_vla/directory, create the Setting.wsgi file, which reads as follows:
Import OS Import Sys Sys.stdout=sys.stderr From Os.path import Abspath,dirname,join From Django.core.handlers.wsgi import Wsgihandler Sys.path.insert (0,abspath (Join (DirName (__file__), "./")) os.environ["Django_settings_module"] = "gui.settings" Application=wsgihandler () |
The purpose of this file is to set up some environment variables.
4 Debugging
Turn on the Apache service
Then open the browser, enter the IP address on it, I entered here is 192.168.145.139:8080.
The above is the basic configuration process,