一、相关库文件的安装
为了能够支持C语言cgi脚本,首先安装bzip2-1.0.6.tar.gz、pcre2-10.30.tar.gz、pcre-8.42.tar.gz、zlib-1.2.7.tar.gz、lighttpd-1.4.15.tar.gz。
解压方法:tar -zxvf <相应源码压缩包>
解压后进入相应源码目录。
安装方式均为: ./configure、make、make install
相关资源包下载地址:https://download.youkuaiyun.com/download/suwei80286/11875063
完成后,输入:lighttpd -v 显示如下:
ighttpd-1.4.15 - a light and fast webserver
Build-Date: Oct 17 2019 21:23:02
说明已成功安装。
二、配置lighttpd
在完成上述源码编译安装后,
1.cd lighttpd-1.4.15/doc 源码文件夹
cp lighttpd.conf /etc/
2.vim /etc/lighttpd.conf 更改配置文件 (注 :set nu 显示行号)
(1). 取消17行"mod_alias", 29行“mod_cgi"注释,如下所示:
(注,取消注释即把最前边的#删除,vim的操作应用,可百度自行脑补!)
14 server.modules = (
15 # "mod_rewrite",
16 # "mod_redirect",
17 "mod_alias",
18 "mod_access",
19 # "mod_cml",
20 # "mod_trigger_b4_dl",
21 # "mod_auth",
22 # "mod_status",
23 # "mod_setenv",
24 # "mod_fastcgi",
25 # "mod_proxy",
26 # "mod_simple_vhost",
27 # "mod_evhost",
28 # "mod_userdir",
29 "mod_cgi",
30 # "mod_compress",
31 # "mod_ssi",
32 # "mod_usertrack",
33 # "mod_expire",
34 # "mod_secdownload",
35 # "mod_rrdtool",
36 "mod_accesslog" )
(2). 取消219~221行注释,并让".cgi" => ""指向为空如下所示:
(注 :219 可快速跳转)
217
218 #### CGI module
219 cgi.assign = ( ".pl" => "/usr/bin/perl",
220 ".cgi" => "" )
221
222
223 #### SSL engine
224 #ssl.engine = "enable"
225 #ssl.pemfile = "server.pem"
226
按ESC键,:wq 保存退出。
3. 按如下指令新建相关文件及目录
mkdir -p /www/pages /www/logs
touch /www/logs/access.log
chmod 777 /www/logs/access.log
echo '<html><body><h1>It_works!</h1><p>Lighttpd_start_success!</p></body></html>' > index.html
4. vim /www/pages/a.c 新建C语言文件,粘贴如下代码:
#include <stdio.h>
int main(int argc, char **argv)
{
printf("Content-type:text/html\n\n");
printf("hello_cgi\n");
return 0;
}
5. gcc /www/pages/a.c -o /www/pages/a.cgi
终端中输入 /www/pages/a.cgi 显示:
Content-type:text/html
hello_cgi
三、运行启动和校验
1. lighttpd -f /etc/lighttpd.conf //启动 lighttpd服务器
也可以 echo 'lighttpd -f /etc/lighttpd.conf' >> /etc/profile 然后重启动,这样,每次开机,服务器就自动启动了。
2. windows端或其它桌面系统打开网页浏览器输入如下标红的地址校验
四、安装CGIC头文件及库文件
1、解压 unzip cgic207.zip 并进入cgic207目录
执行:(注:cgic没有./configure)
make
make install
2、应用cgic编程
参考:https://blog.youkuaiyun.com/qq_35881819/article/details/77131130