mac下编译安装php7.4.5及相关扩展安装

php7.4.5下载地址:https://www.php.net/distributions/php-7.4.5.tar.gz

MAC版本:macOS catalina 10.15.4

 

编译参数:

./configure --prefix=/Users/mac/service/php745 \
--with-config-file-path=/Users/mac/service/php745/etc \
--with-config-file-scan-dir=/Users/mac/service/php745/etc/conf.d \
--enable-pdo \
--with-pdo-mysql \
--with-mysqli \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-short-tags \
--enable-opcache \
--enable-cgi \
--enable-fpm \
--enable-sockets \
--enable-mbstring \
--enable-mbregex \
--enable-bcmath \
--enable-session \
--enable-xml \
--with-zip \
--enable-gd \
--with-zlib \
--with-mhash \
--enable-pcntl \
--with-xmlrpc \
--enable-soap \
--enable-mysqlnd \
--enable-maintainer-zts \
--enable-ftp \
--with-curl \
--enable-inline-optimization \
--enable-sysvsem \
--enable-shmop \
--with-freetype \
--with-gettext \
--with-openssl

 遇到的错误信息1:

checking for libxml-2.0 >= 2.7.6... no
configure: error: Package requirements (libxml-2.0 >= 2.7.6) were not met:

No package 'libxml-2.0' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

解决办法:

brew install libxml2

brew 安装完libxml2后在最后会输出以下信息:

If you need to have libxml2 first in your PATH run:
  echo 'export PATH="/usr/local/opt/libxml2/bin:$PATH"' >> ~/.bash_profile

For compilers to find libxml2 you may need to set:
  export LDFLAGS="-L/usr/local/opt/libxml2/lib"
  export CPPFLAGS="-I/usr/local/opt/libxml2/include"

For pkg-config to find libxml2 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/libxml2/lib/pkgconfig"

注意:php7.4与PHP7.3安装时的差别是在PHP7.3中可以在编译参数中加--with-libxml-dir=/usr/local/opt/libxml2的方式来指明libxml2库的位置,但在PHP7.4中,这种方式不再有效,直接依赖pkg-config。

所以我们需要执行:export PKG_CONFIG_PATH="/usr/local/opt/libxml2/lib/pkgconfig" 命令,但这种方式是覆盖式的,因为下面还要用该种方式指明其它库的位置,所以我们改用追加的方式,具体命令为:

export PKG_CONFIG_PATH=/usr/local/opt/libxml2/lib/pkgconfig:$PKG_CONFIG_PATH

另外在安装libxml2过程中会安装其它依赖的库,其中包括openssl,在安装过程中的提示信息中会有提示openssl的安装位置:

If you need to have openssl@1.1 first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.bash_profile

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"
export PKG_CONFIG_PATH=/usr/local/opt/openssl@1.1/lib/pkgconfig:$PKG_CONFIG_PATH

 

遇到的错误信息2:

checking for zlib >= 1.2.0.4... no
configure: error: Package requirements (zlib >= 1.2.0.4) were not met:

No package 'zlib' found

解决方式:

MacdeMacBook-Pro:php-7.4.5 mac$ brew install zlib
Updating Homebrew...
Warning: zlib 1.2.11 is already installed and up-to-date
To reinstall 1.2.11, run `brew reinstall zlib`

MacdeMacBook-Pro:php-7.4.5 mac$ brew reinstall zlib
==> Reinstalling zlib 
==> Downloading https://homebrew.bintray.com/bottles/zlib-1.2.11.mojave.bottle.tar.gz
Already downloaded: /Users/mac/Library/Caches/Homebrew/downloads/01ac92cf18f86708cd068eaf9a3594a15b31861eca1e4d6718563d5e27acd6b2--zlib-1.2.11.mojave.bottle.tar.gz
==> Pouring zlib-1.2.11.mojave.bottle.tar.gz
==> Caveats
zlib is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

For compilers to find zlib you may need to set:
  export LDFLAGS="-L/usr/local/opt/zlib/lib"
  export CPPFLAGS="-I/usr/local/opt/zlib/include"

For pkg-config to find zlib you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/zlib/lib/pkgconfig"

==> Summary
🍺  /usr/local/Cellar/zlib/1.2.11: 12 files, 373KB

安装完zlib库后再执行: 

export PKG_CONFIG_PATH=/usr/local/opt/zlib/lib/pkgconfig:$PKG_CONFIG_PATH

 遇到的错误信息3:
 

checking for libcurl >= 7.15.5... no
configure: error: Package requirements (libcurl >= 7.15.5) were not met:

No package 'libcurl' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables CURL_CFLAGS
and CURL_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

解决办法:

$ brew reinstall curl
If you need to have curl first in your PATH run:
  echo 'export PATH="/usr/local/opt/curl/bin:$PATH"' >> ~/.bash_profile

For compilers to find curl you may need to set:
  export LDFLAGS="-L/usr/local/opt/curl/lib"
  export CPPFLAGS="-I/usr/local/opt/curl/include"

For pkg-config to find curl you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/curl/lib/pkgconfig"


zsh completions have been installed to:
  /usr/local/opt/curl/share/zsh/site-functions
==> Summary
🍺  /usr/local/Cellar/curl/7.69.1: 459 files, 3.2MB

安装完curl后再执行:

export PKG_CONFIG_PATH=/usr/local/opt/curl/lib/pkgconfig:$PKG_CONFIG_PATH

 遇到的错误信息4:

configure: error: Cannot locate header file libintl.h

解决办法:

brew install gettext
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/gettext-0.20.2_1.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/52/52067198cab528f05fdc0b06f7b9711f7614f60a7361f1e764c4f46d3342ff22?__gda__=exp=1
######################################################################## 100.0%
==> Pouring gettext-0.20.2_1.mojave.bottle.tar.gz
==> Caveats
Emacs Lisp files have been installed to:
  /usr/local/share/emacs/site-lisp/gettext
==> Summary
🍺  /usr/local/Cellar/gettext/0.20.2_1: 1,929 files, 18.7MB
Removing: /usr/local/Cellar/gettext/0.19.8.1... (1,934 files, 16.9MB)

遇到的错误信息5:

checking for openssl >= 1.0.1... no
configure: error: Package requirements (openssl >= 1.0.1) were not met:

No package 'openssl' found

解决办法(其实在先前安装libxml2时已经自动安装了openssl,且与brew reinstall openssl安装的版本和路径均一致):

$ brew reinstall openssl
==> Reinstalling openssl@1.1 
==> Downloading https://homebrew.bintray.com/bottles/openssl@1.1-1.1.1g.mojave.bottle.tar.gz
Already downloaded: /Users/mac/Library/Caches/Homebrew/downloads/6e3ef678544db80c666b0bbc24b33d6d8887a773110106fd9a306c7e76abd222--openssl@1.1-1.1.1g.mojave.bottle.tar.gz
==> Pouring openssl@1.1-1.1.1g.mojave.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@1.1/certs

and run
  /usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.bash_profile

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"

==> Summary
🍺  /usr/local/Cellar/openssl@1.1/1.1.1g: 8,059 files, 18MB
export PKG_CONFIG_PATH=/usr/local/opt/openssl@1.1/lib/pkgconfig:$PKG_CONFIG_PATH

遇到的错误信息6:

checking for PDO includes... (cached) /Users/mac/Downloads/php-7.4.5/ext
checking for sqlite3 > 3.7.4... no
configure: error: Package requirements (sqlite3 > 3.7.4) were not met:

No package 'sqlite3' found

解决办法:

$ brew reinstall sqlite3
==> Reinstalling sqlite 
==> Downloading https://homebrew.bintray.com/bottles/sqlite-3.31.1.mojave.bottle.tar.gz
Already downloaded: /Users/mac/Library/Caches/Homebrew/downloads/86776a192139be19996dbcdb59911aafc04c4e996ba0a1b33b3edcdf3664dfb2--sqlite-3.31.1.mojave.bottle.tar.gz
==> Pouring sqlite-3.31.1.mojave.bottle.tar.gz
==> Caveats
sqlite is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have sqlite first in your PATH run:
  echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.bash_profile

For compilers to find sqlite you may need to set:
  export LDFLAGS="-L/usr/local/opt/sqlite/lib"
  export CPPFLAGS="-I/usr/local/opt/sqlite/include"

For pkg-config to find sqlite you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/sqlite/lib/pkgconfig"

==> Summary
🍺  /usr/local/Cellar/sqlite/3.31.1: 11 files, 4MB
export PKG_CONFIG_PATH=/usr/local/opt/sqlite/lib/pkgconfig:$PKG_CONFIG_PATH

错误信息7:

configure: error: Please specify the install prefix of iconv with --with-iconv=<DIR>

解决办法:

$ brew install libiconv
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
tmux

==> Downloading https://homebrew.bintray.com/bottles/libiconv-1.16.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/24/24d81638fcd7416a56c3dbdac7e2265d7b0476b17a71b631045425380122e6b1?__gda__=exp=158858806
######################################################################## 100.0%
==> Pouring libiconv-1.16.catalina.bottle.tar.gz
==> Caveats
libiconv is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have libiconv first in your PATH run:
  echo 'export PATH="/usr/local/opt/libiconv/bin:$PATH"' >> ~/.zshrc

For compilers to find libiconv you may need to set:
  export LDFLAGS="-L/usr/local/opt/libiconv/lib"
  export CPPFLAGS="-I/usr/local/opt/libiconv/include"

==> Summary
🍺  /usr/local/Cellar/libiconv/1.16: 30 files, 2.4MB
修改./configure命令,加上下面代码:
--with-iconv=/usr/local/opt/libiconv/

错误信息8:

No package 'oniguruma' found

解决办法:

brew install oniguruma

错误信息9:

No package 'libzip' found

解决办法:

brew install libzip

错误信息10(该错误信息是在MAC系统升级到Catalina后出现的):

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.

解决办法:

下面是到官网下载pkg-config 并安装, 如果没有出现上面pkg-config的错误, 可以跳过这一步, 直接到第3步即可

pkg-config 官网链接: https://www.freedesktop.org/wiki/Software/pkg-config/
我下载版本链接为:https://pkg-config.freedesktop.org/releases/pkg-config-0.29.2.tar.gz
    
点击version 0.29.2 进行下载, 下载完成后解压,进入目录顺序执行下面3步。
./configure
make
make install

如果不幸, 在执行第一步的时候就出现如下错误:
configure: error: Either a previously installed pkg-config or "glib-2.0 >= 2.16" could not be found. Please set GLIB_CFLAGS and GLIB_LIBS to the correct values or pass --with-internal-glib to configure to use the bundled copy.

./configure --with-internal-glib

之后configure成功后接着make 和 sudo make install

$ sudo make install
Password:
Installing shared extensions:     /Users/mac/service/php745/lib/php/extensions/no-debug-zts-20190902/
Installing PHP CLI binary:        /Users/mac/service/php745/bin/
Installing PHP CLI man page:      /Users/mac/service/php745/php/man/man1/
Installing PHP FPM binary:        /Users/mac/service/php745/sbin/
Installing PHP FPM defconfig:     /Users/mac/service/php745/etc/
Installing PHP FPM man page:      /Users/mac/service/php745/php/man/man8/
Installing PHP FPM status page:   /Users/mac/service/php745/php/php/fpm/
Installing phpdbg binary:         /Users/mac/service/php745/bin/
Installing phpdbg man page:       /Users/mac/service/php745/php/man/man1/
Installing PHP CGI binary:        /Users/mac/service/php745/bin/
Installing PHP CGI man page:      /Users/mac/service/php745/php/man/man1/
Installing build environment:     /Users/mac/service/php745/lib/php/build/
Installing header files:          /Users/mac/service/php745/include/php/
Installing helper programs:       /Users/mac/service/php745/bin/
  program: phpize
  program: php-config
Installing man pages:             /Users/mac/service/php745/php/man/man1/
  page: phpize.1
  page: php-config.1
/Users/mac/Downloads/php-7.4.5/build/shtool install -c ext/phar/phar.phar /Users/mac/service/php745/bin
ln -s -f phar.phar /Users/mac/service/php745/bin/phar
Installing PDO headers:           /Users/mac/service/php745/include/php/ext/pdo/

再之后的相关部分配置步骤为:


sudo cp php.ini-production /Users/mac/service/php745/etc/php.ini
cd /Users/mac/service/php745/etc/
sudo cp php-fpm.conf.default php-fpm.conf
cd /Users/mac/service/php745/etc/php-fpm.d
sudo cp www.conf.default www.conf

测试
$ sudo /Users/mac/service/php745/sbin/php-fpm --test
[28-Apr-2020 17:23:39] NOTICE: configuration file /Users/mac/service/php745/etc/php-fpm.conf test is successful


$ sudo vim /Users/mac/service/php745/etc/php.ini
expose_php = Off
max_execution_time = 60
max_input_time = 60
memory_limit = 128M
post_max_size = 128M
upload_max_filesize = 128M
date.timezone = Asia/Shanghai

配置php-fpm.conf
sudo vim /Users/mac/service/php745/etc/php-fpm.conf
取下以下注释并填写完整路径:
pid = run/php-fpm.pid

查看版本:
#/Users/mac/service/php745/bin/php --version 

PHP服务启动、平滑重启、停止命令:

启动:# sudo /Users/mac/service/php745/sbin/php-fpm
关闭:# sudo kill -INT `cat /Users/mac/service/php745/var/run/php-fpm.pid`
重启:# sudo kill -USR2 `cat /Users/mac/service/php745/var/run/php-fpm.pid`

附几个常用的相关扩展的安装方式:

------------------PSR扩展安装---------------------- 
最新的Phalcon4版本开始需要引入PSR模块,如果没有安装psr模块则会在启动php或者php-fpm报错“Fatal error: Class 'psr\container\containerinterface' not found in Unknown on line 0”,出现segmentation fault。除了需要安装psr模块意外,一定要注意在php.ini中配置extension的顺序。
在加载phalcon.so模块之前就必须先加载psr.so模块。so模块加载顺序依赖于你在php.ini配置中的上下顺序。因此,你必须保证如下的顺序结构:
extension=psr.so
extension=phalcon.so
https://pecl.php.net/package/psr

# cd cd ~/Downloads/soft 
# wget https://pecl.php.net/get/psr-1.0.0.tgz
# tar zxvf psr-1.0.0.tgz
# cd psr-1.0.0
# sudo /Users/mac/service/php745/bin/phpize
# sudo ./configure --with-php-config=/Users/mac/service/php745/bin/php-config
# sudo make
# sudo make install 
# sudo vim /Users/mac/service/php745/etc/php.ini 
extension=psr.so

# sudo kill -USR2 `cat /Users/mac/service/php745/var/run/php-fpm.pid`

------------------Phalcon4.0.5扩展安装---------------------------- 
wget https://github.com/phalcon/cphalcon/archive/v4.0.5.tar.gz
tar zxvf v4.0.5.tar.gz
cd cphalcon/build
cd build
sudo ./install --phpize /Users/mac/service/php745/bin/phpize --php-config /Users/mac/service/php745/bin/php-config
# sudo vim /Users/mac/service/php745/etc/php.ini 
extension=phalcon.so

php-fpm 平滑重启:
# sudo kill -USR2 `cat /Users/mac/service/php745/var/run/php-fpm.pid`

------------------安装phpredis5.2.1扩展-------------------------------- 
http://pecl.php.net/package/redis 

# wget https://pecl.php.net/get/redis-5.2.0.tgz
# tar zxvf redis-5.2.0.tgz
# cd redis-5.2.0
# sudo /Users/mac/service/php745/bin/phpize 
# sudo ./configure --with-php-config=/Users/mac/service/php745/bin/php-config 
# sudo make
# sudo make install 
# sudo vim /Users/mac/service/php745/etc/php.ini 
extension = redis.so 
php-fpm 重启: 
# sudo kill -USR2 `cat /Users/mac/service/php745/var/run/php-fpm.pid`

-----------------安装mongodb1.7.4扩展--------------------------------
http://pecl.php.net/package/mongodb
# wget https://pecl.php.net/get/mongodb-1.7.4.tgz
# tar zxvf mongodb-1.7.4.tgz
# cd mongodb-1.7.4
# /Users/mac/service/php745/bin/phpize
# sudo ./configure --with-php-config=/Users/mac/service/php745/bin/php-config
# sudo make
# sudo make install 
# sudo vim /Users/mac/service/php745/etc/php.ini 
extension=mongodb.so
php-fpm 重启: 
# sudo kill -USR2 `cat /Users/mac/service/php745/var/run/php-fpm.pid`


---------------Imagick扩展安装--------------------------------
不建议采用brew install imagemagick安装方式,原因是太慢!

第一步:先源码安装ImageMagick库
https://imagemagick.org/script/install-source.php
wget https://imagemagick.org/download/ImageMagick.tar.gz
tar -zxf ImageMagick.tar.gz
cd ImageMagick-7.0.10-10
./configure --prefix=/Users/mac/service/ImageMagick
sudo make
sudo make install

第二步:
http://pecl.php.net/package/imagick

$ wget https://pecl.php.net/get/imagick-3.4.4.tgz
$ tar zxvf imagick-3.4.4.tgz 
$ cd imagick-3.4.4    
$ /Users/mac/service/php745/bin/phpize
$ ./configure --with-php-config=/Users/mac/service/php745/bin/php-config --with-imagick=/Users/mac/service/ImageMagick
$ sudo make
$ sudo make install 
$ sudo vim /Users/mac/service/php745/etc/php.ini
extension=imagick.so 
php-fpm 重启: 
sudo kill -USR2 `cat /Users/mac/service/php745/var/run/php-fpm.pid`

--------------安装php memcached扩展----------------
https://launchpad.net/libmemcached
http://localhost/phpinfo.php

先安装libmemcached库
方式一: brew install libmemcached

==> Pouring libmemcached-1.0.18_2.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/libmemcached/1.0.18_2: 231 files, 1.8MB
==> Caveats
==> memcached
To have launchd start memcached now and restart at login:
  brew services start memcached
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/memcached/bin/memcached


方式二:
https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
tar -zxvf libmemcached-1.0.18.tar.gz
cd libmemcached-1.0.18
./configure --prefix=/Users/mac/service/libmemcached
make && make install


接着:

wget https://pecl.php.net/get/memcached-3.1.5.tgz
tar zxvf memcached-3.1.5.tgz
cd memcached-3.1.5
sudo /Users/mac/service/php745/bin/phpize



./configure --with-php-config=/Users/mac/service/php745/bin/php-config --with-libmemcached-dir=/usr/local/Cellar/libmemcached/1.0.18_2

或
./configure --with-php-config=/Users/mac/service/php745/bin/php-config --with-libmemcached-dir=/Users/mac/service/libmemcached --disable-memcached-sasl


sudo make
sudo make install
sudo vim /Users/mac/service/php745/etc/php.ini
extension=memcached.so

php-fpm 重启:
# sudo kill -USR2 `cat /Users/mac/service/php745/var/run/php-fpm.pid`

把更新命令行下的php:

$sudo cp /Users/mac/service/php745/bin/php /usr/bin
如果sudo cp命令报:mac  cp: /usr/bin/php: Read-only file system
则运行:$ sudo mount -uw /

$php -version 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值