Mac安裝Apache Http Server
阿新 • • 發佈:2018-12-16
下載原始碼
下載地址:http://httpd.apache.org/download.cgi
例如我們要下載2.4.35
版本的,那麼我們就下載它的原始檔,如下圖:
點選第二個Source
進行下載即可。
配置、編譯、安裝
- 配置
cd httpd-2.4.35
./configure --prefix=/usr/local/httpd-2.4.35
沒有出現Error,視為配置完成。
可能遇見的錯誤有
- APR not found 開啟終端找個合適的地方執行下面的命令
wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz
tar -zxf apr-1.4.5.tar.gz
cd apr-1.4.5
sudo ./configure --prefix=/usr/local/apr
sudo make && sudo make install
重新執行配置命令即可。
- APR-util not found 開啟終端找個合適的地方執行下面的命令
wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz
tar apr-util-1.3.12.tar.gz
cd apr-util-1.3.12
sudo ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
sudo make && sudo make install
重新執行配置命令,發現還是會出現該問題。配置命令修改如下:
./configure --prefix=/usr/local/httpd-2.4.35 --with-apr-util=/usr/local/apr-util
- pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/ 開啟終端找個合適的地方執行下面的命令
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip
unzip pcre-8.10.zip
cd pcre-8.10
sudo ./configure --prefix=/usr/local/pcre
sudo make && sudo make install
修改配置命令如下並執行
./configure --prefix=/usr/local/httpd-2.4.35 --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre
配置成功,如下圖
- 編譯
sudo make
大概過去了3分鐘… 沒提示錯誤,視為成功…
- 安裝
sudo make install
大概過去了30秒…
沒提示錯誤,視為成功…
成功後,在我們的--prefix
指定的目錄/usr/local/httpd
下生成了下面的內容
啟動
cd /usr/local/httpd
sudo bin/apachectl -k start
啟動成功後終端提示如下:
httpd (pid 74018) already running
訪問http://localhost
或http://127.0.0.1
,得到下圖:
可能遇見的錯誤
- Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1. Set the ‘ServerName’ directive globally to suppress this message
意思是缺少了了ServerName
配置,開啟bin/httpd.conf
,修改如下:
#
# 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 127.0.0.1
增加ServerName 127.0.0.1
重新啟動即可