先下载源码包
解压:
tar zxvf httpd-2.2.9.tar.gz –C /usr/src
cd /usr/src/httpd-2.2.9
./configure –prefix=/usr/local/apache2 –enable-so—enable-rewrite
--prefix 用于指定httpd程序将要安装到的系统目录
--enable-so 使httpd功能能够动态加载模块功能
--enable-rewrite 使httpd具有rewrite网页地址重写功能。
编译并安装
Make && make install
cd /usr/local/apache2/
vi /usr/local/apache2/conf/httpd.conf
检查httpd.conf主配置文件是存在语法错误
/usr/local/apache2/bin/apachectl –l
/usr/local/apache2/bin/httpd -t
启动httpd服务
/usr/local/apache2/bin/apachectl start
设置在服务器开机后自动启动httpd服务
vi /etc/rc.d/rc.local
/usr/local/apache2/bin/apachectl start
Httpd.conf 配置文件结构
[root@localhost conf]# cd /usr/local/apache2/conf/
[root@localhost conf]# cp httpd.conf httpd.conf.bak
去除httpd.conf文件中的注释行及空白内容,保留有效的配置信息。
[root@localhost conf]# grep -v "#" httpd.conf.bak | grep -v "^$" > httpd.conf
[root@localhost conf]# cat httpd.conf
网页存放位置
documentRoot "/usr/local/apache2/htdocs"
directoryIndex index.html index.htm index.php
访问日志文件
tail -2 /usr/local/apache2/logs/access_log
错误日志文件
tail -2 /usr/local/apache2/logs/error_log