一、編譯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