ning

一生太短,一瞬好长

0%

osx10.12 php5.6出现imagettfbbox()函数找不到解决办法

昨天使用laravel使用 [mewebstudio/captcha]url(https://github.com/mewebstudio/captcha) 验证码扩展的时候出现了imagettfbbox()不存在的异常,去网上搜索了一下,是因为osx10.12系统的php5.6gd库并没有编译完全,那么这边的方案是直接用homebrew替代.那么关于[homebrew]url(https://brew.sh/index_zh-cn.html)的安装的这边就不赘述了,
官网有中文教程,当然在使用的时候记得开启翻墙,这样会访问的很快。

1
2
#搜索php版本
brew search php56

图1

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
#安装php56,下面是可加参数
###
--with-cgi
Enable building of the CGI executable (implies --without-fpm)
--with-debug
Compile with debugging symbols
--with-enchant
Build with enchant support
--with-gmp
Build with gmp support
--with-homebrew-curl
Include Curl support via Homebrew
--with-homebrew-libressl
Include LibreSSL instead of OpenSSL via Homebrew
--with-homebrew-libxml2
Include Libxml2 support via Homebrew
--with-homebrew-libxslt
Include LibXSLT support via Homebrew
--with-httpd22
Enable building of shared Apache 2.2 Handler module
--with-httpd24
Enable building of shared Apache 2.4 Handler module
--with-imap
Include IMAP extension
--with-libmysql
Include (old-style) libmysql support instead of mysqlnd
--with-mssql
Include MSSQL-DB support
--with-pdo-oci
Include Oracle databases (requries ORACLE_HOME be set)
--with-pear
Build with PEAR
--with-phpdbg
Enable building of the phpdbg SAPI executable
--with-postgresql
Build with postgresql support
--with-thread-safety
Build with thread safety
--without-bz2
Build without bz2 support
--without-fpm
Disable building of the fpm SAPI executable
--without-ldap
Build without LDAP support
--without-legacy-mysql
Do not include the deprecated mysql_ functions
--without-mysql
Remove MySQL/MariaDB support
--without-pcntl
Build without Process Control support
--without-unixodbc
Build without unixODBC support
--HEAD
Install HEAD version
###
#执行命令,这边直接可以在后面加参数
这边是直接加上apache参数(提示这里用osx10.12的apache时也要安装),会有 libexec.so直接生成
如果你不想 下图有下载链接 你可以直接下载
brew install php56 --with httpd24

libexec下载链接:
[libexec]url(http://cdn.ningke.xin/libexec.zip)
让默认的apache使用brew安装的php扩展,下载上面的libexec 放在 /usr/local/Cellar/php56/5.6.30_6/libexec目录下,当然您也可以放在别的目录。

1
2
3
4
5
6
7
8
9
cp -r libexec /usr/local/Cellar/php56/5.6.30_6/libexec
#编辑apache配置文件
sudo vim /etc/apache2/httpd.conf
#找到170行左右位置 注释掉下行(前面加上#)
#LoadModule php5_module libexec/apache2/libphp5.so
#在下面新增一行加入
LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so
#重启apache
sudo apachectl restart

访问phpinfo文件看是否切换成功,如果出现下图界面说明成功切换
phpinfo

安装之后切换php版本,会看到如下提示:

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
#按照如下提示,执行下行命令,在执行php -v 就变成brew安装的php5.6版本了
export PATH="$(brew --prefix homebrew/php/php56)/bin:$PATH"

###提示
If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc,
~/.zshrc, ~/.profile or your shell's equivalent configuration file:

export PATH="$(brew --prefix homebrew/php/php56)/bin:$PATH"

✩✩✩✩ FPM ✩✩✩✩

To launch php-fpm on startup:
mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist

The control script is located at /usr/local/opt/php56/sbin/php56-fpm

OS X 10.8 and newer come with php-fpm pre-installed, to ensure you are using the brew version you need to make sure /usr/local/sbin is before /usr/sbin in your PATH:

PATH="/usr/local/sbin:$PATH"

You may also need to edit the plist to use the correct "UserName".

Please note that the plist was called 'homebrew-php.josegonzalez.php56.plist' in old versions
of this formula.

With the release of macOS Sierra the Apache module is now not built by default. If you want to build it on your system
you have to install php with the --with-httpd24 option. See brew options php56 for more details.

To have launchd start homebrew/php/php56 now and restart at login:
brew services start homebrew/php/php56

另外,brew安装其他扩展的时候,比如php56-opcache php56-mcrypt等 要注意下,一定要加上 –build-from-source不然的话会出现 :

1
2
3
4
5
6
7
8
9
10
11
12
#执行 php -v 可能出现以下提示,是因为brew编译的扩展和php官网扩展不一致导致的。
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/opt/php56-mcrypt/mcrypt.so' - dlopen(/usr/local/opt/php56-mcrypt/mcrypt.so, 9): Library not loaded: /usr/local/opt/libtool/lib/libltdl.7.dylib
Referenced from: /usr/local/opt/php56-mcrypt/mcrypt.so
Reason: image not found in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/opt/php56-mcrypt/mcrypt.so' - dlopen(/usr/local/opt/php56-mcrypt/mcrypt.so, 9): Library not loaded: /usr/local/opt/libtool/lib/libltdl.7.dylib
Referenced from: /usr/local/opt/php56-mcrypt/mcrypt.so
Reason: image not found in Unknown on line 0
PHP 5.6.30 (cli) (built: Mar 11 2017 09:56:27)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

解决办法,如果已经出现了运行以下命令(例子),执行之后再运行php -v就不会出现以上提示了

1
2
brew reinstall php56-opcache ---build-from-source
brew reinstall php56-mcrypt ---build-from-source
感谢您的慷慨