源码安装apache

源码安装Apache步骤


1、卸载原有的apache

2、安装编译环境

3、下载apache源码包

4、安装源码包

5、 测试apache


一、卸载原有apache

[root@admxj yum.repos.d]# rpm -qa | grep httpd
httpd-tools-2.2.15-47.el6.centos.1.i686
httpd-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源码包

建议大家去官网下载 http://httpd.apache.org/download.cgi

我这里是以2.4为例 http://mirrors.noc.im/apache//httpd/httpd-2.4.18.tar.gz

[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/httpd
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... no
configure: 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... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
configure: 
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... no
configure: 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-util
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking for working mkdir -p... yes
APR-util Version: 1.5.4
checking for chosen layout... apr-util
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
Applying apr-util hints file rules for i686-pc-linux-gnu
checking for APR... no
configure: 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... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
configure: 
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... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for gcc option to accept ISO C99... -std=gnu99
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
[root@admxj httpd-2.4.18]#

继续报错 找不到pcre这个包

我们去下载pcre这个安装包 ftp://ftp.csx.cam.ac.uk/pub/software/programming/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/pcre
configure: 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

通过浏览器访问可以正常显示 大功告成, 接下来配置。。。。。。。。。。wKiom1adyIyxjbgmAAA6Hmtm_IQ185.png


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章