1. install apache and apache-python module: sudoapt-getinstallapache2sudoapt-getinstalllibapache2-mod-python2.7 2. Configure vim/etc/apache2/conf. d/charset in apachepython to cancel adddefacharcharsetutf-
1. Install the apache and apache-python modules:
- Sudo apt-get install apache2
- Sudo apt-get install libapache2-mod-python2.7
Ii. apache python Configuration
- Vim/etc/apache2/conf. d/charset, uncomment adddefacharcharset UTF-8
-
- Vim/etc/apache2/mod-available/python. conf, add:
-
- AddHandler mod_python. py
- AddType text/html. py
- PythonHandler pytest
- PythonDebug On
-
-
- Sudo ln-s/etc/apache2/mod-available/python. conf/etc/apache2/mod-enabled/python. conf
-
- Sudo vim/etc/apache2/sites-available/python, the content is as follows:
-
- DocumentRoot/var/www/py
- ServerName py
-
-
- AddHandler mod_python. py
- PythonHandler pytest
- PythonDebug On
-
-
-
- Ln-s/etc/apache2/sites-available/python/etc/apache2/sites-enabled/python
-
- Mkdir-p/var/www/py
- Chown-R www-data: www-data/var/www/py // the user running apache. The default value is www-data.
- Chmod-R 775/var/www/py
- Sudo adduser dave www-data
-
- Sudo service apache2 restart
- Access: http: // 127.0.0.1
Iii. test whether the task is successful: sudo vim/var/www/py/pytest. py. PythonHandler pytest in the Same Name:
- #! /Usr/bin/python
- #-*-Coding: UTF-8 -*-
- From mod_python import apache
-
- Def handler (req ):
- Req. content_type = 'text/html '// type of the request object
- Req. write ('Hello! ') // Req is the request object, which has a proprietary method: write
- Return apache. OK
-
- Chown-R www-data: www-data pytest. py
- Chmod 775 pytest. py
-
- Sudo service apache2 restart
- Access: http: // 127.0.0.1/py/pytest. py
Iv. virtualenv installation and configuration
- Sudo apt-get install-y python-dev python-setuptools
- Sudo easy_install virtualenv virtualenvwrapper pip
-
- Sudo mkdir/home/dave/study/webapps // The total working directory of all virtualenv Environments
- Sudo chown-R www-data: www-data/home/dave/study/webapps
- Sudo chmod-R g + rw/home/dave/study/webapps
-
- Add the following line ~ /. Bashrc:
- Export VIRTUALENV_USE_DISTRIBUTE = 1
- Export WORKON_HOME =/home/dave/study/webapps
- Source/usr/local/bin/virtualenvwrapper. sh
- Export PIP_VIRTUALENV_BASE = $ WORKON_HOME
- Export PIP_RESPECT_VIRTUALENV = true
- Export PYTHONPATH =/usr/local/lib/python2.7: $ PYTHONPATH
-
- Then source ~ /. Bashrc. If an error is reported, view the directory owner and permissions.
Create a virtual environment and install related software:
- Cd ~ /Study/webapps
- Mkvirtualenv firstenv
- Pip install "django = 1.4.5 ",
- Pip install MySQL-python
- // Install the related software in the virtual environment. Note that before installing mysql-python, you must first install sudo apt-get install python-dev libmysqlclient-dev; otherwise, the installation will fail.
-
-
- Check whether django is successfully installed:
- Python, enter idle
- > Import django
- > Print django. VERSION
- 1.4.5
For general usage of virtualenvwrapper, see http://www.cnblogs.com/Phenix_Yang/archive/2012/05/08/2489724.html:
- Cd webapps
- Mkvirtualenv NAME // create a virtual environment
- Rmvirtualenv NAME // delete a virtual environment
- Lsvirtualenv // list all Virtual Environments
- Workon NAME // enter the specified virtual environment. If no NAME is specified, all virtual environments are listed.
- Deactivate // exit the current Virtual Environment
General Usage of pip: when installing the software, pip is found on the pypi website, while pypi only collects links to the software package. The problem is that the link may be invalid, so pip is also flawed.
- Pip freeze // list all installed software packages
- Pip search django // find the software package with django in the name
- Pip install django // install django. The latest version is installed by default.
- Pip install "django = 1.4.5" // specify the version when installing the software package. You can also use <, <=,>,> = to specify the version range, for example, pip install "django> 1.4 <1.5"
- Pip install-U django // upgrade django
- Pip uninstall django // uninstall django