macOS怎样编译安装PHP7.3?

macOS里编译安装PHP7.3

在撰写本文的时候,php7.3最新的版本是7.3.33,以下是macOS编译安装PHP的过程

一、编译配置

编译配置,命令执行之后,会检测你系统的环境是否已经满足编译依赖

./configure \
  --prefix=/usr/local/php-7.3.33 \
  --with-config-file-path=/usr/local/php-7.3.33/etc \
  --with-pdo-mysql=mysqlnd \
  --with-mysqli=mysqlnd \
  --with-libxml-dir \
  --with-gd \
  --with-jpeg-dir \
  --with-png-dir \
  --with-freetype-dir \
  --with-iconv=/usr/local/Cellar/libiconv/1.16 \
  --with-zlib-dir=/usr/local/Cellar/zlib/1.2.11 \
  --with-bz2=/usr/local/Cellar/bzip2/1.0.8 \
  --with-openssl=/usr/local/Cellar/openssl@1.1/1.1.1n \
  --with-curl=/usr/local/Cellar/curl/7.82.0 \
  --enable-soap \
  --enable-mbstring \
  --enable-sockets \
  --enable-exif \
  --with-readline=/usr/local/Cellar/readline/8.1.2 \
  --disable-ipv6

以上有些参数指定到了实际的库目录,如--with-iconv=/usr/local/Cellar/libiconv/1.16,这里我指定到我电脑里libiconv的实际安装目录,如果你电脑没有,可以使用homebrew进行安装

二、编译过程可能遇见的错误

编译的过程中首先可能会遇到以下第两个错误

  • liconv相关
Undefined symbols for architecture x86_64:
  "_libiconv", referenced from:
      _do_convert in gdkanji.o
      _php_iconv_string in iconv.o
      __php_iconv_strlen in iconv.o
      _zif_iconv_substr in iconv.o
      __php_iconv_strpos in iconv.o
      _zif_iconv_mime_encode in iconv.o
      __php_iconv_appendl in iconv.o
      ...
  "_libiconv_close", referenced from:
      _do_convert in gdkanji.o
      _php_iconv_string in iconv.o
      __php_iconv_strlen in iconv.o
      _zif_iconv_substr in iconv.o
      __php_iconv_strpos in iconv.o
      _zif_iconv_mime_encode in iconv.o
      __php_iconv_mime_decode in iconv.o
      ...
  "_libiconv_open", referenced from:
      _do_convert in gdkanji.o
      _php_iconv_string in iconv.o
      __php_iconv_strlen in iconv.o
      _zif_iconv_substr in iconv.o
      __php_iconv_strpos in iconv.o
      _zif_iconv_mime_encode in iconv.o
      __php_iconv_mime_decode in iconv.o
      ...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [sapi/cli/php] Error 1

解决办法:我们手动打开源码目录下 configure命令 生成的Makefile文件,找到EXTRA_LIBS变量,将变量值中的-liconv这个参数替换为你实际安装的libiconv.dylib的绝对路径,如我的电脑使用homebrew安装,在我电脑里绝对路径是/usr/local/Cellar/libiconv/1.16/lib/libiconv.dylib

  • readline相关

可能遇到相关的错误如下

Undefined symbols for architecture x86_64:
  "_append_history", referenced from:
      _readline_shell_run in readline_cli.o
  "_history_list", referenced from:
      _zif_readline_list_history in readline.o
  "_rl_completion_suppress_append", referenced from:
      _zif_readline_info in readline.o
  "_rl_done", referenced from:
      _zif_readline_info in readline.o
  "_rl_mark", referenced from:
      _zif_readline_info in readline.o
  "_rl_pending_input", referenced from:
      _zif_readline_info in readline.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [sapi/cli/php] Error 1

找到EXTRA_LIBS变量,将变量值中的-lreadline这个参数替换为你实际安装的libreadline.dylib的绝对路径,如/usr/local/Cellar/readline/8.1.2/lib/libreadline.dylib

  • 最终修改后

修改了Makefile文件之后,最终的EXTRA_LIBS变量值如下

EXTRA_LIBS = -lcrypto -lssl -lcrypto -lresolv /usr/local/Cellar/readline/8.1.2/lib/libreadline.dylib /usr/local/Cellar/libiconv/1.16/lib/libiconv.dylib /usr/local/Cellar/libiconv/1.16/lib/libiconv.dylib -lpng -lz -ljpeg -lbz2 -lz -lcrypto -lssl -lcrypto -lm -lxml2 -lz -licucore -lm -lcurl -lxml2 -lz -licucore -lm -lfreetype -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm

三、编译与安装

# 编译
make
# 安装
make install

所有原创文章采用 知识共享署名-非商业性使用 4.0 国际许可协议 进行许可。
您可以自由的转载和修改,但请务必注明文章来源并且不可用于商业目的。
本站部分内容收集于互联网,如果有侵权内容、不妥之处,请联系我们删除。敬请谅解!

评论已关闭

很多东西宁缺毋滥,流星的光芒短暂而灼热闪耀。

让你变得更好的那个人,往往是你觉得很难与之相处的那个人。—— by 小宇

觉得自己做的到和不做的到,其实只在一念之间。

路在自己脚下,没有人可以决定我的方向。

你的选择是做或不做,但不做就永远不会有机会。

凡事顺其自然,遇事处于泰然,得意之时淡然,失意之时坦然,艰辛曲折必然,历尽沧桑悟然。