博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux +apache+fastcgi运行c/c++
阅读量:7046 次
发布时间:2019-06-28

本文共 2312 字,大约阅读时间需要 7 分钟。

       在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 配置

AllowOverride NoneOptions Indexes ExecCGI # 执行CGIOrder allow,denyAllow from all
#添加文件映射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 保存退出即可

 

    python with fastcgi

 

  五. 安装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 
void main(void){int count = 0;while(FCGI_Accept() >= 0)printf("Content-type: text/html\r\n""\r\n""
FastCGI Hello!""

FastCGI Hello!

""Request number %d running on host
%s\n",++count, getenv("SERVER_NAME"));}

    编译: gcc -o fcgi_test.fcgi cgi_test.c -I/usr/local/include -L/usr/local/lib -lfcgi

  

   fast cgi

 

 

 

 

大小: 13.6 KB大小: 15.8 

转载地址:http://zmzol.baihongyu.com/

你可能感兴趣的文章
matplotlib 中文字体问题
查看>>
protobuf v3测试
查看>>
(1)知识准备【利用objective-c的runtime特性,结合FMDB实现一个轻量级的ORM】
查看>>
Angular js开发的各种坑(持续更新中。。。)
查看>>
Google Apps - Gmail API的通知功能
查看>>
调试java8 函数式
查看>>
Intellij使用心得(二) -- 关于启动Web服务器的几个事
查看>>
linux源代码安装软件
查看>>
2013年4月IT技术行业网站综合影响力排名
查看>>
Magento session机制的分析与应用
查看>>
linux 服务器长ping 加时间戳;转
查看>>
http与https的区别
查看>>
一些可以查询IP地理位置、身份证所在地、手机归属地的接口
查看>>
鼠标滚动插件smoovejs和wowjs
查看>>
我的友情链接
查看>>
javascript学习记录-数组(8)-完结 2014/02/26
查看>>
读取通讯录联系人
查看>>
ssh三大框架简单整合,struts2整合JasperReport报表、图表,解决HTML显示图片不出来,PDF中文不显示的问题...
查看>>
XML基础知识
查看>>
telnet: Unable to connect to remote host: No route to host处理过程
查看>>