Linux下編譯安裝Apache Http Server
1.下載httpd-2.4.12.tar.bz2
wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.12.tar.bz2
2.解壓下載的文件##
tar -xjvf httpd-2.4.12.tar.bz2
3.configure配置編譯安裝條件
./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite
配置 | 說明 |
---|---|
--prefix=/usr/local/apach2 | 設置編譯安裝到的系統目錄 |
--enable-s | 使httpd服務能夠動態加載模塊功能 |
--enable-rewrite | 使httpd服務具有網頁地址重寫功能 |
ARP not found 錯誤
o@o-pc:~/work/Apache-httpd-2.4.12$ ./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite
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.
解決辦法
下載 arp-1.5.2的源碼包
解壓后編譯安裝
o@o-pc:~/work/arp$ tar -xjvf apr-1.5.2.tar.bz2
o@o-pc:~/work/arp/apr-1.5.2$ ./configure --prefix=/usr/local/apr
...
o@o-pc:~/work/arp/apr-1.5.2$ make
...
o@o-pc:~/work/arp/apr-1.5.2$ sudo make install
APR-util not found 錯誤
o@o-pc:~/work/Apache-httpd-2.4.12$ ./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite
checking for chosen layout... Apache
...
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... no
configure: error: APR-util not found. Please read the documentation.
解決辦法
下載 apr-util-1.5.4 源碼包
o@o-pc:~/work/arp$ wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.5.4.tar.bz2
解壓后編譯安裝
注意./configure
配置的時候需要制定APR路徑--with-apr=/usr/local/apr
是前面編譯安裝apr的時候設置的路徑。
o@o-pc:~/work/arp$ tar -xjvf apr-util-1.5.4.tar.bz2
o@o-pc:~/work/arp/apr-util-1.5.4$ ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
...
o@o-pc:~/work/arp/apr-util-1.5.4$ make
...
o@o-pc:~/work/arp/apr-util-1.5.4$ sudo make install
pcre-config for libpcre not found錯誤
o@o-pc:~/work/Apache-httpd-2.4.12$ ./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite --with-apr-util=/usr/local/apr-util
checking for chosen layout... Apache
...
configure:
configure: Configuring Apache Portable Runtime Utility library...
configure:
checking for APR-util... yes
...
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
解決辦法
下載pcre-8.36源碼包
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.36/pcre-8.36.tar.bz2
8.7版本的地址
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.bz2
解壓后編譯安裝
o@o-pc:~/work/arp$ tar -xjvf pcre-8.37.tar.bz2
o@o-pc:~/work/arp/pcre-8.37$ ./configure --prefix=/usr/local/pcre
...
o@o-pc:~/work/arp/pcre-8.37$ make
...
o@o-pc:~/work/arp/pcre-8.37$ sudo make install
上面的錯誤解決后,再次./configure配置
注意添加的兩個--with-...
o@o-pc:~/work/Apache-httpd-2.4.12$ ./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre
4.編譯安裝
o@o-pc:~/work/Apache-httpd-2.4.12$ make
o@o-pc:~/work/Apache-httpd-2.4.12$ sudo make install
5.啟動apache服務
o@o-pc:~/work$ /usr/local/apache2/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
(13)Permission denied: AH00072: make_sock: could not bind to address [::]:80
(13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
注意,需要root權限
o@o-pc:~/work$ sudo /usr/local/apache2/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
提示錯誤,無法確定服務名(就是端口號)
切換到目錄/usr/local/apache2/conf
vi編輯文件httpd.conf(文件是只讀的,修改需要root權限)
o@o-pc:/usr/local/apache2/conf$ sudo vi httpd.conf
添加一行
ServerName localhost:80
然后重新啟動服務試試
o@o-pc:~$ sudo /usr/local/apache2/bin/apachectl start
httpd (pid 31083) already running
現在我們可以試試是否生效了
打開瀏覽器,輸入地址localhost回車看看是否顯示 Is Work!
顯示了就說們Apache Http Server已經在運行了
不方便截圖,這里直接用curl來獲取下網頁的內容
o@o-pc:~$ curl localhost
<html><body><h1>It works!</h1></body></html>
6.停止Apache Http 服務
可以看到停止后再去獲取就失敗了
o@o-pc:~$ sudo /usr/local/apache2/bin/apachectl stop
o@o-pc:~$ curl localhost
curl: (7) Failed to connect to localhost port 80: 拒絕連接