Under Mac using homebrew to switch between different versions of php

Developed under the recently switched back to Mac, so writing a lot more like the Mac environment deployment articles. We need to switch today about local development environment. Originally wanted to direct development in the current environment, after all Mac comes with PHP environment, today added a new need an extension freetype, require recompiling PHP. Because of this expansion is the core built-in expansion, can not be compiled and installed by phpize. Only one solution is to find PHP installation recompile the source code at compile time, plus -with-freetype-dir.

But I know one thing - Mac is built on PHP, simply can not find the source where it is installed!

So again we need to recompile PHP, and does not affect Mac current PHP environment.

Installation and management software under Mac, of course, can not do without a homebrew.

Install a different version of PHP
BREW install php54
BREW install php55
BREW install php56
BREW install php70
when installing a new version, you will be reminded on a great chance, php version xxx already installed, you need to unlink the original version. So this is the following commands. First unlink install. After installing naturally link better.

Conventional switching
php mounted brew through different versions can be switched Link brew and brew unlink.

brew list
BREW unlink php56
BREW Link php55
large version can brew list to check if it is a small version of the words can only go to / usr / local / Cellar / php55 read. This time using php-version can be a little more convenient.

homebrew, there is a very easy to manage and switch the PHP version of the tool - php-version.

php-version
Installation php-version

brew install php-version
and then execute the following commands. This command may speak the following into ~ / .bashrc or ~ / .zshrc go

source $ (brew --prefix php-version ) /php-version.sh && php-version xxx # xxx is the version number
directly executed

php-version
you can see the current version, such as my own

PHP-Version ~ ➜
5.4.45
5.5.38
5.6.30
* 7.0.20
then use the following commands to switch to

php-version 7.0.20
look version of php, has switched better.

php -v
Note: I am in the early has been installed php7, today when switching versions of php -v has been no change, he misled me. Finally, I first remove this version php70 after install, no problem.

In the IDEA
although in the terminal, php -v already is the latest 7. I had IDEA in the php version is 5.6.30 of. The change up is very simple.

Find php settings in Preference in, say the original / usr / bin / php changed to / usr / local / bin / php can be.

Different versions of the configuration of
each version of the configuration directory

/ usr / local / etc / php / xxx
years, provided as necessary.

Installing an expansion
Suppose we want to install version 5.6 of the plug-mcrypt

brew search php56-mcrypt

brew install php56-mcrypt # installed by default /usr/local/Cellar/under
then find mcrypt.so files, viewing path through pwd, and then edit the PHP configuration file (php.ini):

vi /usr/local/etc/php/xxx/php.ini # brew default configuration file path by
adding code in php file with:

extension=/usr/local/Cellar/php56-mcrypt/5.6/mcrypt.so

Guess you like

Origin www.cnblogs.com/photo520/p/11619154.html