MACOS10.15brew安装PHP5.6

最简单的是用下面的安装

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测试

image

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