下载源代码
下载地址:http://www.php.net/downloads.php
下载最新版php安装包。
编译安装
tar -zxvf php-7.4.7.tar.gzcd 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
安装PHP8 时去除了部分配置项
./configure --prefix=/usr/local/php8 --with-config-file-path=/usr/local/php8/etc --with-config-file-scan-dir=/usr/local/php8/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 --enable-intl --enable-mbstring --enable-mysqlnd --with-mysql-sock=/tmp/mysql.sock --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-zlib-dir=/usr/local/opt/zlib --with-iconv=/usr/local/Cellar/libiconv/1.16 --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-sockets
可能的报错一:
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'
alias php8="/usr/local/php8/bin/php"
alias composer8="/usr/local/php8/bin/php /usr/local/Cellar/composer/1.8.5/bin/composer"
source ~/.bash_profile
