MAC下面源码编译安装PHP7.1

在mac下面编译php还是遇到不少坑的,下面就我在安装过程中遇到的问题及解决方案记录下来供各位仁者参考。

系统环境

macOs版本:10.13.6
PHP版本:php7.1.21

安装依赖

brew install libjpeg libpng libxml gettext openssl freetype pcre
这里就不再说明brew的安装方法了,请自行百度

需要手动安装的是 libiconv
网站地址: http://www.gnu.org/software/libiconv/
当前版本: https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz
下载解压完后,configure采用了直接使用默认目录安装默认是 /usr/local

    $ cd libiconv-1.15
    $ ./configure
    $ make
    $ sudo make install

PHP编译安装

./configure --prefix=/usr/local/php/7.1 \
--with-config-file-path=/usr/local/php/7.1/etc \
--with-config-file-scan-dir=/usr/local/php/7.1/etc/conf.d \
--enable-fpm \
--with-fpm-user=yluchao \
--with-fpm-group=admin \
--with-mysqli \
--with-pdo-mysql \
--with-iconv-dir=/usr/local \
--enable-short-tags \
--with-freetype-dir \
--with-zlib \
--with-jpeg-dir \
--with-png-dir \
--with-libxml-dir=/usr/bin/xml2-config \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--with-mcrypt \
--enable-ftp \
--with-gd \
--enable-gd-native-ttf \
--with-openssl=/usr/local/opt/openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear \
--disable-fileinfo \
--enable-maintainer-zts \
--enable-mysqlnd
  • 注:
    新版本会同时检测 gettext喝iconv。所以安装时先去除gettext等php安装成功后,再去增加gettext扩展

如果make时报此错误

z -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm  -o sapi/cli/php
Undefined symbols for architecture x86_64:
  "_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
      ...
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

解决方案:

vim Makefile文件
找到 这两个关键词EXTRA_LDFLAGS和EXTRA_LDFLAGS_PROGRAM删除

EXTRA_LDFLAGS = -L/Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk/usr/lib -L/usr/local/opt/openssl/lib -L/usr/local/lib -L/usr/local/opt/freetype/lib
EXTRA_LDFLAGS_PROGRAM = -L/Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk/usr/lib -L/usr/local/opt/openssl/lib -L/usr/local/lib -L/usr/local/opt/freetype/lib

删除 -L/Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk/usr/lib 类似此字符串的字符

安装gettext扩展

首先在{源码目录}/ext/gettext 执行/usr/local/php/7.1/bin/phpize(根据自己环境可变)。成功后安装扩展。

./configure --with-php-config=/usr/local/php/7.1/bin/php-config --with-gettext=/usr/local/opt/gettext

make & sudo make install 

添加扩展配置

sudo vim /usr/local/php/7.1/etc/conf.d/gettext.ini
增加:extension=/usr/local/php/7.1/lib/php/extensions/no-debug-zts-20160303/gettext.so

你可能感兴趣的:(php,软件安装)