Apache Http Server - Mac安装Apache Http Server

版权声明:写文章辛苦,请不要复制粘贴,如果要,请注明来处 https://blog.csdn.net/u012627861/article/details/83144834

官方文档对Apache Http Server的安装说明:http://httpd.apache.org/docs/2.4/install.html

下载源码

下载地址:http://httpd.apache.org/download.cgi
例如我们要下载2.4.35版本的,那么我们就下载它的源文件,如下图:
在这里插入图片描述
点击第二个Source进行下载即可。

配置、编译、安装

  1. 配置
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

配置成功,如下图
在这里插入图片描述

  1. 编译
sudo make

大概过去了3分钟…
没提示错误,视为成功…

  1. 安装
sudo make install

大概过去了30秒…
没提示错误,视为成功…
成功后,在我们的--prefix指定的目录/usr/local/httpd下生成了下面的内容
在这里插入图片描述

启动

cd /usr/local/httpd
sudo bin/apachectl -k start

启动成功后终端提示如下:

httpd (pid 74018) already running

访问http://localhosthttp://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重新启动即可

猜你喜欢

转载自blog.csdn.net/u012627861/article/details/83144834