Build an AMPD environment using Centos

Source: Internet
Author: User
Tags install django


Note: httpd and mysql are installed by default in rhel 5.3. If not, download and install the RPM package and delete/etc/httpd/modules/mod_python.so.

1. Install python


1 wget http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz

2 tar xfz mod_python-2.7.11.tgz
3 cd python-2.7.11

Install./config -- prefix =/usr/local/python/
Make & make install
4 ln-s/usr/local/python/bin/python2.7/usr/bin/
5 ln-s/usr/local/python/bin/python/usr/bin/


Ii. Install setuptools


Wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg#md5=fe1f997bc722265116870bc7919059ea


1 sh setuptools-0.6c11-py2.7.egg


2 ldconfig # make it take effect


3. Install the mysqldb Module

Wget http://cdnetworks-kr-2.dl.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz

1 tar zxvf MySQL-python-1.2.3.tar.gz

2 cd MySQL-python

3python2. 7 setup. py build
# Ln-s/usr/local/python/bin/python2.7/usr/bin/(note to establish a connection)

4 python2.7 setup. py install # Installation

5 test:

[Root @ localhost conf] # python2.7
Python 2.7.1 (r271: 86832, Mar 21 2011, 10:13:38)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> Import MySQLdb
>>>

It is correct if no prompt is displayed.


4. Install mod_python

Wget http://archive.apache.org/dist/httpd/modpython/mod_python-3.3.0b.tgz

1 install apr-devel-1.2.7-11.el5_5.2.i386.rpm, apr-util-devel-1.2.7-7.SEL5_3.2.i386.rpm, httpd-devel-2.2.4.el5.centos.i386.rpm before installation, because you need to dynamically add python modules, or else you cannot find apxs

2 tar xvf mod_python-3.3.0b.tgz

3cd mod_python-3.3.0b

4./configure -- with-apxs =/usr/sbin/apxs -- with-python =/usr/local/python/bin/python ### (apache supports python)

5 make & make install

6. Note
LoadModule python_module modules/mod_python.so does not need to be added because it has been configured in/etc/httpd/conf. d/python. conf

7 ervice httpd restart (restart apache)

8 test:

[Root @ localhost conf] # python
Python 2.7.1 (r271: 86832, Mar 21 2011, 10:13:38)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> Import mod_python
>>>


5. Install Django

Wget http://www.djangoproject.com/download/1.2.5/tarball/
1 tar xfz Django-1.2.5.tar.gz
2 cd Django-1.2.5
3 python2.7 setup. py install
4 test:

[Root @ localhost conf] # python
Python 2.7.1 (r271: 86832, Mar 21 2011, 10:13:38)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> Import django
>>>


6. test all
1 mkdr/www
2cd/www

3/usr/local/python/bin/django-admin.py startproject mytest
4 cd mytest
5 python manage. py runserver 0.0.0.0: 8000
6. The effect is as follows:


Browser access:




Exit 7 CRTL + C


VII. Configure apache Virtual directories (two types of virtual directories are available: directory-based and domain-based)

1. Based on Virtual Directories
Vi/etc/httpd/conf/httpd. conf

Add the following configuration files:
Alias/python "/www"

<Directory/www>

AllowOverride FileInfo

AddHandler mod_python. py

PythonHandler test

PythonDebug On

</Directory>

# Service httpd restart (remember to restart )##

Write test. py in the/www directory:

From mod_python import apache

Def handler (req ):

Req. write ("Hello World! ")

Return apache. OK

Access in a browser:


2. Access a VM based on a Domain Name:
1 vi/etc/httpd/conf/httpd. conf
NameVirtualHost *: 80 ### remove comments

Add the following Configuration:
<VirtualHost *: 80>
ServerAdmin admin@zhnews.com
DocumentRoot/www
ServerName www.test.com
<Directory "/www">
AllowOverride FileInfo
AddHandler mod_python. py
PythonHandler test
PythonDebug On
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow, deny
Allow from all
</Directory>

</VirtualHost>

# Service httpd restart (remember to restart )##

# Map the IP address of the local hosts file to www.test.com ##

Browser access:


At this point, the configuration is successful.


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.