mac上编译安装php

Posted 木偶跳舞

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mac上编译安装php相关的知识,希望对你有一定的参考价值。

下载源代码


下载地址:http://www.php.net/downloads.php


下载最新版php安装包。

编译安装

tar -zxvf php-7.4.7.tar.gz 

cd php-7.4.7/

./buildconf --force

./configure --prefix=/usr/local/php \\
			--with-config-file-path=/usr/local/php/etc \\
     --with-config-file-scan-dir=/usr/local/php/etc/conf.d \\
     --enable-bcmath \\
     --with-bz2=/usr/local/opt/bzip2 \\
     --with-curl=/usr/local/opt/curl \\
     --enable-filter \\
     --enable-fpm \\
     --with-fpm-user=www \\
     --with-fpm-group=www \\
     --with-gd \\
     --enable-gd-native-ttf \\
     --with-freetype-dir \\
     --with-jpeg-dir \\
     --with-png-dir \\
     --enable-intl \\
     --enable-mbstring \\
     --with-mcrypt \\
     --enable-mysqlnd \\
     --with-mysql-sock=/tmp/mysql.sock \\
     --with-mysqli=mysqlnd \\
     --with-pdo-mysql=mysqlnd \\
     --with-redis \\
     --with-pdo-sqlite \\
     --with-zlib-dir=/usr/local/opt/zlib \\
     --with-iconv=/usr/local/Cellar/libiconv/1.16 \\
     --with-icu-dir=/usr/local/opt/icu4c \\
     --disable-phpdbg \\
     --disable-phpdbg-webhelper \\
     --enable-opcache \\
     --enable-fileinfo \\
     --with-openssl=/usr/local/bin/openssl-1.1.1g \\
     --enable-simplexml \\
     --with-sqlite3 \\
     --enable-xmlreader \\
     --enable-xmlwriter \\
     --enable-zip \\
     --enable-sockets \\
     --with-xmlrpc
                                            
                                        

可能的报错一:

configure: error: The pkg-config script could not be found or is too old.  Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
path to pkg-config.

解决方法

brew install pkg-config

可能的报错二:

configure: error: Package requirements (openssl >= 1.0.1) were not met:  
No package 'openssl' found

解决方法

export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/bin/openssl-1.1.1g"

可能的报错三:

checking for icu-uc >= 50.1 icu-io icu-i18n... no
configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met:

No package 'icu-uc' found
No package 'icu-io' found
No package 'icu-i18n' found

解决方法

export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/opt/icu4c/lib/pkgconfig"

make && make install

make   

make install

可能的报错一:

/usr/local/bin/php-7.4.7/ext/libxml/libxml.c:34:10: fatal error: 'libxml/parser.h' file not found
#include <libxml/parser.h>
         ^~~~~~~~~~~~~~~~~
1 error generated.
make: *** [ext/libxml/libxml.lo] Error 1

解决方法

brew install libxml2

echo 'export PATH="/usr/local/opt/libxml2/bin:$PATH"' >> ~/.bash_profile
export LDFLAGS="-L/usr/local/opt/libxml2/lib"
export CPPFLAGS="-I/usr/local/opt/libxml2/include"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/opt/libxml2/lib/pkgconfig"

配置自定义命令

vim ~/.bash_profile

alias php='/usr/local/php/bin/php'
alias php-fpm='/usr/local/php/sbin/php-fpm'

source ~/.bash_profile

以上是关于mac上编译安装php的主要内容,如果未能解决你的问题,请参考以下文章

mac 上编译安装nginx

在 Mac OS 上编译 FFmpeg

代码块无法在 mac OSX 上编译

CentOS 6上编译安装AMP详解

在 mac os 上编译 dlib

尽管在 macBookPro 上编译和运行完美,但在 Mac mini 上编译项目的桥接头问题