MAC下PHP版本切换

homebrew 升级到2.1.4之后。已经不维护php5.6 tap了。所以brew install php56是不行的。

Mac系统10.13.6 我的系统自带Apache2.4+php7.1.16

1、安装php7.2

brew install [email protected]

安装完 会有info根据提示操作就行(也可以使用命令 brew info [email protected]查看)

To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so

    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>

Finally, check DirectoryIndex includes index.php
    DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
    /usr/local/etc/php/7.2/

[email protected] is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

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

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


To have launchd start [email protected] now and restart at login:
  brew services start [email protected]
Or, if you don't want/need a background service you can just run:
  php-fpm

2、安装[email protected]

这个就查了好久,因为homebrew新版本废弃了php56

$ brew tap exolnet/homebrew-deprecated

$ brew install [email protected]

上面安装完之后也可以。

To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php5_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp5.so

    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>

Finally, check DirectoryIndex includes index.php
    DirectoryIndex index.php index.html

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

[email protected] is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

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

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


To have launchd start exolnet/deprecated/[email protected] now and restart at login:
  brew services start exolnet/deprecated/[email protected]
Or, if you don't want/need a background service you can just run:
  php-fpm

3、安装php56的php56-mcrypt php56-yaf扩展

brew services stop [email protected]

brew services start exolnet/deprecated/[email protected]

brew unlink [email protected]

brew link [email protected] --force

1、安装yaf

进入 https://github.com/laruence/yaf/tree/php5 下载源码进行编译安装(2019-06-01还是有的,以后不维护了不知道还有没有这个链接)

find / -name ‘php-config’ 2>>/dev/null
find / -name ‘phpize’ 2>>/dev/null

上面找出来的都会有两个。一个是PHP7.2一个是PHP5.6

/usr/local/bin/phpize和/usr/local/bin/php-config是php56

$/usr/local/bin/phpize
$./configure --with-php-config=/usr/local/bin/php-config
make && make install

2、查找php56的php.ini位置后

vim php.ini

加入下面代码,我是在文件末尾加入的

[yaf]
yaf.environ = product
yaf.library = NULL
yaf.cache_config = 0
yaf.name_suffix = 1
yaf.name_separator = ""
yaf.forward_limit = 5
yaf.use_namespace = 0
yaf.use_spl_autoload = 0
extension=yaf.so //关键步骤

第二天改成用brew-php-switch来切换PHP版本,然后修改PATH,就可以用pecl来安装了

2、安装xdebug

https://pecl.php.net/package/Xdebug 查找需要的版本

然后选个版本

比如pecl install xdebug-2.6.0 (这个2.6.0及以上版本就需要php7了)

如果不能安装一般是PHP版本不对,就换个版本(xdebug-2.5.5)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章