最簡單的是用下面的安裝
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6
我這裏用的是brew
MAC新版本10.15.4 系統自帶的PHP是7.3
下面是安裝步驟
$ brew tap exolnet/homebrew-deprecated
$ brew install [email protected]
安裝失敗,大致安裝信息如下
==> Reinstalling exolnet/deprecated/[email protected]
==> Pouring [email protected]
==> /usr/local/Cellar/[email protected]/5.6.40/bin/pear config-set php_ini /usr/local/etc/
Last 15 lines from /Users/xxx/Library/Logs/Homebrew/[email protected]/post_install.01.pear:
2020-05-14 23:21:38 +0800
/usr/local/Cellar/[email protected]/5.6.40/bin/pear
config-set
php_ini
/usr/local/etc/php/5.6/php.ini
system
dyld: Library not loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
Referenced from: /usr/local/Cellar/[email protected]/5.6.40/bin/php
Reason: image not found
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall exolnet/deprecated/[email protected]`
==> Caveats
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
==> Summary
🍺 /usr/local/Cellar/[email protected]/5.6.40: 498 files, 60.5MB
% brew install https://github.com/tebelorg/Tump/releases/download/v1.0.0/openssl.rb
執行下面命令 會報錯
/usr/local/opt/[email protected]/bin/php -v
錯誤如下
dyld: Library not loaded: /usr/local/opt/[email protected]/lib/libssl.1.1.dylib
Referenced from: /usr/local/opt/libpq/lib/libpq.5.dylib
brew install https://github.com/tebelorg/Tump/releases/download/v1.0.0/openssl.rb
如果一直卡着
可以分開操作(我是卡着裏用下面的方法搞定的)
mkdir tem
cd tem
wget https://github.com/tebelorg/Tump/releases/download/v1.0.0/openssl.rb
brew install ./openssl.rb
brew switch openssl 1.0.2t
再執行 報錯
/usr/local/opt/[email protected]/bin/php -v /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.64.dylib
Referenced from: /usr/local/opt/[email protected]/bin/php
Reason: image not found
先備份原來的高版本(目前是66.1),php7還需要
cd /usr/local/Cellar/
cp -rf icu4c icu4c66
安裝需要的版本(64)
cd $(brew --prefix)/Homebrew/Library/Taps/homebrew/homebrew-core/Formula
git log --follow icu4c.rb
commit 22fb699a417093cd1440857134c530f1e3794f7d
Author: Bo Anderson <[email protected]>
Date: Thu Apr 23 14:37:03 2020 +0000
icu4c: update 66.1 bottle.
commit c78114de1252ac63590b06c1f2325e576a5d5226
Author: Pavel Omelchenko <[email protected]>
Date: Fri Apr 3 00:58:01 2020 +0300
icu4c 66.1
commit a806a621ed3722fb580a58000fb274a2f2d86a6d
Author: Thierry Moisan <[email protected]>
Date: Wed Oct 2 13:07:31 2019 -0400
icu4c: update homepage and url (#44812)
commit 896d1018c7a4906f2c3fa1386aaf283497db60a2
Author: BrewTestBot <[email protected]>
Date: Sat Sep 28 13:49:39 2019 +0000
icu4c: update 64.2 bottle.
commit c81a048b0ebea0ba976af220806fb8ef35201e9a (icu4c-64)
Author: BrewTestBot <[email protected]>
Date: Fri Apr 19 03:35:49 2019 +0000
icu4c: update 64.2 bottle.
commit 44895fce117ab92a44d733315b702c48dbb3898d
Author: Chongyu Zhu <[email protected]>
Date: Thu Mar 28 09:47:20 2019 +0800
icu4c 64.2
後面省略 沒用
選一個 64.2版本
git checkout -b icu4c-64 c81a048b0ebea0ba976af220806fb8ef35201e9a
brew reinstall ./icu4c.rb
cd /usr/local/Cellar/icu4c
cp -rf …/icu4c66/66.1 .
記得刪除備份的icu4c66目錄
接下來就可以切換 不同的icu4c了
brew switch icu4c 66.1 (php7時需要)
brew switch icu4c 64.2 (php5.6是需要)
tip:這個切換可以寫在腳本里,比如brew-php-switcher
再執行 就OK了
/usr/local/opt/[email protected]/bin/php -v
PHP 5.6.40 (cli) (built: Apr 23 2019 11:14:34)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
接下來配置Apache
我brew 安裝php56的時候 會默認給我裝個新的Apache。我這裏使用系統自帶的,所以卸載了新裝的
brew uninstall httpd
更改Apache配置
sudo vim /private/etc/apache2/httpd.conf
加入下面內容
LoadModule php5_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp5.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
找到 DirectoryIndex 添加一個index.php
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
然後保存配置,並重啓Apache
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
這一段是解釋PHP的。否則Apache會原樣輸出PHP文件的內容
找到httpd.conf 中DocumentRoot的文件夾
在裏面新建一個index.php
內容如下
<?php
phpinfo();
瀏覽器打開localhost測試