源碼安裝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


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