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

你可能感兴趣的:(PHP,php,mac)