发现bug是因为项目页面的验证码无法显示,没有imagettftext()这个方法,出现错误的原因是PHP编译时没有加上FreeType。 首先去freetype官网下载,选择的是freetype-2.4.8.tar.bz2 本来想用-curl下载,但是下载下来格式不正确,不知道为什么。 #### 解压Extract ```shell $ tar -jxf freetype-2.4.8.tar.bz2 ``` 附上一些tar的参数 -j: bz2 -z: gzip -x:extract -c: create -f: file (last parameter) #### 编译 ```shell $ cd freetype-2.4.8.tar.bz2 $ ./configure --prefix=/usr/local/freetype ``` 报错: ```shell GNU make (>= 3.80) or makepp (>= 1.19) is required to build FreeType2. Please try `GNUMAKE= ./configure'. or >&2 `GNUMAKE="makepp --norc-substitution" ./configure'. ``` 网上提供的都是linux下的解决办法,所以卡住了,gmake:没有方法,make: xcrun: error: active developer path ("/Library/Developer/CommandLineTools") does not exist ```shell xcode-select --install ``` 开始安装xcode。run: make --v 可以看到GNU Make 3.81的信息。 再次编译,成功。 ### refference [Call to undefined function imagettftext()解决方法]( https://blog.phpgao.com/undefined_imagettftext.html) ### rutorial - [Mac Pro 编译安装 PHP 5.6.21 及 问题汇总](http://www.cnblogs.com/52php/p/5683356.html) - [mac下安装GD库FreeType](http://blog.haohtml.com/archives/15687) - [mac升级yosemite后安装gd的freetype扩展](http://www.cnblogs.com/walter371/p/4120040.html) [reffer:mac下重新编译php新版本](http://helonghua.com/2015/04/01/mac-install-new-php/) ### 编译PHP 重新从官网下了PHP-5.6.29,解压到/usr/local/src/下,然后开始编译,找到config.nice文。 中途报错两次:一次无法locate libintl.h) 需要去修改configure文件,在判断PHP_GETTEXT目录那里加上/usr/local/opt/gettext | [stackoverflow.com](http://stackoverflow.com/questions/21165067/configure-cannot-locate-header-file-when-the-directory-is-specified-with-cppfl) 第二次报错 : mcrypt.h not found 手动配置:--with-mcrypt=/usr/local/Cellar/mcrypt/2.6.8 \ #### 下面是解压后config.nice文件中拷贝出来的 ./configure \ --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --with-openssl \ --with-zlib \ --with-bz2 \ --with-gd \ --with-gettext \ --with-mhash \ --with-iconv \ --with-curl \ --with-xmlrpc \ --with-mysql \ --with-pdo-mysql \ --with-mysqli \ --enable-calendar \ --enable-pdo \ --enable-zip \ --enable-mbstring \ --enable-mbregex \ --enable-bcmath \ --enable-soap \ --enable-sockets \ --enable-ftp \ --enable-gd-native-ttf \ --enable-shmop \ --enable-sysvmsg \ --enable-sysvsem \ --enable-sysvshm \ --enable-xml \ --enable-pcntl \ --enable-fpm \ --enable-opcache \ --without-pear \ #### 下面是经过编辑添加后的部分 --with-mcrypt=/usr/local/Cellar/mcrypt/2.6.8 \ --with-png-dir=/usr/local/Cellar/libpng/1.6.25 \ --with-jpeg-dir=/usr/local/Cellar/jpeg/8d \ --with-openssl-dir=/usr/local/Cellar/openssl/1.0.2j \ --with-freetype-dir=/usr/local/Cellar/freetype/2.7 这时候需要设置php的全局变量,本来想着先删除mac自带的php,结果出现了Operation not permitted。查了一下发现 [OS X 10.11 引入了rootless | zhihu.com](https://www.zhihu.com/question/31116473) ———————— 一句话总结,即使是root用户,将无法对以下路径有写和执行权限: /System /bin /sbin /usr (except /usr/local) 只有Apple自身签名的软件(含命令行工具)可以。 ———————— 编译了没有效果,选择了Homebrew安装[Yosemite / El Capitan php-gd + mcrypt installation](http://stackoverflow.com/questions/26493762/yosemite-el-capitan-php-gd-mcrypt-installation/26505558#26505558) 项目Github: [Github Homebrew-php](https://github.com/Homebrew/homebrew-php) 浏览issue的时候发现可以打印gd_info :FreeType=>Bool(false) 不过有指出一个问题,就是php_info()时注意php的版本,我看了下localhost打印出来还是自带的5.6.27 ,但是刚才已经把httpd.conf的php5_module的加载地址修改为了Homebrew下载的了。 检索了一下系统上的httpd.conf文件,发现在/usr/local/etc/下面又出现了一个/apache2/2.4/httpd.conf 确认了一下加载的是这个文件,bash输入 brew --prefix可以看出/usr/local是brew安装的,应该是没有启动mac自带的apache。 为了方便区分原生的php所以用brew重新安装了php55。 前面没有提到很多tutorial中有个bug——下载下来的php没有带libexec文件夹,即没有apache的libphp,所以: ``` brew install php55 --with-httpd24 ``` 最后确定/usr/local/下的httpd.conf php5_module的目录是正确,sudo apachectl restart, var_dump(gd_info()); 终于成功了。 折腾一遍下来,apache、php都重新装了一个,其实还是用MAMP最方便吧...