zoukankan      html  css  js  c++  java
  • ubuntu下配置django+apache+mysql+mod_python+Python

     

    网上有N种安装方法,我都试过,没有一个最后能成功,浪费了一下午的时间,终于搞定,

    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.org  Django-x.x.x.tar.gz 

    解压:tar xzvf  Django-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:~$sudo  python /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<Location "/server/">    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

    </Location>

    重启apache2 ,网上有很多种方法,直接重新开机是最实惠的。

    10.打开浏览器:http://127.0.0.1:8000

    出现:

    It worked!

    Congratulations on your first Django-powered page.

    证明apache以配置完成

     

     

    转自:http://www.cnblogs.com/changefuture/archive/2011/12/25/2300864.html

  • 相关阅读:
    学习的原动力
    “六顶思考帽”给我的启示
    关于DataSet与Strongly typed DataSet几点思考(原创)
    设计模式之Singleton和Factory
    CentOS修改网络配置
    Proxmox VE(PVE)安装教程
    CentOS开启SELinux导致samba无法访问的解决办法
    nano编辑器使用教程
    CentOS 如何挂载硬盘
    PVE硬盘直通
  • 原文地址:https://www.cnblogs.com/Jghost/p/3037297.html
Copyright © 2011-2022 走看看