Apache配置

在httpd.conf中查找DocumentRoot:

+ExecCGI 支持cgi

DocumentRoot  "F:\phpStud\PHPTutorial\WWW"
<Directory />
Options +Indexes +FollowSymLinks +ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>

让apache识别py文件为cgi程序:

AddHandler cgi-script .cgi .pl .py

指定目录下执行cgi程序

ScriptAlias /cgi-bin/ "F:/phpStud/PHPTutorial/Apache/cgi-bin/"

重启 apache, from.py 文件内容

#!D:\python\python.exe  #python 运行程序位置
#coding=utf-
print ("Content-type:text/html")
print () # 空行,告诉服务器结束头部
print ('<html>')
print ('<head>')
print ('<meta charset="utf-8">')
print ('<title>Hello Word - 我的第一个 CGI 程序!</title>')
print ('</head>')
print ('<body>')
print ('<h2>Hello Word! 我是来自菜鸟教程的第一CGI程序</h2>')
print ('</body>')
print ('</html>')

运行文件存放位置

F:\phpStud\PHPTutorial\Apache\cgi-bin\from.py

浏览器访问地址:

http://localhost/cgi-bin/from.py

cgi 运行文件注意要点

第一:#! 前面不能有空格,后面紧跟解释程序;

第二,python等解释程序的目录是否正确;

第三,作为http协议的要求,一定要输出http headers;

第四,在存在http headers的前提下,一定要在headers后面打印一个空行,否则服务器会报错;

第五,把错误的程序在python的idle中执行一下,验证正确性;

最后,实在搞不定的情况下,查看apache的logs文件夹下的error.log文件,来确定问题。

相关文章:windows+phpstudy(apache) 以cgi方式支持python

Windows 配置Apache+CGI

windows+phpstudy(apache) 以cgi方式运行python的更多相关文章

  1. windows下更改Apache以fastcgi方式运行php

    Apache 默认 apache2handler 方式运行处理php. 下面说切换方法: 1.下载fastcgi模块,打开https://www.apachelounge.com/download/选 ...

  2. 在mac os下的Apache服务器的cgi中运行python

    我是搬运工.. Running Python Programs on the Mac OS X Apache Web Server The Mac OS X operating system incl ...

  3. 如何在Windows下开发Python:在cmd下运行Python脚本+如何使用Python Shell(command line模式和GUI模式)+如何使用Python IDE

    http://www.crifan.com/how_to_do_python_development_under_windows_environment/ 本文目的 希望对于,如何在Windows下, ...

  4. 在Apache中运行Python WSGI应用

    我们介绍如何使用Apache模块mod_wsgi来运行Python WSGI应用. 安装mod_wsgi 我们假设你已经有了Apache和Python环境,在Linux或者Mac上,那第一步自然是安装 ...

  5. Windows 下apache https配置(phpstudy)

    1.首先获取证书,https://www.pianyissl.com/  免费三个月的 或者 自己生成私钥.证书,然后应用到apache中. http://blog.sina.com.cn/s/blo ...

  6. Windows版本Apache+php的Xhprof应用

    [知识] {Apache} Apache是世界使用排名第一的Web服务器软件.它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一. {PHP} ...

  7. 以OpenGL方式运行Unity

    Unity在Windows上默认以DirextX的方式运行,在MacOS和Linux上默认以OpenGl的方式运行, 如果希望在Windows上以OpenGL的方式运行可以在命令行中输入 -force ...

  8. linux运行python程序

    linux下有多种方式运行python:   1. 命令行执行: 建立一个*.py文档,在其中书写python代码.之后,在命令行执行: $ python   *.py 注意事项:1. 需要指明文件的 ...

  9. 【Python从入门到精通】(二)怎么运行Python呢?有哪些好的开发工具(PyCharm)

    您好,我是码农飞哥,感谢您阅读本文,欢迎一键三连哦. 这是Pyhon系列文章的第二篇,本文主要介绍如何运行Python程序以及安装PyCharm开发工具. 干货满满,建议收藏,需要用到时常看看. 小伙 ...

随机推荐

  1. .net程序反编译工具(ILSpy)

    ILSpy是SharpDevelop小组的反编译工具,ILSPY这个开源工具的目的就是代替reflector的,它可以反编译出比reflector更好的C#代码. PC官方版 C#反编译工具ilspy ...

  2. Spring cloud微服务安全实战-7-5配置grafana图表及报警

    先过一下grafana的配置文件 grafana的配置文件. 右键服务的地址.发信人 账号 和面等 配置要连到prometheus上. 登陆的密码是多少,第二行是不允许用户注册. dashboard. ...

  3. 【LeetCode算法-28/35】Implement strStr()/Search Insert Position

    LeetCode第28题 Return the index of the first occurrence of needle in haystack, or -1 if needle is not ...

  4. WebViewJavascriptBridge js跟app的交互框架

    https://github.com/marcuswestin/WebViewJavascriptBridge 参考: https://www.cnblogs.com/LiLihongqiang/p/ ...

  5. LeetCode Top Interview Questions

    LeetCode Top Interview Questions https://leetcode.com/problemset/top-interview-questions/ # No. Titl ...

  6. [LeetCode] 655. Print Binary Tree 打印二叉树

    Print a binary tree in an m*n 2D string array following these rules: The row number m should be equa ...

  7. RSA 系统找不到指定的文件

    未测试 System.Security.Cryptography.RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); 改为 C ...

  8. Android MVP框架实现登录案例

    一.Model package com.czhappy.mvpdemo.model; /** * author: chenzheng * created on: 2019/5/16 11:06 * d ...

  9. typeof与instanceof运算符

    typeof运算符用来判断某个变量的数据类型.typeof()返回值类型有如下几种: 1.number :数值类型 2.string :字符串类型 3.boolean :布尔型 4.function: ...

  10. 永久修改 Linux pip国内源

    一些常用的国内源 清华大学:https://pypi.tuna.tsinghua.edu.cn/simple 阿里云:https://mirrors.aliyun.com/pypi/simple 中国 ...