httpd-2.4.1.tar.gz http://httpd.apache.org/download.cgi
1.# 将文件cp到/usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# tar -zxvf httpd-2.4.1.tar.gz
[root@localhost local]# cd httpd-2.4.1
[root@localhost httpd-2.4.1]# ./configure --prefix=/usr/loca/httpd-apache/ --enable-modules=most --enable-mods-shared=most --with-mpm=prefork --enable-so --enable-rewrite
# 上面请特别注意到:
--prefix=/安装的路径:设置apache安装路径
--enable-so :这个项目则是在宣告使用动态函式库!特别重要!
--enable-rewrite :这个项目只是预防用的!可以先设定,不过不一定会用到!
--enable :表示需要启用的模块,可以自行增减
2.# 而且在此处可能会出现错误
# checking for APR...no
# 下载apr-1.4.6.tar.gz http://apr.apache.org/download.cgi
# 同样放在/usr/local/
[root@localhost httpd-2.4.1]# cd /usr/local
[root@localhost local]# tar -zxvf apr-1.4.6.tar.gz
[root@localhost local]# cd apr-1.4.6
# 将apr-1.4.6安装在/usr/local/apr下面
[root@localhost apr-1.4.6]# ./configure
[root@localhost apr-1.4.6]# make && make install
# 安装完成后继续
[root@localhost apr-1.4.6]# cd ../httpd-2.4.1
[root@localhost httpd-2.4.1]# ./configure --prefix=/usr/loca/httpd-apache/ --enable-modules=most --enable-mods-shared=most --with-mpm=prefork --enable-so --enable-rewrite
3.# 此处可能还会出现错误
checking for APR-util...no
# 继续下载安装文件
# 下载apr-util-1.4.1.tar.gz http://apr.apache.org/download.cgi
# 同样放在/usr/local/
[root@localhost httpd-2.4.1]# cd /usr/local
[root@localhost local]# tar -zxvf apr-util-1.4.1.tar.gz
[root@localhost local]# cd apr-util-1.4.1
# 安装apr-util-1.4.1
[root@localhost apr-util-1.4.1]# ./configure --with-apr=/usr/local/apr
[root@localhost apr-util-1.4.1]# make && make install
# 安装完成后继续
[root@localhost apr-1.4.6]# cd ../httpd-2.4.1
[root@localhost httpd-2.4.1]# ./configure --prefix=/usr/loca/httpd-apache/ --enable-modules=most --enable-mods-shared=most --with-mpm=prefork --enable-so --enable-rewrite
shared=all --with-ssl=/usr/local/openssl/ --enable-track-vars --enable-rewrite
4.# 可能还会报错
# 安装pcre-8.30.tar.gz http://pcre.org
# 同样放在/usr/local/
[root@localhost httpd-2.4.1]# cd /usr/local
[root@localhost local]# tar -zxvf pcre-8.30.tar.gz
[root@localhost local]# cd pcre-8.30
# 安装apr-util-1.4.1
[root@localhost pcre-8.30]# ./configure --with-apr=/usr/local/apr
[root@localhost pcre-8.30]# make && make install
# 继续
[root@localhost apr-1.4.6]# cd ../httpd-2.4.1
[root@localhost httpd-2.4.1]# ./configure --prefix=/usr/loca/httpd-apache/ --enable-modules=most --enable-mods-shared=most --with-mpm=prefork --enable-so --enable-rewrite
[root@localhost httpd-2.4.1]# make && make install
# OK
[root@localhost apr]# cd ../httpd-apache/
# 启动Apache
[root@localhost httpd-apache]# /usr/local/httpd-apache/bin/apachectl start
[root@localhost httpd-apache]# netstat -an |grep 80
# 打开浏览器,输入http://localhost(或者IP地址)
# 出现 It works!
# 至此,Apache安装完成
将apache注册为系统服务并开机启动:
1.设置开机启动
在/etc/rc.d/rc.local中增加启动apache的命令,例如:/usr/local/httpd/bin/apachectl start
2.注册为系统服务
把上面apache启动脚本apachectl复制到 /etc/rc.d/init.d/目录下,并重命名为httpd
使用编辑器打开httpd文件,并在第一行#!/bin/sh下增加两行文字如下(这是必需的,否则会报httpd不支持chkconfig)
# chkconfig: 35 70 30
# description: Apache
接着注册该服务
chkconfig --add httpd
一切OK了,启动服务
service httpd start
其中所增加的第二行中三个数字第一个表示在运行级别3和5下启动apache,第二、三是关于启动和停止的优先级配置,无关紧要。
编译的httpd不支持chkconfig的解决方法
用chkconfig将自编译设置为系统服务的时候,httpd 服务不支持 chkconfig。
解决过程如下:
1.编辑/etc/init.d/httpd
#!/bin/bash
#chkconfig:345 61 61
#description:Apache httpd
2.配置
[root@localhost ~]# chkconfig --add httpd
[root@localhost ~]# chkconfig --list|grep httpd
httpd 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
[root@localhost ~]# chkconfig --level 345 httpd on
[root@localhost ~]# chkconfig --list|grep httpd
httpd 0:关闭 1:关闭 2:关闭 3:启用 4:启用 5:启用 6:关闭