源码安装Apache步骤
1、卸载原有的apache
2、安装编译环境
3、下载apache源码包
4、安装源码包
5、 测试apache
一、卸载原有apache
[root@admxj yum.repos.d]# rpm -qa | grep httpdhttpd-tools-2.2.15-47.el6.centos.1.i686httpd-2.2.15-47.el6.centos.1.i686[root@admxj yum.repos.d]# rpm -e httpd-tools-2.2.15-47.el6.centos.1.i686 httpd-2.2.15-47.el6.centos.1.i686[root@admxj yum.repos.d]#
二、安装编译环境
[root@admxj yum.repos.d]# yum -y install gcc gcc++ zlib zlib-devel
三、下载apache源码包
建议大家去官网下载
我这里是以2.4为例
[root@admxj yum.repos.d]# cd /opt/[root@admxj yum.repos.d]# wget http://mirrors.noc.im/apache//httpd/httpd-2.4.18.tar.gz
四、安装acpache源码包
[root@admxj opt]# tar -zxvf httpd-2.4.18.tar.gz [root@admxj opt]# cd httpd-2.4.18
编译
[root@admxj httpd-2.4.18]# ./configure --prefix=/usr/local/httpdchecking for chosen layout... Apachechecking for working mkdir -p... yeschecking for grep that handles long lines and -e... /bin/grepchecking for egrep... /bin/grep -Echecking build system type... i686-pc-linux-gnuchecking host system type... i686-pc-linux-gnuchecking target system type... i686-pc-linux-gnuconfigure: configure: Configuring Apache Portable Runtime library...configure: checking for APR... noconfigure: error: APR not found. Please read the documentation.[root@admxj httpd-2.4.18]#
报错了! 提示我们找不到APR
我们接着安装APR
[root@admxj httpd-2.4.18]# cd /opt/[root@admxj opt]# wget [root@admxj opt]# tar -zxvf apr-1.5.2.tar.gz[root@admxj opt]# cd apr-1.5.2[root@admxj apr-1.5.2]# ./configure --prefix=/usr/local/apr[root@admxj apr-1.5.2]# make[root@admxj apr-1.5.2]# make install
APR安装OK了
继续安装apache configure 里面多加一条--with-apr=/usr/local/apr/
[root@admxj apr-1.5.2]# cd /opt/httpd-2.4.18[root@admxj httpd-2.4.18]# ./configure --prefix=/usr/local/httpd --enable-rewrite --enable-so --with-apr=/usr/local/apr/checking for chosen layout... Apachechecking for working mkdir -p... yeschecking for grep that handles long lines and -e... /bin/grepchecking for egrep... /bin/grep -Echecking build system type... i686-pc-linux-gnuchecking host system type... i686-pc-linux-gnuchecking target system type... i686-pc-linux-gnuconfigure: configure: Configuring Apache Portable Runtime library...configure: checking for APR... yes setting CC to "gcc" setting CPP to "gcc -E" setting CFLAGS to " -g -O2 -pthread" setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE" setting LDFLAGS to " "configure: configure: Configuring Apache Portable Runtime Utility library...configure: checking for APR-util... noconfigure: error: APR-util not found. Please read the documentation.[root@admxj httpd-2.4.18]#
继续报错 找不到 APR-util 我们去安装APR-util
[root@admxj opt]# wget [root@admxj opt]# tar -zxvf apr-util-1.5.4.tar.gz[root@admxj opt]# cd apr-util-1.5.4[root@admxj apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-utilchecking build system type... i686-pc-linux-gnuchecking host system type... i686-pc-linux-gnuchecking target system type... i686-pc-linux-gnuchecking for a BSD-compatible install... /usr/bin/install -cchecking for working mkdir -p... yesAPR-util Version: 1.5.4checking for chosen layout... apr-utilchecking for gcc... gccchecking whether the C compiler works... yeschecking for C compiler default output file name... a.outchecking for suffix of executables... checking whether we are cross compiling... nochecking for suffix of object files... ochecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yeschecking for gcc option to accept ISO C89... none neededApplying apr-util hints file rules for i686-pc-linux-gnuchecking for APR... noconfigure: error: APR could not be located. Please use the --with-apr option.[root@admxj apr-util-1.5.4]#
APR-uilt 早不到apr 我们加上一个参数 --with-apr=/usr/local/apr
[root@admxj apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/[root@admxj apr-util-1.5.4]# make[root@admxj apr-util-1.5.4]# make install
我们继续按照apache 再多加一个参数 --with-apr-util=/usr/local/apr-util
[root@admxj apr-util-1.5.4]# cd /opt/httpd-2.4.18[root@admxj httpd-2.4.18]# ./configure --prefix=/usr/local/httpd --enable-rewrite --enable-so --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/checking for chosen layout... Apachechecking for working mkdir -p... yeschecking for grep that handles long lines and -e... /bin/grepchecking for egrep... /bin/grep -Echecking build system type... i686-pc-linux-gnuchecking host system type... i686-pc-linux-gnuchecking target system type... i686-pc-linux-gnuconfigure: configure: Configuring Apache Portable Runtime library...configure: checking for APR... yes setting CC to "gcc" setting CPP to "gcc -E" setting CFLAGS to " -g -O2 -pthread" setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE" setting LDFLAGS to " "configure: configure: Configuring Apache Portable Runtime Utility library...configure: checking for APR-util... yeschecking for gcc... gccchecking whether the C compiler works... yeschecking for C compiler default output file name... a.outchecking for suffix of executables... checking whether we are cross compiling... nochecking for suffix of object files... ochecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yeschecking for gcc option to accept ISO C89... none neededchecking how to run the C preprocessor... gcc -Echecking for gcc option to accept ISO C99... -std=gnu99checking for pcre-config... falseconfigure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/[root@admxj httpd-2.4.18]#
继续报错 找不到pcre这个包
我们去下载pcre这个安装包
[root@admxj httpd-2.4.18]# cd /opt/[root@admxj opt]# wget [root@admxj opt]# tar -zxvf pcre-8.38.tar.gz [root@admxj opt]# cd pcre-8.38[root@admxj pcre-8.38]# ./configure --prefix=/usr/local/pcreconfigure: error: You need a C++ compiler for C++ support
依旧是报错,提示我们缺少c++包 这里我们就直接yum
[root@admxj pcre-8.38]# yum install gcc-c++[root@admxj pcre-8.38]# ./configure --prefix=/usr/local/pcre[root@admxj pcre-8.38]# make[root@admxj pcre-8.38]# make install
我们回去安装apache 再加一个参数 --with-pcre=/usr/local/pcre
[root@admxj pcre-8.38]# cd /opt/httpd-2.4.18[root@admxj httpd-2.4.18]# ./configure --prefix=/usr/local/httpd --enable-rewrite --enable-so --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre/
终于没有报错了 继续编译 -j4 启用4个cpu去编译。提高编译速度。
[root@admxj httpd-2.4.18]# make -j4[root@admxj httpd-2.4.18]# make install
安装完成
五、测试apache
[root@admxj httpd-2.4.18]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd//把 ServerName 前面的#去掉 [root@admxj httpd-2.4.18]# vi /usr/local/httpd/conf/httpd.conf //启动httpd[root@admxj httpd-2.4.18]# /etc/init.d/httpd restart//防火墙添加80端口[root@admxj httpd-2.4.18]# vi /etc/sysconfig/iptables[root@admxj httpd-2.4.18]# service iptables restart
通过浏览器访问可以正常显示 大功告成, 接下来配置。。。。。。。。。。