mac下php7.0.9的编译安装及问题处理总结

下载php7.0.9.tar.gz解压。


  1. ./configure --prefix=/usr/local/php7 \
  2. --with-apxs2=/usr/sbin/apxs \
  3. --enable-fpm \
  4. --with-fpm-user=www \
  5. --with-fpm-group=www \
  6. --with-mysqli \
  7. --with-pdo-mysql \
  8. --with-iconv-dir \
  9. --with-freetype-dir \
  10. --with-zlib \
  11. --with-jpeg-dir \
  12. --with-png-dir \
  13. --with-libxml-dir=/usr \
  14. --enable-xml \
  15. --disable-rpath \
  16. --enable-bcmath \
  17. --enable-shmop \
  18. --enable-sysvsem \
  19. --enable-inline-optimization \
  20. --with-curl \
  21. --enable-mbregex \
  22. --enable-mbstring \
  23. --with-mcrypt \
  24. --enable-ftp \
  25. --with-gd \
  26. --enable-gd-native-ttf \
  27. --with-openssl \
  28. --with-mhash \
  29. --enable-pcntl \
  30. --enable-sockets \
  31. --with-xmlrpc \
  32. --enable-zip \
  33. --enable-soap \
  34. --without-pear \
  35. --with-gettext \
  36. --disable-fileinfo \
  37. --enable-maintainer-zts


问题一:


  1. checking for pkg-config... no
  2. configure: error: Cannot find OpenSSL\'s

本地

  1. whereis openssl
  2. /usr/bin/openssl

Linux系统一般是yum install openssl openssl-devel这种。
关于Mac OS一般是说要通过brew来安装。

有些文章提到pkg-config,在报错提示那里有显示它。经查它是一个用来处理第三方库依赖的。
对pkg-config的说明:
pkg-config的一些用法

  1. curl http://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz -o pkg-config-0.28.tar.gz
  2. tar zxvf pkg-config-0.28.tar.gz
  3. cd pkg-config-0.28
  4. ./configure --with-internal-glib
  5. make
  6. make install
(上面的版本是2003年的,实际有更新的版本。)
但是上述执行完后,执行
whereis pkg-config
提示找不到,但是再执行前面php的configure的时候就会显示

  1. checking for pkg-config... /usr/local/bin/pkg-config
说明安装成功了。

不过下面还是提示找不到evp.php

决定自己编译安装openssl,openssl-devel

  1. curl https://www.openssl.org/source/openssl-1.0.2h.tar.gz -o openssl-1.0.2h.tar.gz
  2. tar zxvf openssl-1.0.2h.tar.gz
  3. cd openssl-1.0.2h
  4. ./config
  5. make depend
  6. make
  7. make test
  8. make install

查看configure文件,里面显示安装的位置在 /usr/local/ssl/

再次执行前面php的configure,又报错:

  1. configure: error: jpeglib.h not found.
把--with-jpeg-dir和--with-png-dir去掉,结果报错。还是保留吧。
加了个--with-webp-dir,后来这里报错。这一条不加了。
到这里下载源码: http://libjpeg.sourceforge.net/
执行configure的时候报错,看起来是/bin/sh后面有个奇怪的字符。查了一下因为是configure文件是dos格式的,可以通过
vim ./configure
:set ff//查看文件格式是dos还是unix,相当于:set fileformat
:set ff=unix
:wq
再执行./configure即可。
然后make && sudo make install
这时会报/usr/local/man/man1/xxx文件或目录不存在。这时手动创建这个目录即可。

继续执行php的configure发现报错,说找不到jpeglib.h
查看jpeg的configure里写默认安装目录在/usr/local,但下面并有include,创建这个目录然后把源码里的*.h复制到这个目录下;
重复执行,又报jpeglib.a找不到。这次需要在/usr/local/lib(如果没有目录创建之),然后把jpeg源码目录里编译出来的jpeglib.a文件复制到其中。

又报错:

  1. configure: error: png.h not found.
来这里
http://www.libpng.org/pub/png/libpng.html
找libpng.编译安装即可。


又报错:

  1. configure: error: freetype-config not found.
到 http://download.savannah.gnu.org/releases/freetype/
下载freetype
编译安装,没报什么错。

又报错,查了一下都说通过一个叫gettext的包来获得。

  1. configure: error: Cannot locate header file libintl.h

  1. wget http://ftp.gnu.org/pub/gnu/gettext/gettext-0.19.2.tar.xz
  2. tar -zxvf gettext-0.19.2.tar.xz
  3. cd gettext-0.19.2/
  4. ./configure
  5. make
  6. sudo make install
中间弹了几次对javac的提示,因为我没有安装java。

又报错:

  1. configure: error: mcrypt.h not found. Please reinstall libmcrypt.
来这里 ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt
下载。
编译安装即可。

搞定!configure完成。


然后执行

  1. make test
中间报错,说在php源码包里的ext/openssl/里有文件没找到,要找的文件刚好在下载的openssl源码包里有。直接把源码包里的/include/openssl目录整个复制到ext/openssl中。
又报错,说ext/ftp里缺少openssl/ssl.h文件。像上面那样处理,通过。
又报错,说ext/phar里缺少openssl/evp.h文件。 像上面那样处理,通过。
又报错,说ext/mysqlnd里缺少mysqlnd/evp.h文件。 像上面那样处理,通过。
又报错:

  1. undefined symbols for architecture x86_64
查了一下,说是跟xcode有关系。
参考stackoverflow的文章
说要使用

  1. xcode-select --install
实际执行的时候说已经安装了,需要更新。
错误详细:

  1. Undefined symbols for architecture x86_64:
  2. "_PKCS5_PBKDF2_HMAC", referenced from:
  3. _zif_openssl_pbkdf2 in openssl.o
  4. "_SSL_CTX_set_alpn_protos", referenced from:
  5. _php_openssl_setup_crypto in xp_ssl.o
  6. "_SSL_CTX_set_alpn_select_cb", referenced from:
  7. _php_openssl_setup_crypto in xp_ssl.o
  8. "_SSL_get0_alpn_selected", referenced from:
  9. _php_openssl_sockop_set_option in xp_ssl.o
  10. "_SSL_select_next_proto", referenced from:
  11. _server_alpn_callback in xp_ssl.o
  12. "_TLSv1_1_client_method", referenced from:
  13. _php_openssl_setup_crypto in xp_ssl.o
  14. "_TLSv1_1_server_method", referenced from:
  15. _php_openssl_setup_crypto in xp_ssl.o
  16. "_TLSv1_2_client_method", referenced from:
  17. _php_openssl_setup_crypto in xp_ssl.o
  18. "_TLSv1_2_server_method", referenced from:
  19. _php_openssl_setup_crypto in xp_ssl.o
  20. ld: symbol(s) not found for architecture x86_64
说是因为openssl版本不一致

此bug的官方报告:
https://discussions.apple.com/thread/7066528?start=0&tstart=0

安装了homebrew,说是用来做包依赖管理的。
从这个地址安装:
http://brew.sh/index_zh-cn.html
使用

  1. brew list openssl
显示没有。于是执行

  1. brew install openssl
安装完毕之后再list显示:

  1. NeodeMacBook-Pro:openssl neosong$ brew list openssl
  2. /usr/local/Cellar/openssl/1.0.2h_1/bin/c_rehash
  3. /usr/local/Cellar/openssl/1.0.2h_1/bin/openssl
  4. /usr/local/Cellar/openssl/1.0.2h_1/include/openssl/ (75 files)
  5. /usr/local/Cellar/openssl/1.0.2h_1/lib/libcrypto.1.0.0.dylib
  6. /usr/local/Cellar/openssl/1.0.2h_1/lib/libssl.1.0.0.dylib
  7. /usr/local/Cellar/openssl/1.0.2h_1/lib/engines/ (12 files)
  8. /usr/local/Cellar/openssl/1.0.2h_1/lib/pkgconfig/ (3 files)
  9. /usr/local/Cellar/openssl/1.0.2h_1/lib/ (4 other files)
  10. /usr/local/Cellar/openssl/1.0.2h_1/share/man/ (1588 files)
参考文章:
https://github.com/phpbrew/phpbrew/issues/636
https://github.com/phpbrew/phpbrew/wiki/Trouble-Shooting:-Can't-build-PHP-on-OS-X-El-Capitan
按文章里的建议,说在配置的时候,--with-openssl= / usr / local / Cellar / openssl / 1.0 . 2h _1
这样就可以解决前面的问题了。


  1. export LDFLAGS="/usr/local/opt/openssl/lib/libssl.dylib /usr/local/opt/openssl/lib/libcrypto.dylib"
最后是上面这句搞定的。总之看起来是编译依赖的问题。这里需要注意执行上面这句的用户与进行make的用户得是同一个,不然变量注册会无效。如果make的时候使用的是sudo执行的,需要切换到root用户来执行上面的命令。

sudo su -

然后以root用户执行前面的export与make等命令。

补充:
如果安装过程中出现了使用sudo仍然提示“Operation not permitted”的情况的话,是因为Mac El Captain加入了rootless机制,相当于给系统加了一道安全防线。
要解决这类问题,需要重启mac,在启动时不断按command+r,这时会进入恢复模式,打开Terminal,执行:

csrutil disable

然后再重启就可以了。

之后再进入恢复模式,执行:

csrutil enable

即可恢复。

nginx的编译安装更简单,只需要注意要带上zlib和pcre两个扩展即可。

yaf框架的一般nginx代理配置如下:
server {
        listen 80;
        server_name   myyaf myyaf.com;
        access_log  /var/log/nginx/myyaf.access.log;
        error_log   /var/log/nginx/myyaf-error.log;
        root /Users/xxxx/yaftest/public;
        index  index.html index.php;
        if (!-e $request_filename) {
                  rewrite ^/(.*) /index.php?$1 last;
               }
        location ~ /.svn/ {
                        deny all;
               }
        location / {
                        root /Users/xxxx/yaftest/public;
                        index  index.html index.php;
                }
        location ~ \.php$ {
                        index index.php;
                        fastcgi_pass   127.0.0.1:9000;
                        fastcgi_index  index.php;
                        fastcgi_param  SCRIPT_FILENAME
                          $document_root$fastcgi_script_name;
                        include fastcgi_params;
                }
}


参考文章:

PHP编译过程中常见错误信息的解决方法

关于El Captain的Rootless机制


你可能感兴趣的:(PHP)