博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[macOS] PHP双版本,5.6跟7.1
阅读量:7052 次
发布时间:2019-06-28

本文共 6506 字,大约阅读时间需要 21 分钟。

转过来的,原文看这里,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  and . 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 .

eZ Publish 5 is  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 .

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  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 .

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 . 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:

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:

janit@turska ~ -  $ php --versionPHP 5.6.18 (cli) (built: Feb  6 2016 06:53:53)Copyright (c) 1997-2016 The PHP GroupZend 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:

janit@turska ~ -  $ brew unlink php56Unlinking /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:

brew install php70

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

PHP 7.0.4 (cli) (built: Mar  9 2016 12:26:14) ( NTS )Copyright (c) 1997-2016 The PHP GroupZend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies    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:

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  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, . 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:

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

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):

mkdir -p ~/Library/LaunchAgents

Copy startup scripts to the LaunchAgents directory:

cp /usr/local/opt/php70/homebrew.mxcl.php70.plist ~/Library/LaunchAgents/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:

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plistlaunchctl 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:

# PHP 7.0fastcgi_pass 127.0.0.1:9000; # PHP 5.6# 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.

转载地址:http://hupol.baihongyu.com/

你可能感兴趣的文章
史上最牛内推小组(持续更新)
查看>>
现实中的路由规则,可能比你想象中复杂的多
查看>>
nginx配置gzip中的坑
查看>>
Javascript中的函数声明与函数表达式
查看>>
Python学习笔记 - queue
查看>>
茶器漫谈 高逼格 or 真内涵?
查看>>
HTML5学习之Web Storage基础知识
查看>>
tab切换
查看>>
垃圾回收及内存调试工具的介绍
查看>>
你的接口,真的能承受高并发吗?
查看>>
自定义View实用小技巧
查看>>
iOS CALayer anchorPoint 的应用场景
查看>>
如何變聰明?訓練自己變成結構化思維型的人!- TechMoon 科技月球
查看>>
超好用的VueJs调试工具——vue-devtools
查看>>
到底怎么才算“懂”python的twisted框架?
查看>>
Flutter 基础布局Widgets之Expanded详解
查看>>
spring cloud微服务分布式云架构- Eureka服务器搭建及配置
查看>>
adb命令集合
查看>>
网站排障分析常用的命令
查看>>
利用inotifywait监控主机文件和目录
查看>>