ubuntu装配啊pache2全套安装过程+源码包
在Ubuntu 6.1版本上进行Rails部署,由于需要配置实现一个Apache
Server对多个Mongrel的均衡负载,而原来安装的Apache2.0.55版本不支持BalancerMember特性(需Apache
2.2+版本),因此决定对系统上的Apahce进行升级。
2.0升级到2.2的详细变动信息可以参照Apache的文档
。
首先尝试用apt-get来升级,
- sudo apt-get install apache2
不料Ubuntu下载下来的还是旧的Apache2.0版本,因此决定下载Apache2.2的安装包,手动安装。
1. 下载安装包
- wget -c http: //apache.mirror.phpchina.com/httpd/httpd-2.2.6.tar.gz
http://apache.mirror.phpchina.com
是在中国比较快的Apache镜像,如果要选择其它镜像,可以到http://httpd.apache.org/download.cgi
查看。
2. 解压安装包
- tar -xvf httpd- 2.2 . 6 .tar.gz
解压后可以看到当前目录下新建了httpd-2.2.6目录。
3. 进入该目录
- cd httpd- 2.2 . 6
4. 执行configure命令进行配置
我的配置命令是
- ./configure --enable-cache --enable-mem-cache --enable-deflate --enable-proxy --enable-proxy-html --enable-proxy-balancer --enable-rewrite --enable-so
配置时可以设定./configure --prefix=PREFIX的PREFIX选项来指定安装目录,默认的安装目录是/usr/local/apache2,后面的enable选项指定了要安装的模块。如果需要更详细的配置信息可以参照这里
。
#./configure --prefix……检查编辑环境时出现:
checking for APR... no
configure: error: APR not found
. Please read the documentation.
可以用./configure –help | grep apr
查看帮助。
--with-included-apr Use bundled copies of APR/APR-Util
--with-apr=PATH prefix for installed APR or the full path to apr-config
--with-apr-util=PATH prefix for installed APU or the full path to
安装APR(Apache Portable Runtime )
[root@localhost ~]# cd /tmp/52lamp/ //源码存放位置
[root@localhost 52lamp]# tar -zxvf apr-1.4.2.tar.gz //unzip -o apr-1.4.2.zip
[root@localhost 52lamp]# cd apr-1.4.2
[root@localhost apr-1.4.2]# ./configure
[root@localhost apr-1.4.2]# make
[root@localhost apr-1.4.2]# make install
再次检查编译环境出现
checking for APR-util... no
configure: error: APR-util not found
. Please read the documentation.
[root@localhost httpd-2.2.16]# ./configure –help | grep apr-util
--with-apr-util=PATH prefix for installed APU or the full path to
[root@localhost 52lamp]# tar -zxvf apr-util-1.3.9.tar.gz
[root@localhost 52lamp]# cd apr-util-1.3.9
[root@localhost apr-util-1.3.9]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.3.9]# make
[root@localhost apr-util-1.3.9]# make install
./configure仍提示APR-util not found,增加--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util后出现
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
[root@localhost httpd-2.2.16]# ./configure –help | grep pcre
--with-pcre=PATH Use external PCRE library
[root@localhost 52lamp]# unzip -o pcre-8.10.zip
[root@localhost 52lamp]# cd pcre-8.10
[root@localhost cd pcre-8.10]# ./configure --prefix=/usr/local/pcre
[root@localhost cd pcre-8.10]# make
[root@localhost cd pcre-8.10]# make install
继续安装Apache/httpd,./configure 时加上参数 --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre,这个问题就解决了。
Apache安装过程,Apr、apr-util、pcre下载详见本站其他页面。5. 编译
- make
6. 安装,先切换到安装目录(PREFIX指定的目录),执行命令
- make install
7. 测试安装结果,先运行
- killall httpd
终止所有正在运行的apache httpd进程,之后可以通过执行命令
- /usr/local/apache2/bin/apachectl -k start
- /usr/local/apache2/bin/apachectl -k stop
8. 这时候机器上仍然装有原来的Apache2.0版本,因此需要将旧版本从启动目录中移除。
- rm -d /etc/init.d/apache2
- rm -d /etc/init.d/apachectl
9.编写启动脚本,命名为apache2,保存至/etc/init.d,内容如下
- #!/bin/bash
- #description:http server
- #chkconfig: 235 98 98
- case "$1" in
- start)
- echo "Starting Apache daemon..."
- /usr/local/apache2/bin/apachectl -k start
- ;;
- stop)
- echo "Stopping Apache daemon..."
- /usr/local/apache2/bin/apachectl -k stop
- ;;
- restart)
- echo "Restarting Apache daemon..."
- /usr/local/apache2/bin/apachectl -k restart
- ;;
- status)
- statusproc /usr/local/apache2/bin/httpd
- ;;
- *)
- echo "Usage: $0 {start|stop|restart|status}"
- exit 1
- ;;
- esac
10. 修改原apache2命令对应的可执行文件,执行
- which apache2
找到旧的apache2命令对应的可执行文件路径,如/usr/sbin/apache2,进入/usr/sbin目录,删除原来的可执行文件,同时建立符号链接指向刚才创建的apache2
- rm -d apache2
- ln -s /etc/init.d/apache2 /usr/sbin/apache2
这时候就可以通过apache2 start|stop|restart|status来分别启动、停止、重启apache服务和查看apache的运行状态了。