- 安装apache2
sudo apt-get install apache2
- 分析文件夹
- 配置的文件夹位置/etc/apache2/
- html文件夹位置/var/www/html/
- cgi文件夹位置** /usr/lib/cgi-bin**
- 这部分很多的网上帖子把文件位置说成是/var/www/cgi-bin ,当然这是可以修改的,我上述所说是默认文件位置。还有网上的帖子将/cgi-bin写成/bin-cgi ,对于老手来说没什么,对于我这个新手来说可是踩了很多坑。
- 配置文件
cd /etc/apache2
ls -l
-rw-r--r-- 1 root root 7224 12月 3 23:55 apache2.conf
drwxr-xr-x 2 root root 4096 3月 16 16:52 conf-available
drwxr-xr-x 2 root root 4096 3月 16 16:28 conf-enabled
-rw-r--r-- 1 root root 1782 7月 17 2019 envvars
-rw-r--r-- 1 root root 31063 7月 17 2019 magic
drwxr-xr-x 2 root root 12288 3月 16 16:28 mods-available
drwxr-xr-x 2 root root 4096 3月 16 16:35 mods-enabled
-rw-r--r-- 1 root root 320 7月 17 2019 ports.conf
drwxr-xr-x 2 root root 4096 3月 16 16:28 sites-available
drwxr-xr-x 2 root root 4096 3月 16 16:28 sites-enabled
- 可以看到这两个文件夹 ” **mods-enabled **“ 和 ” **mods-available **“其中 ” **mods-enabled **“ 为常用的(也就是默认开启的), ” **mods-available **“为不常用的(也就是默认不开启)
- " cd /mods-available " 进入该目录,输入 " ls cgi. " 查找带cgi的文件,可以找到 " cgid.conf* “, “**cgid.load **”, " cgi.load “, " **proxy_fcgi.load ", " proxy_scgi.load **“中 “**proxy_fcgi.load ", " proxy_scgi.load **” 我们暂不用,只需要前三个 " cgid.conf”, " **cgid.load **”, " cgi.load” 就可以了
- 接下来,使用 " ln -s . . " 将这三个文件软链接到 " **mods-enabled **" 目录下
ln -s /etc/apache2/mods-available/cgid.conf /etc/apache2/mods-enabled/cgid.conf
ln -s /etc/apache2/mods-available/cgid.load /etc/apache2/mods-enabled/cgid.load
ln -s /etc/apache2/mods-available/cgi.load /etc/apache2/mods-enabled/cgi.load
- "
sudo /etc/init.d/apache2 restart
" 重启apache服务 - 进入目录
cd /usr/bin/cgi-bin
vim test.c
/*************************************************************************
> File Name: test.c
> Author: houwenzhi
> Mail: houwenzhi@163.com
> Created Time: 2020年03月16日 星期一 16时55分53秒
************************************************************************/
#include<stdio.h>
int main()
{
printf("Content-Type: \n\n\n");
printf("Hello, world\n");
return 0;
}
* 编译
`gcc test.c -o test.cgi`
- 修改生成文件的权限
sudo chmod 755 test.cgi
- 打开浏览器访问
http://localhost/cgi-bin/test.cgi - cgi的配置使用,使嵌入式系统开发时更加的便捷,它不仅可以支持C语言还支持PYTHON、shell等