Apache + Python + mod_python + Django compilation and Installation Guide
1. This article will show you how to install the SDK using the source code package in Linux.
Apache 2.2.16
Python 1, 2.7
Mod_python 3.3.1
Django SVN trunk version
However, the compilation process is successful by default because the error information obtained during the compilation process cannot be known. For any questions, refer to the post-discussion forum.
2. The"
"Only indicates the command prompt. Do not enter it together with the command.
1. install Apache 2.2.16
1. Download
Http://httpd.apache.org
Download the latest httpd server. As long as the version is not much different from 2.2.16, you can refer to this article for configuration and installation.
2. Decompress
Tar xvfz httpd-2.2.16.tar.gz
The above command will get the httpd-2.2.16 directory in the current directory, which is the source directory of Apache 2.2.16.
For details about the decompression command, please refer to my article:
3. Configure
The process of compiling and installing source code is usually three steps: Configure/make install. Apache also follows this rule.
Go to the httpd-2.2.4 directory:
CD httpd-2.2.16
Run the following command to view configure help information:
./Configure -- Help
All the installation details are controlled by configure and its parameters.
If you try to install software from the source code package at the beginning, please get used to the lengthy and complex parameters after configure as soon as possible!
Below is my recommended configure parameter, which will install Apache under/opt/Apache and include all common Apache modules:
. /Configure -- prefix =/opt/Apache -- With-config-file-Path =/opt/Apache/conf -- enable-mod-shared = most -- enable-track-vars -- enable -CGI -- enable-so -- enable-file-Cache -- enable-disk-Cache -- enable-Mem-Cache -- enable-dumpio -- enable-logio -- enable-mime -Magic -- enable-headers -- enable-UserTrack -- enable-version -- enable-SSL -- enable-HTTP -- enable-Rewrite -- enable-proxy-connect -- enable-proxy -HTTP -- enable-proxy-FTP -- enable-proxy-AJP -- enable-proxy-balancer
Of course, installing all extension modules means to extend Apache functionality to the limit, but if you do not configure these modules or ignore them, they may bring you unnecessary trouble or security risks.
(The "-- enable-so" parameter is selected to allow Apache to use DSO for mod_python compilation later)
4. Make/make install
The really long step starts (I am referring to the time). The following command starts the compilation process:
Make
After the compilation is complete, run:
Make install
Install Apache in the/opt/Apache directory configured in step 3.
5. Configure Apache
Configuring the httpd. conf file of Apache is a big project. There are many articles on the Internet to guide you through correct and necessary configurations. I will not go into detail here.
Please refer to my article on how to add Apache to system services:
Add Apache to a Linux System Service
6. Known issues and solutions
If you encounter a. So permission error similar to the following:
Httpd: syntax error on line 63 of/opt/Apache/CONF/httpd. conf: cannot load/opt/Apache/modules/mod_python.so into server:/opt/Apache/modules/mod_python.so: cannot restore segment prot after reloc: Permission denied
This indicates that your. So file has insufficient permissions. It is likely that your SELinux (if you have installed it) permission check fails.
You can use the following command to define the. So file as a shared class library file. Then you can pass the permission check:
Chcon-T texrel_shlib_t/opt/Apache/modules/*. So
Note: Do not change *. So permission to 777. For details, refer to this article: Solve the PHP permission problem caused by SELinux.
The Installation Process of Apache is described in detail above. Later, Python/mod_python will only provide necessary explanations and recommended configure commands.
Ii. Install Python 2.7
1. Compile and install
Download the latest Python source code package from www.python.org, decompress the package, enter the directory, and execute:
./Configure -- prefix =/opt/Python/2.7
Make
Make install
Use the following command to add python to/usr/bin and distinguish Python execution files of other versions so that they can coexist.
Ln/opt/Python/2.7/bin/Python/usr/bin/python2.7
Later, you can compile the new version of python into/opt/Python/[version] and use the above command to generate a link to the corresponding version.
2. Set the running command
Note that the current Python 2.7 execution program is python2.7. To enter the shell of Python 2.7, type python2.7. If you want to use Python 2.7 for execution. in the first line of the script, run the python command:
! /Usr/bin/python2.7
If you think Python 2.7 will be used by default in the future, you can:
Rm-F/usr/bin/Python
Ln/opt/Python/2.7/bin/Python/usr/bin/Python
In this way, python is executed to enter 2.7.
3. Install mod_python
1. Go to www.modpython.org
Download the source code package, decompress the package, enter the directory, and run:
./Configure -- With-apxs =/opt/Apache/bin/apxs -- With-Python =/usr/bin/python2.7
Make
Make install
------------------
Note that there is a bug
Connobject. C: In function '_ conn_read ':
Connobject. C: 142: Error: Request for member 'Next' in something not a structure
Or Union
Apxs: Error: Command failed with rc = 65536
.
Make [1]: *** [mod_python.so] Error 1
Make [1]: Leaving directory '/usr/src/RPM/build/mod_python-3.3.1/src'
Make: *** [do_dso] Error 2
In mod_python-3.3.1/src/connobject. C to be modified
! (B = apr_brigade_sentinel (B)
Is
! (B = apr_brigade_sentinel (bb)
--------------
After completion, mod_python adds the mod_python.so library file to/opt/Apache/modules and adds the mod_python package to/opt/Python/2.7/lib/python2.7/Site-packages.
If the Compilation Program does not detect Apache and python, an error is returned and the program exits.
2. Configure httpd. conf
Find the/opt/Apache/CONF/httpd. conf configuration file and add it in the appropriate location:
Loadmodule python_module modules/mod_python.so
Remember, modules/mod_python.so must have the permission to pass SELinux check. For more information, see section 6th in chapter 1 of this Article!
4. Install Django
This time, we use the svn head version of Django (the latest development version ).
The advantage of using this version is that any official update requires you to run SVN to obtain the latest version and use it.
1. if the system does not have a subversion, find the installation (Procedure omitted ).
2. Get the latest working copy version.
You can select either of the following two versions:
First, all Django source code (many files ):
SVN Co http://code.djangoproject.com/svn/django
/Source/SVN/Django
Second, the latest version of Django trunk:
SVN Co http://code.djangoproject.com/svn/django/trunk
/Source/SVN/django_trunk
3. Link Django source code to the python site-packages public code directory.
All source code versions:
Ln-S/source/SVN/Django/trunk/Django/opt/Python/2.5.1/lib/python2.5/Site-packages/Django
The latest trunk version:
Ln-S/source/SVN/Django/opt/Python/2.5.1/lib/python2.5/Site-packages/Django
Be sure to include the-S parameter; otherwise, an error will occur in subsequent calls!
The above command only creates a link to the current source code directory to the site-packages, so that every time you run the following command to update Django, Python calls the latest version after the update:
CD/source/SVN/Django
SVN cleanup (if locked is prompted, execute this sentence)
SVN update
4. Copy Django Management Files
Run the following command to copy the management file to/usr/bin so that the file can be executed everywhere:
CP/ORIGIN/SVN/Django/trunk/Django/bin/django-admin.py/usr/bin/
Or
CP/source/SVN/Django/bin/django-admin.py/usr/bin/
If you run the django-admin.py, you get the following error message:
Importerror: No module named Django. Core
The django-admin.py is running in another version of python!
Remember, our Django is installed in Python 2.7 (/opt/Python/2.7). If your python 2.7 command is python2.7 (refer to chapter 2, section 2nd ), you need to modify the first line of/usr/bin/django-admin.py:
! /Usr/bin/python2.7
Or the python command that has installed Django.
4. References
For the official Installation Guide, refer:
Http://www.djangoproject.com/documentation/install/
For details about how to use Django, refer to this part of the official guide:
Http://www.djangoproject.com/documentation/modpython/
We recommend that you use the. htaccess file instead of modifying the httpd. conf configuration file directly, because. htaccess is more flexible.
Remember to configure AllowOverride In the httpd. conf configuration file (for example, AllowOverride = All)
V. Summary
If you follow the installation steps above, we will get the following content:
Apache 2.2.16 directory:
/Opt/Apache
Python 2.7 directory:
/Opt/Python/2.7.
Mod_python.so location:
/Opt/Apache/modules/mod_python.so
Django source package directory:
/Source/SVN/Django
Modified files:
/Opt/Apache/CONF/httpd. conf
To update DJANGO:
CD/source/SVN/Django
SVN update
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/bearjb2006/archive/2010/07/30/5776462.aspx