在macOS上通过源码安装apache httpd
安装环境
系统版本
macOS Big Sur(11.2.2)
硬件信息
Processor Name: Dual-Core Intel Core i5
Processor Speed: 2.3 GHz
Number of Processors: 1
Total Number of Cores: 2
Memory: 8 GB
安装版本: 2.4.46
apache httpd版本
2.4.46
安装步骤
下载源码包
登录:https://httpd.apache.org/download.cgi#apache24
找到下载链接并下载:
https://mirrors.bfsu.edu.cn/apache//httpd/httpd-2.4.46.tar.gz
解压到文件夹httpd-2.4.46
下载依赖包APR、APR-util、PCRE
APR and APR-Util
Make sure you have APR and APR-Util already installed on your system. If you don’t, or prefer to not use the system-provided versions, download the latest versions of both APR and APR-Util from Apache APR, unpack them into /httpd_source_tree_root/srclib/apr and /httpd_source_tree_root/srclib/apr-util (be sure the directory names do not have version numbers; for example, the APR distribution must be under /httpd_source_tree_root/srclib/apr/) and use ./configure’s --with-included-apr option. On some platforms, you may have to install the corresponding -dev packages to allow httpd to build against your installed copy of APR and APR-Util.
此时最新的APR和APR-util分别是1.7.0和1.6.1,
下载后分别解压到刚解压的httpd的目录httpd-2.4.46下的srclib/apr和srclib/apr-util中
修改BUG
如果直接执行.configuration --with-included-apr --prefix=XXX, make 会报错
修改文件arp_want头文件
路径:httpd-2.4.46/srclib/apr/include/apr_want.h
改法:用/* */注释掉结构体iovec的定义
修改apr.h文件
路径:httpd-2.4.46/srclib/apr/include/apr.h
改法:
找到“#error Can not determine the proper size for pid_t”
将其替换成:#define APR_PID_T_FMT “d”
修改
路径:httpd-2.4.46/modules/filters/mod_ext_filter.c
改法:
在文件开始增加:
APR_DECLARE(apr_status_t) apr_procattr_limit_set(apr_procattr_t *attr,apr_int32_t what,struct rlimit *limit);
配置
执行:
./configure --prefix=XXX/apache-httpd-2.4.46 --with-included-apr
其中,XXX要替换成你的本地目录,XXX/apache-httpd-2.4.46 是最后生成可执行文件的根目录。
–with-included-apr: 使用刚下载的最新的APR和APR-util进行httpd的构建。
编码
执行:
make
安装
make install
运行
进入XXX/apache-httpd-2.4.46/bin
执行:
sudo apachectl start
验证
打开浏览器,在地址栏输入:localhost