一、编译httpd
1、安装依赖包
# yum -y install pcre-devel openssl-devel
2、httpd依赖apr和apr-util
# tar xf apr-1.5.1.tar.bz2
# cd apr-1.5.1
# ./configure --prefix=/usr/local/apr
# make && make install
# tar xf apr-util-1.5.4.tar.bz2
# cd apr-util-1.5.4
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
# make && make install
3、httpd编译安装
# tar xf httpd-2.4.12.tar.bz2
# cd httpd-2.4.12
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd-2.4.12 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=event
# make && make install
4、导出头文件
# ln -sv /usr/local/apache/include /usr/include/httpd
5、导出man手册
# vim /etc/man.conf
MANPATH /usr/local/apache/man
MANPATH /usr/man
MANPATH /usr/share/man
MANPATH /usr/local/man
MANPATH /usr/local/share/man
MANPATH /usr/X11R6/man
添加红色行
6、 输出二进制程序
# vim /etc/profile.d/httpd.sh
export PATH=/usr/local/apache/bin:$PATH
7、修改启动脚本
# cp -a /etc/init.d/httpd{,24}
#vim /etc/init.d/httpd24
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}
修改红色行
8、修改httpd配置文件
# vim /etc/httpd-2.4.12/httpd.conf
Pidfile "/var/run/httpd/httpd.pid"
User apache
Group apache
修改红色行
9、测试httpd服务是否正常
# /etc/init.d/httpd24 start
#/etc/init.d/httpd24 restart
二、使用CGI
1、加载mod_cgi模块
# vim /etc/httpd-2.4.12/httpd.conf
#LoadModule cgi_module modules/mod_cgi.so
将此行的#号去掉
2、开启访问权限
<Directory />
AllowOverride none
Require all granted
</Directory>
此处红色部分默认是拒绝所有,改为granted
<Directory "/usr/local/apache/cgi-bin">
AllowOverride None
Options ExecCGI
Require all granted
</Directory>
3、修改cgi测试脚本的相关权限
/usr/local/apache/cgi-bin目录下默认有一个test-cgi脚本
# cd /usr/local/apache/agi-bin
# chown :root test-cgi
# chmod +x test-cgi
# /etc/init.d/httpd24 restart
4、向test-cgi中添加内容
在开头添加一行
# vim test-cgi
#!/bin/bash
echo "Content-type: text/plain; charset=iso-8859-1"
echo
第二个echo行留空白,不要将空白行删掉
5、访问网站测试
http://IP/cgi-bin/test-cgi