前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >apache+mod-python

apache+mod-python

作者头像
py3study
发布2020-01-13 12:36:35
6140
发布2020-01-13 12:36:35
举报
文章被收录于专栏:python3python3

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以配置完成

现在这个工程没有任何程序

继续work。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-08-06 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • It worked!
    • Congratulations on your first Django-powered page.
    • It worked!
      • Congratulations on your first Django-powered page.
      相关产品与服务
      云数据库 SQL Server
      腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档