Apache Http Server - Mac安装Apache Http Server

官方文档对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重新启动即可

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值