環境:Ubuntu 16.0.4
Apache官網下載Apache httpd壓縮包:httpd-2.4.27.tar.gz,安裝之前請確定安裝了make工具,我安裝的是GNU make
- 解壓文件
sudo tar -zxvf '/home/fanchao/桌面/share/apache http server/httpd-2.4.27.tar.gz' -C /etc/httpd
在解壓後的文件目錄下有個install文件,裏面寫着
For complete installation documentation, see [ht]docs/manual/install.html or http://httpd.apache.org/docs/2.4/install.html
- 通過查看文檔,安裝所需要的環境 :
安裝 APR(其實不用安裝,後面說明):下載 apr-1.6.2.tar.gz
解壓:
sudo tar -zxvf '/home/fanchao/桌面/share/apache http server/apr-1.6.2.tar.gz' -C /etc/httpd
編譯和安裝:
sudo cd /etc/httpd/apr-1.6.2 #進入解壓後的文件目錄 sudo ./configure #這裏可以添加參數 --prefix=你要安裝的目錄,我這裏沒有加,默認安裝在/user/loacl目錄下 以下所有的./configure都可以添加這個參數 sudo make sudo make install
安裝APR-UTIL(其實不用安裝,後面說明):下載 apr-util-1.6.0.tar.gz
解壓:
sudo tar -zxvf '/home/fanchao/ 桌面/share/apache http server/apr-util-1.6.0.tar.gz' -C /etc/httpd
編譯和安裝
cd /etc/httpd/apr-util-1.6.0 sudo ./configure --with-apr=/usr/local/apr/bin/apr-1-config sudo make
這裏報錯
xml/apr_xml.c:35:19: fatal error: expat.h: 沒有那個文件或目錄 compilation terminated. /etc/httpd/apr-util-1.6.0/build/rules.mk:206: recipe for target 'xml/apr_xml.lo' failed make[1]: *** [xml/apr_xml.lo] Error 1 make[1]: Leaving directory '/etc/httpd/apr-util-1.6.0' /etc/httpd/apr-util-1.6.0/build/rules.mk:118: recipe for target 'all-recursive' failed make: *** [all-recursive] Error 1
解決辦法就是安裝libexpat1-dev
sudo apt-get install libexpat1-dev
重新輸
sudo make sudo make install
安裝httpd所需要的prce庫:下載prce-8.41.zip
解壓:
sudo unzip '/home/fanchao/桌面/share/apache http server/pcre-8.41.zip' -d /etc/httpd
編譯和安裝:
cd /etc/httpd/pcre-8.41 sudo ./configure sudo make sudo make install
最後編譯安裝apache httpd
sudo ./configure --with-apr='/usr/local/apr/bin/apr-1-config' --with-apr-util='/usr/local/apr/bin/apu-1-config' --with-prce='/usr/local/bin/pcre-config' #這裏還有其他參數可以配置,具體參照官方 sudo make sudo make install
到現在按照官方文檔的說明應該就已經安裝好了,但是我到make這步就報錯了
collect2: error: ld returned 1 exit status Makefile:48: recipe for target 'htpasswd' failed make[2]: *** [htpasswd] Error 1 make[2]: Leaving directory '/etc/httpd-2.4.27/support' /etc/httpd-2.4.27/build/rules.mk:75: recipe for target 'all-recursive' failed make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory '/etc/httpd-2.4.27/support' /etc/httpd-2.4.27/build/rules.mk:75: recipe for target 'all-recursive' failed make: *** [all-recursive] Error 1
我查了很多地方都沒有遇到這個錯誤或者說這個錯誤是怎麼發生的。這個錯誤是因爲在httpd目錄下的srclib目錄裏面沒有apr和apr-util所導致的,但是./configure又不會報錯,到make纔會報錯,所以把下載下來到apr和apr-util解壓到srclib目錄下到apr和apr-util目錄,注意目錄名字要一致。
這就是我之前說的不用安裝apr和apr-util的原因,它會自動安裝,手動安裝後去指定安裝路徑是會報錯的。
重新生成make文件和make
sudo ./configure --with-prce='/usr/local/bin/pcre-config' --with-included-apr #其他參數請參照官方 sudo make sudo make install
現在就可以安裝成功了,如果沒有指定文件夾那麼就會默認安裝在 /usr/local/apache2
運行
sudo '/usr/local/apache2/bin/apachectl' -k start #啓動 sudo '/usr/local/apache2/bin/apachectl' -k stop #停止
完結。