[MacOS] PHP dual version, 5.6 and 7.1

Source: Internet
Author: User
Tags install php zend

Turn around, the original look here, 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 in OS x with PHP-FPM

The latest iterations of PHP in the 7.x branch was great improvement over the last PHP 5 version, which is 5.6. However many applications don ' t support it and it'll 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 what 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-make sure, the release is backwards compatible. To a large-a-is true, but there is certain incompatibilities which was 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 is a intermediary step to whole new architecture. Development of new features on EZ Publish is frozen in if the team focused on the new product known as EZ Platform .

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

The the case isn't only for EZ products, but many developers working with PHP would need to keep many versions of the run Time in action for years to come.

Installing versions of PHP with Homebrew

Developers working with PHP on OS X (El Capitan) has 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 IoT like APT or Yum familiar to many Linux users, and for OS X. If you do not have Homebrew installed yet and then head through to the homepage or the installation Guide. As an added benefit to some approaches of running PHP in OS X, you can easily install PHP extensions required to run EZ us ING brew, such as Php-imagick, Php-intl, Php-xsl and others.

Brew has a number of PHP versions in it ' s repositories. They is 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 would 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 would take a and a while to run, but after that you'll have the latest PHP installed. Once This is what you can check the. ve now got PHP-installed by issuing the PHP--version command:

[Email protected] ~-  $ php--versionphp 5.6.18 (CLI) (Built:feb  

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 t o The PHP files:

[Email protected] ~-  $ brew unlink php56unlinking/usr/local/cellar/php56/5.6.18 ... symlinks removed

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

Brew Install PHP70

Once This was done, verify that the default version was now PHP 7:

PHP 7.0.4 (CLI) (Built:mar  9 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 do you can use PHP 5.6 from the command line with the command php56.

Setting up multiple PHP versions using PHP-FPM

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

The Using php-fpm is possible with the Apache Web server as well, but the this case we'll use the Nginx Web server. To install the Nginx with Homebrew, follow these instructions. They contain all, need to get Nginx, and php-fpm running on OS x.

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

Fastcgi_pass 127.0.0.1:9000;

This means, FastCGI requests coming in to Nginx would 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-Php-fpms configured to listening in different ports (9000 and 9056), but they ' re isn't running at the Mome Nt. You'll need to both of them to processes that'll start when booting up the machine. This is do 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'll 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 the 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 same lines with comments to go from PHP 5.6 to 7.0 and 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 runnin G virtual machines.

[MacOS] PHP dual version, 5.6 and 7.1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.