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)

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