Linux +apache+fastcgi运行c/c++
在Linux上搭建apache+fastcgi环境,说多了都是泪啊. 花费我几天时间,开源软件虽说好用,但是版本众多,文档缺乏,什么都只能自己摸索. 终于成功运行起来,特此记录.
一. apache 安装
此处下载 apache-2.2.27 版本,常规的 configure make 命令,安装非常方便
wget http://mirrors.cnnic.cn/apache//httpd/httpd-2.2.27.tar.bz2tar -xjzf httpd-2.2.27.tar.bz2cd httpd-2.2.27./configure --prefix=/usr/local/apache2make && make install
二. apache 配置
<Directory "/usr/local/apache2/cgi-bin">AllowOverride NoneOptions Indexes ExecCGI # 执行CGIOrder allow,denyAllow from all</Directory>#添加文件映射AddHandler cgi-script .cgi .py
运行服务: ./apachectl start
打开 http://localhost, 成功会显示 It works!
三. 编译安装 fastcgi模块
fastcgi有多个分支版本, mod_fastcgi 官方地址: http://www.fastcgi.com/,这个是官方提供的扩展模块,已经很久没维护了; 而且下载链接已失效了
mod_fcgid 是apache官方维护的版本,与mod_fastcgi二进制兼容,原来的fastcgi程序不用重新编译就能工作. 其在mod_fastcgi基础上做了大量的代化
这里选择mod_fastcgi测试,生产环境不建议使用:
wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gztar -xzvf mod_fastcgi-2.4.6.tar.gzcd mod_fastcgi-2.4.6cp Makefile.AP2 Makefilemake top_dir=/usr/local/apache2make top_dir=/usr/local/apache install
编译完成后编辑httpd.conf, 加入fastcgi模块
LoadModule fastcgi_module modules/mod_fastcgi.so
四. 测试运行
下载安装 jnopy , fastcgi的python模块
cd jonpy-2.2.27
python setup.py install
#!/usr/bin/pythonimport jon.cgi as cgiimport jon.fcgi as fcgiclass Handler(cgi.Handler):def process(self, req):req.set_header("Content-Type", "text/plain")req.write("Hello, world!\n")fcgi.Server({fcgi.FCGI_RESPONDER: Handler}).run()
运行再一次出现500错误,查看日志: [error] No such file or directory exec of '/usr/local/apach2/cg-bin/hello_fcgi.py' failed
这就奇怪了,明明在/cgi-bin目录,打印的路径也是正常,怎么可能找不到呢? 难道是这脚本有猫腻,手动运行看看,报错: ./hello_fcgi.py: /usr/bin/python^M: bad interpreter: 没有那个文件或目录
原来这个文件有特殊字符,从windows下拷贝过来的文件很容易出现这个问题, vi 打开文件,直接 :set ff=unix 保存退出即可

五. 安装fastcgi开发库
如果顺序进行上面几步,表明环境都已经搭建好,下面部署c++程序
5.1 安装fastcgi开发库
wget http://www.fastcgi.com/dist/fcgi.tar.gzcd fcgi-2.4.1./configuremakemake install
make时出错, error: 'EOF' was not declared in this scope ,这EOF不是stdio.h中的吗, libfcgi/fcgio.cpp 中添加代码 #include <stdio.h> ,再次make,一切正常
5.2 编码测试
#include "fcgi_stdio.h"#include <stdlib.h>void main(void){int count = 0;while(FCGI_Accept() >= 0)printf("Content-type: text/html\r\n""\r\n""<title>FastCGI Hello!</title>""<h1>FastCGI Hello!</h1>""Request number %d running on host <i>%s</i>\n",++count, getenv("SERVER_NAME"));}
编译: gcc -o fcgi_test.fcgi cgi_test.c -I/usr/local/include -L/usr/local/lib -lfcgi

大小: 13.6 KB
大小: 15.8
Linux +apache+fastcgi运行c/c++的更多相关文章
- Linux apache的运行用户和用户组
我们在安装apache后,有时在上传文件的时候,提示没有权限或者是不可写,我们都会去查文件夹的权限. 通过ls -l /var/www/html/website可以很直观的看出我们文件和文件夹的权限, ...
- Linux apache的运行用户和用户组
我们在安装apache后,有时在上传文件的时候,提示没有权限或者是不可写,我们都会去查文件夹的权限. 通过ls -l /var/www/html/website可以很直观的看出我们文件和文件夹的权限, ...
- Nginx+FastCGI运行原理(一)
1 实战Nginx与PHP(FastCGI)的安装.配置与优化 1.1 什么是 FastCGI FastCGI是一个可伸缩地.高速地在HTTP server和动态脚本语言间通信的接口.多数流行的HTT ...
- Linux+apache+mono+asp.net安装教程
Linux+apache+mono+asp.net安装教程(CentOS上测试的) 一.准备工作: 1.安装linux系统(CentOS,这个就不多讲了) 2.下载所需软件 http-2.4.4.ta ...
- Atitit linux获取项目运行环境版本
Atitit linux获取项目运行环境版本 1.1. Nginx版本1 1.2. Php版本1 1.3. Mysql版本2 1.4. Redis版本2 1.1. Nginx版本 [root@iZ25 ...
- CentOS 6.3下源码安装LAMP(Linux+Apache+Mysql+Php)环境
一.简介 什么是LAMP LAMP是一种Web网络应用和开发环境,是Linux, Apache, MySQL, Php/Perl的缩写,每一个字母代表了一个组件,每个组件就其本身而言都是在它所代 ...
- CentOS 6.3 源码安装LAMP(Linux+Apache+Mysql+Php)环境
一.简介 什么是LAMP LAMP是一种Web网络应用和开发环境,是Linux, Apache, MySQL, Php/Perl的缩写,每一个字母代表了一个组件,每个组件就其本身而>言都是在它所 ...
- Centos下安装配置LAMP(Linux+Apache+MySQL+PHP)
Centos下安装配置LAMP(Linux+Apache+MySQL+PHP) 关于LAMP的各种知识,还请大家自行百度谷歌,在这里就不详细的介绍了,今天主要是介绍一下在Centos下安装,搭建一 ...
- [转] Ubuntu 12.04下LAMP安装配置 (Linux+Apache+Mysql+PHP)
我是一个Linux新手,想要安装一台Ubuntu 12.04版的Linux服务器,用这台服务器上的LAMP套件来运行我自己的个人网站.LAMP套件就是 “Linux+Apache+Mysql+PHP这 ...
随机推荐
- selendroid inspector xpth元素定位记录
android自动化测试元素定位,目前发现appium官方的uiautomatorviewer一般的元素定位还行,但好多都找不到. 这个时候,可以考虑selendroid的inspector 官网:h ...
- 在线HTML编辑器 kindeditor-4.1.10 上传图片文件 应用指南
1.在ASPX页面中对应的head.body添加相应的红色部分 2.引用kindeditor-4.1.10中的litjosn.dll 3.在写入数据库时要替换相应的路径和IP 4.kindeditor ...
- .net在Controller里的方法添加[HttpGet]和[HttpPost]
前端用post过来,Controller就要用[HttpPost],前端用get,Controller就要用[HttpGet],或者不管前端用什么,Controller都不加这些. 前端用post $ ...
- java 反射机制探究
一 反射机制操作类的成员变量 二 操作类的方法 三 利用反射实例化类 四 利用反射访问一个类的私有成员 五 利用反射覆盖数据对象的toString 方法
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState:
今天做项目中的支付宝功能,是在fragment中做的,在支付成功后,想切换到支付成功的页面. 结果就报错了IllegalStateException: Can not perform this act ...
- 关于TouchEvent中出现异常:MessageQueue-JNI问题
Tag:MessageQueue-JNI Exception dispatching input event. Exception in MessageQueue callback: handleRe ...
- c#局域网文件搬移
/// kongxiang--2013.7.23 /// using System;using System.Collections.Generic;using System.Linq;using S ...
- 06链队列_LinkQueue--(栈与队列)
#include "stdio.h" #include "stdlib.h" #include "io.h" #include " ...
- windows server 2003 负载平衡的详细设置步骤(转载)
声明:本文为转载. 当把一台服务器(包括Web服务器.FTP服务器或者流媒体服务器等等)放入网络中之后,随着客户端数量的不断增加,人们往往需要功能更强大.处理速度更快的服务器.为了解决这个问题,如果将 ...
- 修改placeholder颜色
#contact_info为textarea的ID #contact_info::-webkit-input-placeholder{ color:#999;}#contact_info:-moz-p ...