1、准备工作
- 使用如下命令检查
Apache是否安装
apache2 -v
# 或者
systemctl status apache2

如果没有安装Apache,可以参考此文安装:https://blog.youkuaiyun.com/github_38336924/article/details/82459078
2、Apache配置CGI
- 启动
CGI模块
a2enmod cgi

- 重启
Apache
service apache2 restart
# 或者
systemctl restart apache2
- 默认执行的
CGI脚本需要放在/usr/lib/cgi-bin目录下,在/etc/apache2/conf-enabled/serve-cgi-bin.conf文件中可以进行修改

3、测试
- 在
/usr/lib/cgi-bin目录下 ,通过命令vi hello.c新建脚本测试
#include "stdio.h"
int main(int argc,char* argv[])
{
printf("Context-Type:text/html\n\n");
printf("HelloWorld\n");
return 0;
}

- 执行
gcc -o hello.c编译为.cgi或者.fcgi结尾的文件
gcc -o hello.cgi hello.c
# 或者
gcc -o hello.fcgi hello.c
- 浏览器地址栏
ip+cgi-bin/hello.fcgi,查看是否成功

394



被折叠的 条评论
为什么被折叠?



