转过来的,原文看这里,https://www.symfony.fi/page/how-to-run-both-php-5-6-and-php-7-x-with-homebrew-on-os-x-with-php-fpm

How to run both PHP 5.6 and PHP 7.x with Homebrew on OS X with PHP-FPM

The latest iterations of PHP in the 7.x branch are great improvement over the last PHP 5 version, which is 5.6. However many applications don't support it and it will be useful to run many versions on a local environment. In my case a laptop running macOS (OS X) and using the Homebrew packet manager. This is how to run both PHP 5.6 and PHP 7.1 simultaneously.

PHP 7.0 was a large release of the popular programming language and platform powering large parts of the web. The new release of PHP brings performance improvements and new features. The PHP community goes to great lengths to make sure that the release is backwards compatible. To a large part this is true, but there are certain incompatibilities which are described in the official Migration Guide.

eZ Publish 5 is a hybrid application with both contemporary PHP as well as older code dating back to 2003. That version was an intermediary step to more to a whole new architecture. Development of new features on eZ Publish was frozen in 2014 when the team focused on the new product known as eZ Platform.

Despite not receiving new features, eZ Publish is still a valid product and will continue to be supported way until 2021. The last major version was released before PHP 7 was launched and will likely never receive (official) support for it. The new Symfony Framework powered eZ Platform is already stable with PHP 7 for development use.

This is the case not only for eZ products, but many developers working with PHP will need to keep many versions of the runtime in action for years to come.

Installing two versions of PHP with Homebrew

Developers working with PHP on OS X (El Capitan) have a number of options for installing PHP. Ranging from enabling the built in PHP to running a dedicated virtual machine for the LAMP environment. One great option is to use the Homebrew packet manager.

Homebrew is a lot like APT or Yum familiar to many Linux users, but for OS X. If you do don't have Homebrew installed yet, then head over to the homepage or the installation guide. As an added benefit to some approaches of running PHP on OS X, you can easily install PHP extensions required to run eZ using brew, such as php-imagick, php-intl, php-xsl and others.

Brew has a number of PHP versions in it's repositories. They are specified in the package names with a number, such as php56 for PHP 5.6 and php70 for PHP 7.0. The "dot releases" in PHP bring new functionalities and can brake backwards compatibility, so in the future there will be packages like php71 for PHP 7.1 in the future.

Once you've got the packet manager up and running it's time to install PHP. Let's start with installing PHP 5.6:

  1. brew install php56

This will take a while to run, but after that you will have the latest PHP 56 installed. Once this is done you can check that you've now got PHP 56 installed by issuing the php --version command:

  1. janit@turska ~ - $ php --version
  2. PHP 5.6.18 (cli) (built: Feb 6 2016 06:53:53)
  3. Copyright (c) 1997-2016 The PHP Group
  4. Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

However in this case we'll want to make PHP 7.0 the default version, so we'll need to issue a command to remove symlinks to the PHP files:

  1. janit@turska ~ - $ brew unlink php56
  2. Unlinking /usr/local/Cellar/php56/5.6.18... 18 symlinks removed

This now removed filesystem links pointing to php56. Next we'll want to install PHP 7.0:

  1. brew install php70

Once this is done, verify that the default version is now PHP 7:

  1. PHP 7.0.4 (cli) (built: Mar 9 2016 12:26:14) ( NTS )
  2. Copyright (c) 1997-2016 The PHP Group
  3. Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
  4. with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

To make it easy for us to run PHP 5.6 on the command line by creating a symlink and using it:

  1. ln -s /usr/local/Cellar/php56/5.6.NN/bin/php /usr/local/bin/php56

Once this is done you can use PHP 5.6 from the command line with the command php56.

Setting up multiple PHP versions using PHP-FPM

PHP is most often used to power web applications, so we'll need to link our two PHP versions to versions. PHP-FPM is a modern way of running PHP with a process manager and the FastCGI protocol. This enables high performance as well as easy switching between various versions of PHP.

Using PHP-FPM is possible with the Apache web server as well, but in this case we'll use the Nginx web server. To install Nginx with Homebrew, follow these instructions. They contain all that you need to get Nginx and PHP-FPM running on OS X.

By default PHP-FPM is configured to use ports for communication. An IP Addressand a Port together form a Socket, which allows running multiple backends with a single IP. In case of PHP-FPM the default socket used is marked in the virtual host configurations (located in /usr/local/etc/nginx/servers/) with:

  1. fastcgi_pass 127.0.0.1:9000;

This means that FastCGI requests coming in to Nginx will be passed to a PHP process manager listening at IP 127.0.0.1 and port 9000. The port 9000 is just a default value and we can modify it by changing the configurations. We'll leave PHP 7.0 to listen in the default port, but set 5.6 to listen to port 9056.

Open up the configuration file in a text editor: /usr/local/etc/php/5.6/fpm.d/www.conf

  1. listen = 127.0.0.1:9056

Now we've got two PHP-FPMs configured to listening in different ports (9000 and 9056), but they're not running at the moment. You'll need to both of them to processes that will start when booting up the machine. This is done using the standard Homebrew approach.

Create the directory for Launch agents (it might already exist):

  1. mkdir -p ~/Library/LaunchAgents

Copy startup scripts to the LaunchAgents directory:

  1. cp /usr/local/opt/php70/homebrew.mxcl.php70.plist ~/Library/LaunchAgents/
  2. cp /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/

Finally launch both PHP-FPM processes - only required this time, they will start automatically on next boot up:

  1. launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist
  2. launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist

Next you'll want to create two virtual hosts for Nginx and configure them to different ports. In your eZ Platform config, for example you'll only need to switch between the two lines with comments to go from PHP 5.6 to 7.0 and back to 5.6:

  1. # PHP 7.0
  2. fastcgi_pass 127.0.0.1:9000;
  3.  
  4. # PHP 5.6
  5. # fastcgi_pass 127.0.0.1:9056;

That's it, you can now switch back and forth between different PHP versions when using OS X without the overhead of running virtual machines.

[macOS] PHP双版本,5.6跟7.1的更多相关文章

  1. windows下怎么解决Python双版本问题

    相信大家会在windows下会遇到Python双版本问题 当我们装了Python2和Python3时我们好只能在命令栏调出最高版本的那个低版本的难道消失了吗?今天我们就解决这个问题! 1.下载 我们在 ...

  2. python在windows(双版本)及linux环境下安装

    python下载 下载地址:https://www.python.org/downloads/ 可以下载需要的版本,这里选择2.7.12和3.6.2 下面第一个是linux版本,第二个是windows ...

  3. 【转】Windows下安装python2和python3双版本

    [转]Windows下安装python2和python3双版本 现在大家常用的桌面操作系统有:Windows.Mac OS.ubuntu,其中Mac OS 和 ubuntu上都会自带python.这里 ...

  4. 如何在openWRT系统上实现双版本

    最近由于项目需要,需要在AR9331芯片单板(原来是4MBFlash,后来扩充到16MB Flash)上,实现openwrt双版本机制. 双版本的好处,主要是:在升级版本过程中,如果遇到断电等情况,不 ...

  5. centos下搭建python双版本环境

    目录 centos下搭建python双版本环境 一.安装python3 1.理清自带python位置 2.更新用于下载编译python3的相关包 3.安装pip 4.用pip安装wget 5.用wge ...

  6. python在windows(双版本)及linux(源码编译)环境下安装

    python下载 下载地址:https://www.python.org/downloads/ 可以下载需要的版本,这里选择2.7.12和3.6.2 下面第一个是linux版本,第二个是windows ...

  7. [转帖]如何在VirtualBox中运行macOS Catalina Beta版本

    如何在VirtualBox中运行macOS Catalina Beta版本 secist2019-08-03共2179人围观系统安全 https://www.freebuf.com/articles/ ...

  8. [linux]centos7.4上升级python2版本到python3.6.5 【安装双版本,默认python3】

    版本声明 centos7.4 前言:linux上的python默认是版本2的,之前学django项目用的是3的版本 所以得升级下版本~ 1.下载python3.6.5 cd /usr/local/ w ...

  9. Windows下安装python2和python3双版本

    现在大家常用的桌面操作系统有:Windows.Mac OS.ubuntu,其中Mac OS 和 ubuntu上都会自带python.这里我们只介绍下Windows(我用的Win10)环境下的pytho ...

随机推荐

  1. 5.动态代理AOP实现-DynamicProxy模式

    通过动态代理模式Interceptor实现在RegUser()方法本身业务前后加上一些自己的功能,如:PreProceed和PostProceed,即不修改UserProcessor类又能增加新功能 ...

  2. 阿里云ECS服务器无法上传文件的解决方案

    1.安装软件启动FTP服务 yum install vsftpd # 安装service vsftpd start # 启动服务chkconfig vsftpd on # 开机启动 2.防火墙ipta ...

  3. bootstrap 列表組

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  4. 【静默】在RHEL 6.5上静默安装Oracle 18c

    [静默]在RHEL 6.5上静默安装Oracle 18c Oracle 18c.18c其实就是12.2.0.2,19c就是12.2.0.3.db_home.zip 安装包大概4.25G,解压后有8.9 ...

  5. 蜕变成蝶~Linux设备驱动之异步通知和异步I/O

    在设备驱动中使用异步通知可以使得对设备的访问可进行时,由驱动主动通知应用程序进行访问.因此,使用无阻塞I/O的应用程序无需轮询设备是否可访问,而阻塞访问也可以被类似“中断”的异步通知所取代.异步通知类 ...

  6. CPU高速缓存行与内存关系 及并发MESI 协议

    先来一个整体图 一. 大致关系: CPU Cache --> 前端总线 FSB (下图中的Bus) --> Memory 内存 CPU 为了更快的执行代码.于是当从内存中读取数据时,并不是 ...

  7. lua 中protobuf repeated 嵌套类 复合类型

    PB基础知识科普 syntax = "proto2"; package PB; message Item { required string name = ; } message ...

  8. SpringBoot------集成MyBatis报错

    在spring boot启动main方法所在的类中加入 @MapperScan注入后报错: Invalid default: public abstract java.lang.Class org.m ...

  9. 浅谈一下Windows下的用户权限

    大学毕业后,选择做了苹果开发,一直是使用的Mac系统,所以对Windows的基本操作忘得几乎一干二净:因为做内网穿透的需要,要用到Windows下的权限问题,所以重新研究了一下Windows设置用户权 ...

  10. 【thinkphp5.1】 endroid/qrcode 二维码生成

    composer 链接: https://packagist.org/packages/endroid/qrcode 注意:PHP版本 要求 7.1+ 1. 使用 composer 安装 endroi ...