Apache Linux下Apache安裝步驟


Apache簡介

         Apache HTTP Server(簡稱Apache)是Apache軟件基金會的一個開放源碼的網頁服務器,可以在大多數計算機操作系統中運行,由於其多平台和安全性被廣泛使用,是最流行的Web服務器端軟件之一。它快速、可靠並且可通過簡單的API擴展,將Perl/Python等解釋器編譯到服務器中。關於更多Apache的介紹,可以參考百科“http://baike.baidu.com/view/28283.htm或官網http://www.apache.org/ 或 http://httpd.apache.org/的介紹。

 

Apache相關軟件下載

  Apache的相關軟件包下載地址http://apr.apache.org/projects.html

1.   Apache HTTP Server

    截止目前為止,Apache HTTP Server 目前最新的版本是 Apache httpd 2.4.6 Released, 下載地址:http://httpd.apache.org/download.cgi#apache24

2.   APR and APR-Util包

    截止目前為止,APR and APR-Util的最新版本如下,下載地址:http://apr.apache.org/download.cgi

  • APR 1.4.8, released June 21, 2013
  • APR-util 1.5.2, released April 4, 2013
  • APR-iconv 1.2.1, released November 26, 2007

3.   PCRE包

   截止目前為止,PCRE最新的包為8.33,下載地址如下

   可以下載了相關安裝包,上傳到/root/kerry這個臨時目錄。也可以直接通過wget下載。

 

Apache安裝要求

下面是官方文檔的要求,必須安裝APR、APR-Util、PCRE,gcc-c++等包,文檔URL地址http://httpd.apache.org/docs/2.4/install.html

 Requirements

The following requirements exist for building Apache httpd:

APR and APR-Util

Make sure you have APR and APR-Util already installed on your system. If you don't, or prefer to not use the system-provided versions, download the latest versions of both APR and APR-Util from Apache APR, unpack them into ./srclib/apr and ./srclib/apr-util (be sure the directory names do not have version numbers; for example, the APR distribution must be under ./srclib/apr/) and use ./configure's --with-included-apr option. On some platforms, you may have to install the corresponding -dev packages to allow httpd to build against your installed copy of APR and APR-Util.

Perl-Compatible Regular Expressions Library (PCRE)

This library is required but not longer bundled with httpd. Download the source code from http://www.pcre.org, or install a Port or Package. If your build system can't find the pcre-config script installed by the PCRE build, point to it using the --with-pcre parameter. On some platforms, you may have to install the corresponding -dev package to allow httpd to build against your installed copy of PCRE.

Disk Space

Make sure you have at least 50 MB of temporary free disk space available. After installation the server occupies approximately 10 MB of disk space. The actual disk space requirements will vary considerably based on your chosen configuration options, any third-party modules, and, of course, the size of the web site or sites that you have on the server.

ANSI-C Compiler and Build System

Make sure you have an ANSI-C compiler installed. The GNU C compiler (GCC) from the Free Software Foundation (FSF) is recommended. If you don't have GCC then at least make sure your vendor's compiler is ANSI compliant. In addition, your PATH must contain basic build tools such as make.

Accurate time keeping

Elements of the HTTP protocol are expressed as the time of day. So, it's time to investigate setting some time synchronization facility on your system. Usually thentpdate or xntpd programs are used for this purpose which are based on the Network Time Protocol (NTP). See the NTP homepage for more details about NTP software and public time servers.

Perl 5 [OPTIONAL]

For some of the support scripts like apxs or dbmmanage (which are written in Perl) the Perl 5 interpreter is required (versions 5.003 or newer are sufficient). If you have multiple Perl interpreters (for example, a systemwide install of Perl 4, and your own install of Perl 5), you are advised to use the --with-perl option (see below) to make sure the correct one is used by configure. If no Perl 5 interpreter is found by the configure script, you will not be able to use the affected support scripts. Of course, you will still be able to build and use Apache httpd.

 

安裝提示

Linux下,源碼的安裝一般由3個步驟組成:配置(configure)、編譯(make)、安裝(make install)

過程中用到“configure --prefix=安裝目錄 --with-name=依賴庫源碼解壓目錄”;其中--prefix指的是安裝目錄,--with指的是安裝本文件所依賴的庫文件。

安裝httpd時,進行指定安裝,用到./configure --prefix

具體解釋:“.”表示當前目錄;“/”是目錄分隔符;合起來就是當前目錄下。

1)如不指定prefix,則可執行文件默認放在/usr/local/bin,庫文件默認放在/usr/local/lib,配置文件默認放在/usr/local/etc,其它的資源文件放在/usr /local/share。如果你要卸載這個程序,要么在原來的make目錄下用一次make uninstall(前提是make文件指定過uninstall),要么去上述目錄里面把相關的文件一個個手工刪掉。

2)如指定prefix,直接刪掉一個文件夾就夠了。

注:
./configure的作用是檢測系統配置,生成makefile文件,以便你可以用make和make install來編譯和安裝程序。

./configure是源代碼安裝的第一步,主要的作用是對即將安裝的軟件進行配置,檢查當前的環境是否滿足要安裝軟件的依賴關系,但並不是所有的tar包都是源代碼的包。

你可以先命令ls,看有沒有configure或者makefile文件。

1)如果有configure,就./configure,有很多參數。如果系統環境合適,就會生成makefile,否則會報錯。

2)如果有makefile,就直接make,然后make install。

你還可以用rpm或者deb包來安裝。而且現在的發行版都有自己的包管理器,比如apt或yum,一個命令就可以從源下載軟件,還可以自動解決依賴問題。

 

Apache安裝過程

 Step 1:安裝包gccgcc-c++

[root@getlnx05 pcre-8.33]# yum list gcc-c++

Loaded plugins: product-id, security, subscription-manager

Updating Red Hat repositories.

Available Packages

gcc-c++.x86_64                                                               4.1.2-51.el5                                                                rhel-debuginfo

[root@getlnx05 pcre-8.33]# yum list gcc

Loaded plugins: product-id, security, subscription-manager

Updating Red Hat repositories.

Installed Packages

gcc.x86_64                                                                    4.1.2-51.el5                                                                    installed

[root@getlnx05 pcre-8.33]# rpm -q gcc

gcc-4.1.2-51.el5

從上面可見gcc包已經安裝,缺少gcc-c++包,那么接下來安裝包gcc-c++,如果此處不安裝該包,后面安裝過程中會報錯。(編譯C)

[root@getlnx05 pcre-8.33]#yum install  gcc-c++

 

Step 2:安裝包APRAPR-Util

[root@getlnx05 kerry]# ls apr*  ("kerry"是一個路徑而已)

apr-1.4.8.tar.gz  apr-util-1.5.2.tar.gz

[root@getlnx05 kerry]#

[root@getlnx05 kerry]# tar -zxvf apr-1.4.8.tar.gz

[root@getlnx05 kerry]# cd apr-1.4.8

[root@getlnx05 apr-1.4.8]# ls

clip_image002

新建目錄/usr/local/apr,用作安裝目錄:

[root@getlnx05 apr-1.4.8]# mkdir /usr/local/apr

[root@getlnx05 apr-1.4.8]# ./configure --prefix=/usr/local/apr

clip_image004

[root@getlnx05 apr-1.4.8]# make

[root@getlnx05 apr-1.4.8]# make install

clip_image006

安裝完成后,可以驗證一下。

[ root@getlnx05 apr]# ls -lrt

total 32

drwxr-xr-x 3 root root 4096 Aug 15 06:57 include

drwxr-xr-x 3 root root 4096 Aug 15 06:57 lib

drwxr-xr-x 2 root root 4096 Aug 15 06:57 build-1

drwxr-xr-x 2 root root 4096 Aug 15 06:57 bin

[root@getlnx05 kerry]# tar -zxvf apr-util-1.5.2.tar.gz

[root@getlnx05 kerry]# cd apr-util-1.5.2

clip_image008

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

[root@getlnx05 apr-util-1.5.2]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config

clip_image010

[root@getlnx05 apr-util-1.5.2]# make

[root@getlnx05 apr-util-1.5.2]# make install

clip_image012

 

Step 3:安裝包PCRE

[root@getlnx05 kerry]# unzip pcre-8.33.zip

[root@getlnx05 kerry]# cd pcre-8.33

[root@getlnx05 pcre-8.33]# mkdir /usr/local/pcre

[root@getlnx05 pcre-8.33]# ./configure --prefix=/usr/local/pcre --with-apr=/usr/local/apr/bin/apr-1-config

clip_image014

[root@getlnx05 pcre-8.33]# make

[root@getlnx05 pcre-8.33]# make install

clip_image016

 

Step 4:安裝Apache

[root@getlnx05 kerry]# tar -zxvf httpd-2.4.6.tar.gz

[root@getlnx05  kerry]# cd httpd-2.4.6

[root@getlnx05 httpd-2.4.6]# ./configure --prefix=/usr/local/apache --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

[root@getlnx05 httpd-2.4.6]# make

[root@getlnx05 httpd-2.4.6]# make install

Step 5:啟動Apache服務

[root@getlnx05 httpd-2.4.6]#  /usr/local/apache/bin/apachectl start

用瀏覽器訪問http://localhost時提示It works!

 

Apache安裝問題集錦

 問題1:缺少包gcc-c++導致安裝包apr-util不通過

 [root@getlnx05 kerry]# unzip pcre-8.33.zip

[root@getlnx05 kerry]# cd pcre-8.33

[root@getlnx05 pcre-8.33]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config

clip_image018

一般出現這個錯誤是因為沒有安裝包gcc-c++,可以通過如下命令檢查,

[root@getlnx05 pcre-8.33]# yum list gcc-c++

Loaded plugins: product-id, security, subscription-manager

Updating Red Hat repositories.

Available Packages

gcc-c++.x86_64                                                               4.1.2-51.el5                                                                rhel-debuginfo

[root@getlnx05 pcre-8.33]# yum list gcc

Loaded plugins: product-id, security, subscription-manager

Updating Red Hat repositories.

Installed Packages

gcc.x86_64                                                                    4.1.2-51.el5                                                                    installed

[root@getlnx05 pcre-8.33]# rpm -q gcc

gcc-4.1.2-51.el5

[root@getlnx05 pcre-8.33]# rpm -q gcc-c++

 

問題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

 

問題3:沒有指定PCRE參數

[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... 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@getlnx05 httpd-2.4.6]#

 

問題4:安裝前忘了先安裝APR相關包

[root@getlnx05 httpd-2.4.6]#  ./configure --prefix=/usr/local/appache/

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... no

configure: error: APR not found.  Please read the documentation.

[root@getlnx05 httpd-2.4.6]#

 

問題5:安裝apr-util報錯 

錯誤內容:

make[1]: Entering directory `/usr/local/apr-util-1.6.1'
/bin/sh /usr/local/apr/build-1/libtool --silent --mode=compile gcc -g -O2 -pthread -DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE -I/usr/local/apr-util-1.6.1/include -I/usr/local/apr-util-1.6.1/include/private -I/usr/local/apr/include/apr-1 -o xml/apr_xml.lo -c xml/apr_xml.c && touch xml/apr_xml.lo
xml/apr_xml.c:35:19: 錯誤:expat.h:沒有那個文件或目錄
xml/apr_xml.c:66: 錯誤:expected specifier-qualifier-list before ‘XML_Parser’
xml/apr_xml.c: 在函數‘cleanup_parser’中:
xml/apr_xml.c:364: 錯誤:‘apr_xml_parser’沒有名為‘xp’的成員
xml/apr_xml.c:365: 錯誤:‘apr_xml_parser’沒有名為‘xp’的成員
xml/apr_xml.c: 在文件層:
xml/apr_xml.c:384: 錯誤:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
xml/apr_xml.c: 在函數‘apr_xml_parser_create’中:
xml/apr_xml.c:401: 錯誤:‘apr_xml_parser’沒有名為‘xp’的成員
xml/apr_xml.c:402: 錯誤:‘apr_xml_parser’沒有名為‘xp’的成員
xml/apr_xml.c:410: 錯誤:‘apr_xml_parser’沒有名為‘xp’的成員
xml/apr_xml.c:411: 錯誤:‘apr_xml_parser’沒有名為‘xp’的成員
xml/apr_xml.c:412: 錯誤:‘apr_xml_parser’沒有名為‘xp’的成員
xml/apr_xml.c:424: 錯誤:‘apr_xml_parser’沒有名為‘xp’的成員
xml/apr_xml.c:424: 錯誤:‘default_handler’未聲明(在此函數內第一次使用)
xml/apr_xml.c:424: 錯誤:(即使在一個函數內多次出現,每個未聲明的標識符在其
xml/apr_xml.c:424: 錯誤:所在的函數內也只報告一次。)
xml/apr_xml.c: 在函數‘do_parse’中:
xml/apr_xml.c:434: 錯誤:‘apr_xml_parser’沒有名為‘xp’的成員
xml/apr_xml.c:438: 錯誤:‘apr_xml_parser’沒有名為‘xp’的成員
xml/apr_xml.c:442: 錯誤:‘apr_xml_parser’沒有名為‘xp_err’的成員
xml/apr_xml.c:442: 錯誤:‘apr_xml_parser’沒有名為‘xp’的成員
xml/apr_xml.c: 在函數‘apr_xml_parser_geterror’中:
xml/apr_xml.c:500: 錯誤:‘apr_xml_parser’沒有名為‘xp_err’的成員
xml/apr_xml.c:500: 錯誤:‘apr_xml_parser’沒有名為‘xp_err’的成員
make[1]: *** [xml/apr_xml.lo] 錯誤 1
make[1]: Leaving directory `/usr/local/apr-util-1.6.1'
make: *** [all-recursive] 錯誤 1
[root@cdr02 apr-util-1.6.1]# yum inatsll expat-devel -y
已加載插件:product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
No such command: inatsll. Please use /usr/bin/yum --help
[root@cdr02 apr-util-1.6.1]# yum inatsll -y expat-devel
已加載插件:product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
No such command: inatsll. Please use /usr/bin/yum --help
[root@cdr02 apr-util-1.6.1]# make
make[1]: Entering directory `/usr/local/apr-util-1.6.1'
/bin/sh /usr/local/apr/build-1/libtool --silent --mode=compile gcc -g -O2 -pthread -DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE -I/usr/local/apr-util-1.6.1/include -I/usr/local/apr-util-1.6.1/include/private -I/usr/local/apr/include/apr-1 -o xml/apr_xml.lo -c xml/apr_xml.c && touch xml/apr_xml.lo
xml/apr_xml.c:35:19: 錯誤:expat.h:沒有那個文件或目錄
xml/apr_xml.c:66: 錯誤:expected specifier-qualifier-list before ‘XML_Parser’
xml/apr_xml.c: 在函數‘cleanup_parser’中:
xml/apr_xml.c:364: 錯誤:‘apr_xml_parser’沒有名為‘xp’的成員
xml/apr_xml.c:365: 錯誤:‘apr_xml_parser’沒有名為‘xp’的成員
xml/apr_xml.c: 在文件層:
xml/apr_xml.c:384: 錯誤:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
xml/apr_xml.c: 在函數‘apr_xml_parser_create’中:
xml/apr_xml.c:401: 錯誤:‘apr_xml_parser’沒有名為‘xp’的成員
xml/apr_xml.c:402: 錯誤:‘apr_xml_parser’沒有名為‘xp’的成員
xml/apr_xml.c:410: 錯誤:‘apr_xml_parser’沒有名為‘xp’的成員
xml/apr_xml.c:411: 錯誤:‘apr_xml_parser’沒有名為‘xp’的成員
xml/apr_xml.c:412: 錯誤:‘apr_xml_parser’沒有名為‘xp’的成員
xml/apr_xml.c:424: 錯誤:‘apr_xml_parser’沒有名為‘xp’的成員
xml/apr_xml.c:424: 錯誤:‘default_handler’未聲明(在此函數內第一次使用)
xml/apr_xml.c:424: 錯誤:(即使在一個函數內多次出現,每個未聲明的標識符在其
xml/apr_xml.c:424: 錯誤:所在的函數內也只報告一次。)
xml/apr_xml.c: 在函數‘do_parse’中:
xml/apr_xml.c:434: 錯誤:‘apr_xml_parser’沒有名為‘xp’的成員
xml/apr_xml.c:438: 錯誤:‘apr_xml_parser’沒有名為‘xp’的成員
xml/apr_xml.c:442: 錯誤:‘apr_xml_parser’沒有名為‘xp_err’的成員
xml/apr_xml.c:442: 錯誤:‘apr_xml_parser’沒有名為‘xp’的成員
xml/apr_xml.c: 在函數‘apr_xml_parser_geterror’中:
xml/apr_xml.c:500: 錯誤:‘apr_xml_parser’沒有名為‘xp_err’的成員
xml/apr_xml.c:500: 錯誤:‘apr_xml_parser’沒有名為‘xp_err’的成員
make[1]: *** [xml/apr_xml.lo] 錯誤 1

解決辦法:

安裝expat庫試試。yum install expat-devel

 

問題6:安裝pcre報錯

錯誤內容:invalid value of canonical build

解決辦法:
檢查“./configure --prefix=/usr/local/pcre --with-apr=/usr/local/apr/bin/apr-1-config”是否有多余的空格。

 

問題7:make命令安裝Apache時報錯

錯誤內容:make[2]: *** [htpasswd] 錯誤 1
make[2]: Leaving directory `/usr/local/httpd-2.4.29/support'
make[1]: *** [all-recursive] 錯誤 1
make[1]: Leaving directory `/usr/local/httpd-2.4.29/support'
make: *** [all-recursive] 錯誤 1

解決辦法:
由於安裝的“apr”和“apr-util”的版本是V1.6,造成版本不兼容,需要安裝它們的V1.5。

 

問題8:啟動服務時報錯

[root@getlnx05 httpd-2.4.6]#  /usr/local/apache/bin/apachectl start

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using getlnx05.gfg1.esquel.com. Set the 'ServerName' directive globally to suppress this message

這個時候需要編輯httpd.conf配置文件,添加SeraverName的具體IP地址。如下所示。

[root@getlnx05 conf]# cd /usr/local/apache/conf/

[root@getlnx05 conf]# ls

extra  httpd.conf  magic  mime.types  original

[root@getlnx05 conf]# vi httpd.conf

ServerAdmin you@example.com

#

# ServerName gives the name and port that the server uses to identify itself.

# This can often be determined automatically, but we recommend you specify

# it explicitly to prevent problems during startup.

#

# If your host doesn't have a registered DNS name, enter its IP address here.

#

#ServerName www.example.com:80

ServerName 192.168.9.122:80

#

# Deny access to the entirety of your server's filesystem. You must

# explicitly permit access to web content directories in other

# <Directory> blocks below.

#

"httpd.conf" 502L, 18179C written

[root@getlnx05 conf]# /usr/local/apache/bin/apachectl restart

  如果從其它電腦連接訪問Apache時,輸入url地址:http://192.168.9.122頁面沒有顯示正常,而上面配置也OK,那么你必須關閉防火牆,有時候甚至需要重啟電腦才能OK,重啟Apache服務都無效。

[root@getlnx05 conf]# chkconfig iptables off

[root@getlnx05 conf]# /usr/local/apache/bin/apachectl restart

 

設置Apache的環境變量

1、在"/etc/profile"文件最后添加 export PATH=$PATH:/ usr/local/apache/bin ("="左右不要有空格)
2、[root@admin ~]# source /etc/profile 立即生效)
3、測試重啟:[root@admin ~]# service httpd restart
 

設置Apache開機啟動

1、[root@admin ~]# cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd     (如果有其他的版本的Apache存在,也可以直接覆蓋掉)

2、打開編輯(vim,鍵盤輸入字母"i")"/etc/rc.d/init.d/httpd"文件,在 #!/bin/sh 下增加兩行文字如下:

  # chkconfig: 35 70 30
  # description: Apache

3、注冊該服務

[root@admin ~]# chkconfig –-add httpd

查看結果:[root@admin ~]# chkonfig --list

   

  至此。轉載請注明出處,記得掃碼打賞支持哦,謝謝!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM