前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >在 macOS 编译安装 PHP

在 macOS 编译安装 PHP

作者头像
Yifans_Z
发布2023-08-23 18:43:35
5150
发布2023-08-23 18:43:35
举报
文章被收录于专栏:与荔枝一起成长

环境

  • macOS 10.15.7
  • PHP 7.1.33

下载 PHP

源码地址:https://www.php.net/releases/#7.1.33

代码语言:javascript
复制
cd /tmp
wget https://www.php.net/distributions/php-7.1.33.tar.gz --no-check-certificate
tar zxvf php-7.1.33.tar.gz

安装相关库

确保 Xcode 正确版本正常安装。

代码语言:javascript
复制
# libiconv
brew install libiconv

# openssl
brew install openssl

# zlib 实现 GZIP 压缩页面
brew install zlib

配置编译安装

核心配置选项列表 | php.net

代码语言:javascript
复制
# 查看配置参数
./configure --help
./configure --help | grep openssl

# 注意替换 --prefix
# 按需进行调整
./configure --prefix=/Users/yifan/php/php71 \
--enable-bcmath \
--enable-calendar \
--enable-dba \
--enable-debug \
--enable-exif \
--enable-ftp \
--enable-fpm \
--enable-mbregex \
--enable-mbstring \
--enable-mysqlnd \
--enable-opcache-file \
--enable-soap \
--enable-sockets \
--enable-zip \
--with-curl=/usr/local/opt/curl \
--with-freetype-dir=/usr/local/opt/freetype \
--with-gd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv=/usr/local/opt/libiconv \
--with-icu-dir=/usr/local/opt/icu4c \
--with-jpeg-dir=/usr/local/opt/jpeg \
--with-libzip \
--with-openssl=/usr/local/opt/openssl@1.1 \
--with-bz2=/usr/local/opt/bzip2 \
--with-libxml-dir=/usr/local/opt/libxml2 \
--with-zlib=/usr/local/opt/zlib
代码语言:javascript
复制
# 4核编译
make clean && make -j4
make install

安装常用库:

[https://pecl.php.net/]

代码语言:javascript
复制
./bin/pecl install grpc
./bin/pecl install rdkafka
./bin/pecl install redis

./bin/pecl install mongodb
# PHP7.1
./bin/pecl install https://pecl.php.net/get/mongodb-1.11.1.tgz

./bin/pecl install swoole
# PHP7.1
./bin/pecl install https://pecl.php.net/get/swoole-4.5.11.tgz

遇到的问题

“_libiconv”, referenced from

代码语言:javascript
复制
Undefined symbols for architecture x86_64:
  "_libiconv", referenced from:
      _php_iconv_string in iconv.o
      __php_iconv_strlen in iconv.o
      __php_iconv_substr in iconv.o
      __php_iconv_strpos in iconv.o
      __php_iconv_mime_encode in iconv.o
      __php_iconv_appendl in iconv.o
      _php_iconv_stream_filter_append_bucket 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

解决方法:打开 Makefile 找到:

  • EXTRA_LDFLAGS
  • EXTRA_LDFLAGS_PROGRAM

删除后面的 -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib 相关。

代码语言:javascript
复制
make clean && make -j4
make install

php --ri curl

Please specify the install prefix of iconv with –with-iconv=<DIR>

代码语言:javascript
复制
brew install libiconv

Cannot find OpenSSL’s

configure: error: Cannot find OpenSSL’s <evp.h>

代码语言:javascript
复制
brew install openssl
代码语言:javascript
复制
./configure --with-openssl-dir=(brew --prefix openssl)

error: implicit declaration of function ‘getpid’ is invalid in C99

代码语言:javascript
复制
/Users/.../php/php-7.1.33/ext/zip/lib/mkstemp.c:75:8: error:
      implicit declaration of function 'getpid' is invalid in C99
      [-Werror,-Wimplicit-function-declaration]
        pid = getpid();
              ^
1 error generated.
make: *** [ext/zip/lib/mkstemp.lo] Error 1
make: *** Waiting for unfinished jobs....
代码语言:javascript
复制
brew install libzip

# ./configure add
--with-libzip=(brew --prefix libzip) \

reentrancy.c error: too few arguments to function call

代码语言:javascript
复制
/Users/.../php/php-7.1.33/main/reentrancy.c:139:23: error: too few
      arguments to function call, expected 3, have 2
        readdir_r(dirp, entry);
        ~~~~~~~~~            ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/dirent.h:110:1: note:
      'readdir_r' declared here
int readdir_r(DIR *, struct dirent *, struct dirent **) __DARWIN_INODE64...
^
1 error generated.
make: *** [main/reentrancy.lo] Error 1
make: *** Waiting for unfinished jobs....

查找:

代码语言:javascript
复制
.../php-src/main/reentrancy.c

int readdir_r(DIR *, struct dirent *, struct dirent **)

eaddir_r(dirp, entry)

修改为:

代码语言:javascript
复制
readdir_r(dirp, entry) 修改为 readdir_r(dirp, entry, &entry)

PEAR package PHP_Archive not installed

代码语言:javascript
复制
opcache.a(shared_alloc_shm.o) has no symbols
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
directorytreeiterator.inc
clicommand.inc
directorygraphiterator.inc
invertedregexiterator.inc
pharcommand.inc
make: *** [ext/phar/phar.phar] Segmentation fault: 11
make: *** Waiting for unfinished jobs....
代码语言:javascript
复制
./configure --without-pear --disable-phar

注意:不能加这个选项,会影响 composer 的使用。

XCode 对编译的影响

请保证 Xcode 正确的版本安装,否则可能有异常情况。如果系统不是最新版本可以通过下面的链接安装指定版本。

[https://developer.apple.com/download/all/?q=11.5]

References

– EOF –

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-04-28,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 环境
  • 下载 PHP
  • 安装相关库
  • 配置编译安装
  • 遇到的问题
    • “_libiconv”, referenced from
      • Please specify the install prefix of iconv with –with-iconv=<DIR>
        • Cannot find OpenSSL’s
          • error: implicit declaration of function ‘getpid’ is invalid in C99
            • reentrancy.c error: too few arguments to function call
              • PEAR package PHP_Archive not installed
                • XCode 对编译的影响
                • References
                领券
                问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档