mac 10.13.6 High Sierra 下编译PHP

brew 漫长的时间安装扩展包后,发现竟然不支持php7.4。直接打开brew下的php@7.4.rb的安装脚本进行获取其中的./configure配置,参考网上别人的配置文档,修改后,能兼容brew下的php7.4布局,手工编译也能灵活的设置配置编译模块。

具体步骤

1
2
3
#下载php7.4.30.tar.gz 
#解压缩至/private/tmp/目录下
cd /private/tmp/phpA7.4-20220924-61077-kvzxga/php-7.4.30

配置编译选项

7.4

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#7.4

./configure --prefix=/usr/local/Cellar/php@7.4/7.4.30_1 \
--localstatedir=/usr/local/var \
--sysconfdir=/usr/local/etc/php/7.4 \
--with-config-file-path=/usr/local/etc/php/7.4 \
--with-config-file-scan-dir=/usr/local/etc/php/7.4/conf.d \
--with-pear=/usr/local/Cellar/php@7.4/7.4.30_1/share/php@7.4/pear \
--enable-bcmath \
--enable-calendar \
--enable-exif \
--enable-ftp \
--enable-fpm \
--enable-gd \
--with-mhash \
--enable-intl \
--enable-mbregex \
--enable-mbstring \
--enable-mysqlnd \
--enable-pcntl \
--enable-phpdbg \
--enable-phpdbg-readline \
--enable-phpdbg-webhelper \
--enable-maintainer-zts \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--with-apxs2=/usr/local/opt/httpd/bin/apxs \
--with-bz2=/usr/local/opt/bzip2 \
--with-curl \
--with-external-gd \
--with-external-pcre \
--with-ffi --with-fpm-user=_www \
--with-fpm-group=_www \
--with-gettext=/usr/local/opt/gettext \
--with-gmp=/usr/local/opt/gmp \
--with-iconv=/usr/local/opt/libiconv/ \
--with-kerberos \
--with-layout=GNU \
--enable-inline-optimization \
--with-ldap=/usr/local/opt/openldap \
--with-libxml --with-libedit --with-mhash=/usr \
--with-mysql-sock=/tmp/mysql.sock --with-mysqli=shared,mysqlnd \
--with-openssl=/usr/local/Cellar/openssl@1.1/1.1.1j\
--with-password-argon2=/usr/local/opt/argon2 \
--with-pdo-dblib=/usr/local/opt/freetds \
--with-pdo-mysql=shared,mysqlnd \
--with-pdo-odbc=unixODBC,/usr/local/opt/unixodbc \
--with-pdo-pgsql=/usr/local/opt/libpq \
--with-pdo-sqlite \
--with-pgsql=/usr/local/opt/libpq \
--with-pic \
--with-pspell=/usr/local/opt/aspell \
--with-sodium \
--with-sqlite3 \
--with-tidy=/usr/local/opt/tidy-html5 \
--with-unixODBC \
--with-xmlrpc \
--with-xsl \
--with-gettext \
--enable-session \
--with-zip \
--with-zlib \
--with-ffi \
--enable-soap \
--enable-opcache \
--enable-dtrace \
--with-gdbm=/usr/local/opt/gdbm \
--with-ldap-sasl

8.0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
./configure --prefix=/usr/local/Cellar/php@8.0/8.0.23_1 \
--localstatedir=/usr/local/var \
--sysconfdir=/usr/local/etc/php/8.0 \
--with-config-file-path=/usr/local/etc/php/8.0 \
--with-config-file-scan-dir=/usr/local/etc/php/8.0/conf.d \
--with-pear=/usr/local/Cellar/php@8.0/8.0.23_1/share/php@8.0/pear \
--enable-bcmath \
--enable-calendar \
--enable-exif \
--enable-ftp \
--enable-fpm \
--enable-gd \
--with-mhash \
--enable-intl \
--enable-mbregex \
--enable-mbstring \
--enable-mysqlnd \
--enable-pcntl \
--enable-phpdbg \
--enable-phpdbg-readline \
--enable-phpdbg-webhelper \
--enable-maintainer-zts \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--with-apxs2=/usr/local/opt/httpd/bin/apxs \
--with-bz2=/usr/local/opt/bzip2 \
--with-curl \
--with-external-gd \
--with-external-pcre \
--with-ffi --with-fpm-user=_www \
--with-fpm-group=_www \
--with-gettext=/usr/local/opt/gettext \
--with-gmp=/usr/local/opt/gmp \
--with-iconv=/usr/local/opt/libiconv/ \
--with-kerberos \
--with-layout=GNU \
--enable-inline-optimization \
--with-ldap=/usr/local/opt/openldap \
--with-libxml --with-libedit --with-mhash=/usr \
--with-mysql-sock=/tmp/mysql.sock --with-mysqli=shared,mysqlnd \
--with-openssl=/usr/local/Cellar/openssl@1.1/1.1.1j\
--with-password-argon2=/usr/local/opt/argon2 \
--with-pdo-dblib=/usr/local/opt/freetds \
--with-pdo-mysql=shared,mysqlnd \
--with-pdo-odbc=unixODBC,/usr/local/opt/unixodbc \
--with-pdo-pgsql=/usr/local/opt/libpq \
--with-pdo-sqlite \
--with-pgsql=/usr/local/opt/libpq \
--with-pic \
--with-pspell=/usr/local/opt/aspell \
--with-sodium \
--with-sqlite3 \
--with-tidy=/usr/local/opt/tidy-html5 \
--with-unixODBC \
--with-xmlrpc \
--with-xsl \
--with-gettext \
--enable-session \
--with-zip \
--with-zlib \
--with-ffi \
--enable-soap \
--enable-opcache \
--enable-dtrace \
--with-gdbm=/usr/local/opt/gdbm \
--with-ldap-sasl

5.6

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
./configure --prefix=/usr/local/Cellar/php@5.6/5.6.40 \
--localstatedir=/usr/local/var \
--sysconfdir=/usr/local/etc/php/5.6 \
--with-config-file-path=/usr/local/etc/php/5.6 \
--with-config-file-scan-dir=/usr/local/etc/php/5.6/conf.d \
--with-pear=/usr/local/Cellar/php@5.6/5.6.40/share/php@5.6/pear \
--with-mysql \
--with-mcrypt \
--with-mysqli \
--with-pdo-mysql \
--with-mhash \
--with-curl \
--with-gd \
--with-zlib \
--with-openssl=/usr/local/Cellar/openssl@1.0/1.0.2q \
--with-mcrypt \
--with-xpm-dir=/usr/local/Cellar/libx11/1.8.1/include \
--with-gd=/usr/local/Cellar/gd/2.3.3_3 \
--with-freetype-dir=/usr/local/Cellar/freetype/2.10.1 \
--with-jpeg-dir=/usr/local/Cellar/jpeg-turbo/2.1.4 \
--with-png-dir=/usr/local/Cellar/libpng/1.6.37 \
--with-libxml-dir=/usr/local/Cellar/libxml2/2.10.2_1 \
--with-zlib-dir=/usr/local/Cellar/zlib/1.2.12_1 \
--with-iconv=/usr/local/Cellar/libiconv/1.17 \
--with-curl=/usr/local/Cellar/curl/7.73.0 \
--with-vpx-dir=/usr/local/Cellar/libvpx \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--enable-xml \
--enable-sockets \
--enable-simplexml \
--enable-pcntl \
--enable-soap \
--enable-sockets \
--enable-pdo \
--enable-cli \
--enable-fpm

编译配置选项说明

openssl

需要注意用brew安装,或者手工编译,这里指定了编译所需要的openssl的库地址

bzip2

需要安装bzip2

1
brew install bzip2

在配置中指定bzip2的类库

1
--with-bz2=/usr/local/opt/bzip2

libffi

安装

1
brew install libffi

在环境变量中增加libffi的库地址

1
2
3
export LDFLAGS="$LDFLAGS -L/usr/local/opt/libffi/lib"
export CPPFLAGS="$CPPFLAGS -I/usr/local/opt/libffi/include"
export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig:$PKG_CONFIG_PATH"

PKG_CONFIG_PATH 变量很重要,php7.4开始,很多扩展库的编译都需要通过此环境变量

icu4c

1
brew install icu4c

增加编译环境变量配置

1
2
3
4
export LDFLAGS="$LDFLAGS -L/usr/local/opt/icu4c/lib"
export CPPFLAGS="$CPPFLAGS -I/usr/local/opt/icu4c/include"
export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig:$PKG_CONFIG_PATH"
export PATH="/usr/local/opt/icu4c/bin:$PATH"

sasl

1
2
3
4
5
6
brew install cyrus-sasl

export PATH="/usr/local/opt/cyrus-sasl/sbin:$PATH"
export LDFLAGS="$LDFLAGS -L/usr/local/opt/cyrus-sasl/lib"
export CPPFLAGS="$CPPFLAGS -I/usr/local/opt/cyrus-sasl/include"
export PKG_CONFIG_PATH="/usr/local/opt/cyrus-sasl/lib/pkgconfig:$PKG_CONFIG_PATH"

libxml2

1
2
3
4
5
brew install libxml2

export LDFLAGS="$LDFLAGS -L/usr/local/opt/libxml2/lib"
export CPPFLAGS="$CPPFLAGS -I/usr/local/opt/libxml2/include"
export PKG_CONFIG_PATH="/usr/local/opt/libxml2/lib/pkgconfig:$PKG_CONFIG_PATH"

编译安装

1
make -j2 && make install

配置

编译的配置中默认已经指定了配置文件的位置,配置中的这两句就定义

1
2
--with-config-file-path=/usr/local/etc/php/7.4 \
--with-config-file-scan-dir=/usr/local/etc/php/7.4/conf.d \

复制配置文件php-fpm、php.ini的配置文件

1
2
sudo cp /usr/local/etc/php/7.4/php-fpm.conf.default /usr/local/etc/php/7.4/php-fpm.conf
sudo cp /usr/local/etc/php/7.4/php-fpm.d/www.conf.default /usr/local/etc/php/7.4/php-fpm.d/www.conf

测试配置

1
/usr/local/opt/php@7.4/sbin/php-fpm --test

php.ini 中修改的配置

1
2
3
upload_max_filesize = 128M
post_max_size = 128M
date.timezone = PRC

启动

1
/usr/local/sbin/php74-fpm -D