查看完整目錄:【LAMP搭建系列】
前言
在這里我使用的是源碼安裝的方法,不是很了解Linux下源碼安裝的可以查看我的另一篇文章《Linux軟件安裝管理之——源碼安裝詳解》婚陪。本人的Linux發(fā)行版本為Ubuntu 16.04,不過源碼安裝的方法所有的Linux發(fā)行版本基本都通用频祝,所以也不用太擔心你的系統(tǒng)發(fā)行版和我的不一樣泌参;安裝apache版本為httpd-2.4.29脆淹。
使用源碼安裝的一個好處就是,你可以安裝最新版本的軟件沽一,也可以自定義安裝你想要的其它版本盖溺。
安裝Apache HTTP Server 2.4.2
參考(官方文檔):http://httpd.apache.org/docs/2.4/install.html
1、到官網(wǎng)去下載httpd-2.4.29的源碼包
官方網(wǎng)址為:http://httpd.apache.org/
httpd-2.4.29下載地址為:http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.29.tar.bz2
wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.29.tar.bz2
2铣缠、解壓
tar -xvf httpd-2.4.29.tar.bz2
3烘嘱、新建目標文件夾(即apache的安裝目錄)
mkdir /usr/local/apache2
4、配置
./configure --prefix=/usr/local/apache2 --enable-module=shared
在這個步驟的時候會報幾個錯誤蝗蛙,是因為apache的一些依賴拙友。安裝Apache的時候,必需還要安裝apr歼郭、apr-util遗契、pcre,并在配置時指定相關參數(shù)病曾。下面就是給出這些錯誤的解決方法:
1)錯誤1:
checking for APR... no
configure: error: APR not found.? Please read the documentation.
wget http://mirror.bit.edu.cn/apache//apr/apr-1.6.3.tar.bz2
wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2
tar -xvf apr-1.6.3.tar.bz2 -C srclib/
tar -xvf apr-util-1.6.1.tar.bz2 -C srclib/
mv srclib/apr-1.6.3/ srclib/apr
mv srclib/apr-util-1.6.1/ srclib/apr-util
./configure --with-included-apr
注:這部份命令都是在httpd-2.4.29目錄內執(zhí)行的牍蜂。所有的源碼壓縮包解壓后你都可以將它刪除。
以上的解決方法為官方的給出的泰涂,你也可以使用另外一種方法鲫竞,即使用源碼安裝的方法分別安裝apr與apr-util。
#安裝:apr
wget http://mirror.bit.edu.cn/apache//apr/apr-1.6.3.tar.bz2
tar -xvf apr-1.6.3.tar.bz2
cd apr-1.6.3
./configure --prefix=/usr/local/apr
make
make install
# 安裝Apr-util 在./confiure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
#其他步驟類似逼蒙。
#安裝好以上兩個依賴后从绘,回到httpd-2.4.29目錄,配制:
./configure? --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/
這時就會報出第二個錯誤
2)錯誤2:
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
wget https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.bz2
tar -xvf pcre-8.41.tar.bz2
cd pcre-8.41/
./configure --prefix=/usr/local/pcre
make
make install
#安裝好pcre后是牢,回到httpd-2.4.29目錄僵井,配制:
./configure --with-pcre=/usr/local/pcre
5、編譯
make
6驳棱、安裝
make install
完成該步驟批什,如果沒報任何錯誤的話,則說明你的apache已經(jīng)安裝完成了社搅,下面則進入我們的測試階段驻债。
測試運行
1、配置文件:
進入到你的apache安裝目錄/usr/local/apache2/conf/形葬,打開文件httpd.conf合呐,配制以下幾項:
1)ServerName localhost:80
2)DocumentRoot "/my_php/www"? #該目錄就是以后你的項目根目錄
3)<Directory "/my_php/www">
先配置這三個地方,其它其它的配置可根據(jù)后期需求再作修改笙以。
2淌实、常用操作:
apachectl -k start ? # 啟動 或 httpd -k start
apachectl -k restart ? # 重啟 或? httpd -k restart
apachectl -k stop ? # 停止 或? httpd -k stop
3、測試:
啟動apache
# 先切換到安裝完成后的目錄/usr/local/apache2/bin
./apachectl -k start
然后在瀏覽器里輸入你的ip地址,如果出現(xiàn)It Works!翩伪,則說明你的apache已經(jīng)搭建成功了。
附:
1)查看80端口監(jiān)聽狀態(tài):netstat -nltp | grep 80
2)查看httpd服務啟動狀態(tài):ps -aux | grep httpd