Macos Mojave 10.14.6 安装 php-7.3.10


从官方网站下载最新版php

https://www.php.net/distributions/php-7.3.10.tar.gz


使用 brew 安装依赖库(如果你没有brew,先安装 https://brew.sh)

brew install freetype

brew install libjpeg

brew install openssl

brew install zlib

brew install libcurl

brew install webp

brew install gettext

brew install gmp

brew install libiconv


解压 tar xzf php-7.3.10.tar.gz

然后 cd php-7.3.10


执行配置检查,并生成 Makefile

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm  --with-fpm-user=leo --with-fpm-group=staff --with-mysqli --with-pdo-mysql --with-iconv=/usr/local/Cellar/libiconv/1.16 --with-freetype-dir=/usr/local --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-zlib=/usr/local/Cellar/zlib/1.2.11 --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl=/usr/local/Cellar/curl/7.66.0 --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext=/usr/local/Cellar/gettext/0.20.1 --disable-fileinfo --enable-maintainer-zts --enable-opcache=no --with-gmp --with-openssl=/usr/local/Cellar/openssl/1.0.2t --with-openssl-dir=/usr/local/Cellar/openssl/1.0.2t --with-webp-dir=/usr/local/Cellar/webp/1.0.3 --with-gmp=/usr/local/Cellar/gmp/6.1.2_2


执行 make 


make 过程可能有这个错误

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
  "_libiconv", referenced from:
      _do_convert in gdkanji.o
      _zif_iconv_substr in iconv.o
      _zif_iconv_mime_encode in iconv.o
      _php_iconv_string in iconv.o
      __php_iconv_strlen in iconv.o
      __php_iconv_strpos in iconv.o
      __php_iconv_appendl in iconv.o
      ...
  "_libiconv_close", referenced from:
      _do_convert in gdkanji.o
      _zif_iconv_substr in iconv.o
      _zif_iconv_mime_encode in iconv.o
      _php_iconv_string in iconv.o
      __php_iconv_strlen in iconv.o
      __php_iconv_strpos in iconv.o
      __php_iconv_mime_decode in iconv.o
      ...
  "_libiconv_open", referenced from:
      _do_convert in gdkanji.o
      _zif_iconv_substr in iconv.o
      _zif_iconv_mime_encode in iconv.o
      _php_iconv_string in iconv.o
      __php_iconv_strlen in iconv.o
      __php_iconv_strpos in iconv.o
      __php_iconv_mime_decode in iconv.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


解决方法:

修改 configure 后生成的 Makefile 文件

找到 EXTRA_LIBS 变量

删除 -liconv 

增加

/usr/local/libiconv/lib/libiconv.dylib /usr/local/Cellar/readline/7.0.3_1/lib/libhistory.dylib /usr/local/Cellar/readline/7.0.3_1/lib/

修改后

EXTRA_LIBS = -lcrypto -lssl -lcrypto -lz -lresolv -ledit -lncurses -lpq -lpq -lmcrypt -lltdl -lpng -lz -ljpeg -lcurl -lz -lcrypto -lssl -lcrypto -lm -lxml2 -lz -licucore -lm -lcurl -lldap -lz -lxml2 -lz -licucore -lm -lfreetype -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm /usr/local/Cellar/libiconv/1.16/lib/libiconv.dylib



执行 make 


然后 sudo make install  

$ /usr/local/php/bin/php -m
[PHP Modules]
bcmath
Core
ctype
curl
date
dom
filter
ftp
gd
gettext
gmp
hash
iconv
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvsem
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
zlib

[Zend Modules]




阅读:1590