yum install httpd-devel
./configure.apxs
make
make install
chmod 755 /var/log/httpd #For log out
现在httpd.conf文件中已经加入了下面的代码
LoadModule fcgid_module/usr/lib/httpd/modules/mod_fcgid.so
通过下面的命令新建fcgid.conf文件
# vi /etc/httpd/conf.d/fcgid.conf
添加下面的内容
FcgidIPCDir /var/run/mod_fcgid
FcgidProcessTableFile /var/run/mod_fcgid/fcgid_shm
AddHandler fcgid-script .fcgi
SocketPath /tmp/fcgid_sock/
IPCConnectTimeout 20
MaxProcessCount 8
DefaultMaxClassProcessCount 2
TerminationScore 10
SpawnScore 80
IdleTimeout 300
确保/var/run/mod_fcgid目录存在,而且属主改为apache。
如果启动Apache失败,报“httpd dead but subsys locked”错误,可尝试使用下面的命令调试。
ipcs -s | grep apache | perl -e 'while (
rm -f /var/lock/subsys/httpd
rm -f /var/log/httpd/error_log
service httpd start
cat /var/log/httpd/error_log
如果/var/run/mod_fcgid不存在,就是用下面的命令
#mkdir /var/run/mod_fcgid
#chown apache /var/run/mod_fcgid
现在有了这个目录,而且属主已经改为apache。
在/var/www目录下新建fcgi-bin目录
把TestFastCGI及其依赖的so文件复制到fcgi-bin目录,否则/usr/bin/ld不能找到动态链接库。
我们的TestFastCGI只依赖libfcgi.so文件,所以我们也要把它复制到fcgi-bin目录。
我喜欢把网站要用到的文件全部放到/var/www/目录,避免时间花在权限调整上面。
在httpd.conf下添加下面的设置(除了目录名称和文件名称不同,其它同Windows)
SetHandler fcgid-script
Order allow,deny
Allow from all
ScriptAlias /myfcgid "/var/www/fcgi-bin/TestFastCGI"
IdleTimeout 3600
ProcessLifeTime 7200
MaxProcessCount 64
DefaultMaxClassProcessCount 8
IPCConnectTimeout 300
IPCCommTimeout 7200
BusyTimeout 300
保存后退出重启Apache
#service httpd restart
然后通过“http://192.168.19.130/myfcgid”网址就可以访问了,其中“192.168.19.130”是我Cent OS机器的IP地址。
为了方便在Cent OS上调试我们的FastCGI程序,我们可以新建Shell脚本,示例代码如下
# vi rebuild.sh
#!/bin/sh
service httpd stop
make clean
make
mv TestFastCGI /var/www/fcgi-bin
service httpd start
#chmod 755 rebuild.sh
附:
Win8下通过启用CGI查看Apache服务器环境
修改“C:\ProgramFiles (x86)\Apache Software Foundation\Apache2.2\conf”路径下的httpd.conf文件,原
AllowOverride None
Options None
Order allow,deny
Allow from all
改为
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
打开任务管理器->服务->Apache2.2->重启服务
在浏览器中输入下面的地址(前提是启用了CGI)
http://127.0.0.1/cgi-bin/printenv.pl
打印当前环境变量
修改侦听端口
Listen 80
查看网站根目录在哪里
DocumentRoot"C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs"
配置虚拟目录
找到<IfModule alias_module>节点,在这个节点下可以配置虚拟目录
例如可以插入下面的代码段
Alias /vdir1 "D:/wwwroot/mydir1"
<Directory "D:/wwwroot/ mydir1">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
order allow,deny
Allow from all
Directory>
参考资料
[1]Apache HTTP Server Project(Apache HTTPD)
http://httpd.apache.org/
[2]Apache HTTP Server Version 2.2Documentation
http://httpd.apache.org/docs/2.2/en/
[3] windows下apache设置域名创建虚拟目录
http://www.crackedzone.com/apache-domain-virtual-directory.html
[4] Apache与Tomcat整合
http://www.cnblogs.com/itech/archive/2009/08/18/1548723.html
http://zhidao.baidu.com/link?url=_aaTUHghrT0MxMnEx9iDFkNHdye5QisbwAEW1D2GJBtDN-Vm8pjzVHPlqn7qekdwpnXPeH74-pgOAc7q_2zslK
[5] [Apache手册]Linux环境下配置Apache运行cgi
http://blog.snsgou.com/post-686.html
[6] fastcgi与cgi的区别
http://www.cnblogs.com/lmule/archive/2010/12/09/1900914.html
[7]Apache fcgid模块
http://httpd.apache.org/download.cgi#mod_fcgid
[8]Ap