Apache + python

Source: Internet
Author: User

1. Install apache(httpd-2.2.25.tar.gz)

Download the latest apache source code to the http://httpd.apache.org, unzip and enter the directory:

To install apache under/usr/lcoal/apache, run the following command:

Run:

. /Configure -- prefix =/usr/lcoal/apache -- enable-track-vars -- enable-cgi -- enable-modules = all -- enable-mod-shared = all -- 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 -- enable-so

Run:

Make & make install

In this way, apache is installed.

2. Install pythonpython2.6)

3. Install mod_pythonmod_python3.3.1)

Mod_python (http://www.djangoproject.com/r/mod_python/) is an Apache plug-in embedded in Apache that loads Python code into memory at server startup.

Download the source code package from www.modpython.org, decompress the package, and enter the directory:

[Root @ htuidc mod_python-3.3.1] #./configure -- with-apxs =/usr/local/apache/bin/apxs -- with-python =/usr/bin/python

If the following error occurs:

Configure: error: Can not link to python

Solution:

[Root @ htuidc bin] # yum install python-devel

[Root @ htuidc mod_python-3.3.1] # make

If the following error occurs during compilation:

Connobject. c: 142: error: request for member ?. Ext ?. 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/local/src/mod_python-3.3.1/src'

Make: *** [do_dso] Error 2

You need to modify the/mod_python-3.3.1/src/connobject. c file and place "! (B = APR_BRIGADE_SENTINEL (B )"

Change to "!" (B = APR_BRIGADE_SENTINEL (bb )"

[Root @ htuidc mod_python-3.3.1] # make install


Check whether the mod_python.so library exists in the modules directory of apache. If not, copy/usr/local/src/mod_python-3.3.1/src/mod_python.so to the modules directory of apache.

Add the following to httpd. conf:

LoadModule python_module modules/mod_python.so


4. Create a python website


1) Add httpd. conf

<Directory "/var/www/pyweb/py">

AllowOverride FileInfo

AddHandler mod_python. py

PythonHandler index

PythonDebug On

Order allow, deny

Allow from all

</Directory>


At the same time

<IfModule alias_module>

</IfModule>

Join

ScriptAlias/py/"/home/dantezhu/apache/py /"

Restart apache



2) create a py directory under the apache directory and create a new file index. py in the directory. The content is as follows:

From mod_python import apache

Def handler (req ):

Req. write ("Hello World! ")

Return apache. OK

Note: PythonHandler index, the index name here must be tested using index. py)


This article is from the galean blog, please be sure to keep this source http://galean.blog.51cto.com/7702012/1302140

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.