MAC 下使用brew重新安装PHP

今天在做一个项目的的时候,用php的curl的时候出错,提示

SSL: CA certificate set, but certificate verification is disabled

查了一下是mac系统的curl没有使用openssl的缘故,使用一下命令查看
php -i | grep "SSL Version"
结果如下
SSL Version => SecureTransport
既然这样,我就使用homebrew重新安装了下php
首先确保你的电脑已经已经安装了homebrew,如果没有安装使用如下命令安装
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
在安装此工具前,保证你已经安装了XCode command line tools 并且XCode>=6.1
安装好homebrew,接下来就重新安装php了,关于homebrew可参考https://brew.sh/index_zh-cn.html
安装命令如下
$ brew tap homebrew/dupes
$ brew tap homebrew/versions
$ brew tap homebrew/php 将php加入到homebrew仓库
接下来安装curl,使用openssl
$ brew install --with-openssl curl
接下来安装php,我们安装php5.6
$ brew install --with-homebrew-curl --with-httpd24 --without-ldap php56
修改apache配置 /usr/local/opt/php55/libexec/apache2/libphp5.so to your /etc/apache2/httpd.conf
重启apache
安装php任何的扩展,例如安装mcrypt,使用如下命令
$ brew install php56-mcrypt
再检查php的ssl版本
$ php -i | grep "SSL Version"
结果SSL Version => OpenSSL/1.0.2k
参考网址:https://stackoverflow.com/questions/26461966/osx-10-10-curl-post-to-https-url-gives-sslread-error/26538127#26538127
以下贴上安装好php后的提示
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so

The php.ini file can be found in:
/usr/local/etc/php/5.6/php.ini

✩✩✩✩ Extensions ✩✩✩✩

If you are having issues with custom extension compiling, ensure that you are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH:

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

PHP56 Extensions will always be compiled against this PHP. Please install them using --without-homebrew-php to enable compiling against system PHP.

✩✩✩✩ PHP CLI ✩✩✩✩

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
==> Summary

安装好mcrypt提示
To finish installing mcrypt for PHP 5.6:
* /usr/local/etc/php/5.6/conf.d/ext-mcrypt.ini was created,
do not forget to remove it upon extension removal.
* Validate installation via one of the following methods:
*
* Using PHP from a webserver:
* - Restart your webserver.
* - Write a PHP page that calls "phpinfo();"
* - Load it in a browser and look for the info on the mcrypt module.
* - If you see it, you have been successful!
*
* Using PHP from the command line:
* - Run `php -i "(command-line 'phpinfo()')"`
* - Look for the info on the mcrypt module.
* - If you see it, you have been successful!
我在启动apache的时候,出现了如下的错误

错误一
httpd: Syntax error on line 174 of /usr/local/etc/apache2/2.4/httpd.conf: Cannot load /usr/local/Cellar/php56/5.6.30_6/libexec/apache2/libphp5.so into server: dlopen(/usr/local/Cellar/php56/5.6.30_6/libexec/apache2/libphp5.so, 10): Symbol not found: _ldap_control_find\n Referenced from: /usr/local/Cellar/php56/5.6.30_6/libexec/apache2/libphp5.so\n Expected in: /System/Library/Frameworks/LDAP.framework/Versions/A/LDAP\n in /usr/local/Cellar/php56/5.6.30_6/libexec/apache2/libphp5.so
解决此问题的办法就是卸载掉php,然后重新装
命令如下
$ brew uninstall php56
$ brew install php56 --without-ldap
注意在卸载php的时候,如果安装过其他扩展,那么首先需要卸载扩展,再重新安装
我这里在卸载前就需要先执行
$ brew uninstall php56-mcrypt

安装xdebug扩展
$ brew install php56-xdebug

错误二
httpd: Syntax error on line 170 of /private/etc/apache2/httpd.conf: Cannot load /usr/local/opt/php56/libexec/apache2/libphp5.so into server:
dlopen(/usr/local/opt/php56/libexec/apache2/libphp5.so, 10): Library not loaded: /usr/local/opt/apr-util/libexec/lib/libaprutil-1.0.dylib\n Referenced
from: /usr/local/opt/php56/libexec/apache2/libphp5.so\n Reason: Incompatible library version: libphp5.so requires version 6.0.0 or later,
but libaprutil-1.0.dylib provides version 4.0.0
解决方案
暂无

错误三
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using wuwenlongdeMac-mini.local. Set the 'ServerName' directive globally to suppress this message
解决方案
http.conf : ServerName 127.0.0.1

/usr/local/bin/php php命令路径
/usr/local/bin/apachectl apache命令路径
/usr/local/etc/apache2/2.4/httpd.conf apache配置文件路径

 


本文固定链接: http://blog.wwllcchf.com/?p=617 | 吴文龙的个人博客

作者:wuwenlong 于2017年05月25日发表 &
MAC 下使用brew重新安装PHP | 吴文龙的个人博客

报歉!评论已关闭.