banbanbai 发表于 2018-11-21 11:53:52

apache+mod-python

  1.install Python
  最新的Ubuntu操作系统是含有Python的,可以通过 Python --version 查看的:
  lab@lab:~$ python version
  Python 2.7.1+
  2.install MySQL
  使用最简单的方法:sudo apt-get install mysql-server mysql-client
  3.install Apache
  继续使用命令:sudo apt-get install apache2
  4.install MySQLdb
  sudo apt-get install python-mysqldb
  5.install mod_python
  sudo apt-get install libapache2-mod-python
  6.install Django
  到网站上下载: www.djangoproject.orgDjango-x.x.x.tar.gz
  解压:tar xzvfDjango-1.2.1.tar.gz
  安装:sudo python install setup.py
  7.测试Django 和 MySQLdb是否成功
  在命令行:python
  >>>import django
  >>>import MySQLdb
  如果没有错误提示,则安装成功!
  >>>exit()
  8.运行一个简单程序不是用apache
  lab@lab:~$ cd /var/www
  lab@lab:~$sudopython /usr/local/bin/django-admin.py startproject server
  lab@lab:~$ cd s*
  lab@lab:~$ ls
  可以看到在server 中多了几个文件,不管他
  lab@lab:~$ python manage.py runserver
  出现如下提示:
  0 errors foundDjango version 1.4 pre-alpha, using settings 'server.settings'Development server is running at http://127.0.0.1:8000/Quit the server with CONTROL-C.
  证明一切OK!
  打开浏览器:http://127.0.0.1:8000/server 出现如下画面:
It worked!
Congratulations on your first Django-powered page.
  django是个小的服务器,现在换没有运行在apache2上了
  9.配置apache2
  command:cd /etc/apache2
  command:sudo chmod 777 httpd.conf
  command:gedit httpd.conf
  添加:
  LoadModule python_module /usr/local/lib/apache2/modules/mod_python.so    SetHandler python-program      //这一句必须有,mod_python.so 在安装mod_python时生成的,
  PythonPath "['/var/www'] + sys.path"          //这里不必添加server 目录
  PythonHandler django.core.handlers.modpython
  SetEnv DJANGO_SETTINGS_MODULE server.settings    //工程名server
  PythonOption django.root /server
  PythonDebug On
  
  重启apache2 ,网上有很多种方法,直接重新开机是最实惠的。
  10.打开浏览器:http://127.0.0.1:8000
  出现:
It worked!
Congratulations on your first Django-powered page.
  证明apache以配置完成
  现在这个工程没有任何程序
  继续work。

页: [1]
查看完整版本: apache+mod-python