安裝Apache(httpd)

安裝Apache

apr和apr-util是一個通用函數庫,他能讓httpd不去關心底層的操作系統平臺,可以很方便的移植(linux到Windows)

源碼包安裝httpd(2.4.29):

httpd源碼包 
apr包 
apr-util包

下載包到/usr/local/src/下:

[root@shuai-01 src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.29.tar.gz
[root@shuai-01 src]# wget http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz
[root@shuai-01 src]# wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.bz2
[root@shuai-01 src]# ls              httpd-2.2.34.tar.gz
apr-1.6.3.tar.gz        httpd-2.4.29.tar.gz
apr-util-1.6.1.tar.bz2  mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
httpd-2.2.34            mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz

解壓軟件包:

[root@shuai-01 src]# tar zxvf apr-1.6.3.tar.gz
[root@shuai-01 src]# tar jxvf apr-util-1.6.1.tar.bz2
[root@shuai-01 src]# tar zxvf  httpd-2.4.29.tar.gz
[root@shuai-01 src]# ls
apr-1.6.3               httpd-2.2.34.tar.gz
apr-1.6.3.tar.gz        httpd-2.4.29
apr-util-1.6.1          httpd-2.4.29.tar.gz
apr-util-1.6.1.tar.bz2  mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
httpd-2.2.34            mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz

編譯安裝(apr):

進入apr文件裏,configure , make ,make install,每一步完成後檢查是否成功。

[root@shuai-01 src]# cd apr-1.6.3/
[root@shuai-01 apr-1.6.3]# 
[root@shuai-01 apr-1.6.3]# ./configure --prefix=/usr/local/apr

[root@shuai-01 apr-1.6.3]# echo $?
0
[root@shuai-01 apr-1.6.3]# make
[root@shuai-01 apr-1.6.3]# echo $?
0
[root@shuai-01 apr-1.6.3]# make install
[root@shuai-01 apr-1.6.3]# echo $?
0

安裝apr-util:

進入目錄:

[root@shuai-01 apr-1.6.3]# cd ../apr-util-1.6.1
[root@shuai-01 apr-util-1.6.1]# 

編譯安裝apr-util

[root@shuai-01 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@shuai-01 apr-util-1.6.1]# make
[root@shuai-01 apr-util-1.6.1]# echo $?
0
[root@shuai-01 apr-util-1.6.1]# make install

問題:xml/apr_xml.c:35:19: 致命錯誤:expat.h:沒有那個文件或目錄 #include expat.h

解決:缺少expat-devel包

    yum install expat-devel

安裝httpd:

進入httpd-2.4.29目錄下

[root@shuai-01 src]# cd httpd-2.4.29/
[root@shuai-01 httpd-2.4.29]# 
[root@shuai-01 httpd-2.4.29]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
[root@shuai-01 apr-util-1.6.1]# make
[root@shuai-01 apr-util-1.6.1]# echo $?
0
[root@shuai-01 apr-util-1.6.1]# make install

[root@shuai-01 apache2.4]# ls
bin    cgi-bin  error   icons    lib   man     modules
build  conf     htdocs  include  logs  manual

bin 可執行文件存放目錄 (bin/httpd 起動文件的目錄) 
conf 配置文件所在目錄 
htdocs 存放訪問頁面(默認網站) 
logs 日誌相關的目錄(錯誤日誌,訪問日誌) 
modules 存放模塊

查看Apache加載那些模塊

[root@shuai-01 apache2.4]# /usr/local/apache2.4/bin/httpd -M
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::4f59:7251:18f1:8716. Set the 'ServerName' directive globally to suppress this message
Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 mpm_event_module (static)
 authn_file_module (shared)
 authn_core_module (shared)
 authz_host_module (shared)
 authz_groupfile_module (shared)
 authz_user_module (shared)
 authz_core_module (shared)
 access_compat_module (shared)
 auth_basic_module (shared)
 reqtimeout_module (shared)
 filter_module (shared)
 mime_module (shared)
 log_config_module (shared)
 env_module (shared)
 headers_module (shared)
 setenvif_module (shared)
 version_module (shared)
 unixd_module (shared)
 status_module (shared)
 autoindex_module (shared)
 dir_module (shared)
 alias_module (shared)

啓動Apache

[root@shuai-01 apache2.4]# /usr/local/apache2.4/bin/apachectl start

[root@shuai-01 apache2.4]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1505/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2239/master         
tcp6       0      0 :::80                   :::*                    LISTEN      64263/httpd         
tcp6       0      0 :::22                   :::*                    LISTEN      1505/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      2239/master  

httpd默認監聽80端口, 
sshd默認監聽22端口 
mysqld默認監聽3306端口 
25端口是發郵件的

問題2:checking for APR-util… configure: error: the –with-apr-util parameter is incorrect

[root@getlnx05 httpd-2.4.6]#  ./configure --prefix=/usr/local/apache  --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... x86_64-unknown-linux-gnu

checking host system type... x86_64-unknown-linux-gnu

checking target system type... x86_64-unknown-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"

  setting LDFLAGS to " "

configure:

configure: Configuring Apache Portable Runtime Utility library...

configure:

checking for APR-util... configure: error: the --with-apr-util parameter is incorrect. It must specify an install prefix, a build directory, or an apu-config file.

[root@getlnx05 httpd-2.4.6]#

一般是由於APR-util沒有安裝成功,可以通過驗證該目錄是否爲空來判斷,因爲你有時候執行了make,忘了執行make isntall命令有可能導致這個錯誤。

[root@getlnx05 apr]# cd /usr/local/apr-util

[root@getlnx05 apr-util]# ls

問題三:configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

沒有pcre包, 
查找包

[root@shuai-01 httpd-2.4.29]# yum list |grep pcre

一般的lib庫,通常帶有lib , devel後綴。

安裝包:

[root@shuai-01 httpd-2.4.29]# yum install -y pcre-devel

問題4:

./configure沒有報錯,執行make時報錯,如下:

make[2]: * [exports.lo] Error 1

make[2]: Leaving directory `/usr/local/src/httpd-2.4.7/server’

make[1]: * [all-recursive] Error 1

make[1]: Leaving directory `/usr/local/src/httpd-2.4.7/server’

make: * [all-recursive] Error 1

之前apr,apr-util都編譯安裝成功。 
編譯參數:

./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util  --enable-so --enable-mods-shared=most

解決方案: 
先退出編譯安裝:

make clean

在./configure 參數後面加上 ‘–with-included-apr’參數,再次進行編譯

[root@shuai-01 httpd-2.4.29]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-included-apr --enable-so --enable-mods-shared=most 

這時又出現另一個報錯。錯誤如下:

configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.

然後將apr包和apr-util包拷貝到/usr/local/src/httpd-2.4.29/srclib/目錄下:

[root@shuai-01 httpd-2.4.29]# cp -r apr-1.6.3 /usr/local/src/httpd-2.4.29/srclib/apr
[root@shuai-01 httpd-2.4.29]# cp -r apr-util-1.6.1 /usr/local/src/httpd-2.4.29/srclib/apr-util

重新執行編譯命令

[root@shuai-01 httpd-2.4.29]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-included-apr --enable-so --enable-mods-shared=most 

編譯完成,接着make也成功。

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