When programming in most languages, you may encounter code compatibility problems in different versions, test code compatibility, or debug old code, which requires different language version environments. ruby has rbenv, rvm, and nodejs as well as nvm. Of course, php should also have a similar phpenv, php-version, and phpbrew to manage PHP versions, I have briefly checked the three tools,
When programming in most languages, you may encounter code compatibility problems in different versions, test code compatibility, or debug old code, which requires different language version environments. ruby has rbenv, rvm, and nodejs as well as nvm. Of course, php should also have a similar phpenv, php-version, and phpbrew to manage PHP versions, I have briefly checked the three tools,
When programming in most languages, Zookeeper will encounter code compatibility problems in different versions, test code compatibility, or debug old code, which requires different language version environments.
Zookeeper ruby has rbenv, rvm, and nodejs as well as nvm. Of course, php should also have a similar phpenv, php-version, and phpbrew to manage PHP versions, after a simple look at these three tools, I prefer phpbrew. In fact, I prefer to call it PHPbrew.
If you are sure you want to use phpbrew, please read this article carefully and try again. Please note! There is a hole in the front (in fact, I recommend vagrant ).
Brew & manage PHP versions in pure PHP at HOME
1. Install PHPbrew
Download:
curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrewchmod +x phpbrewsudo mv phpbrew /usr/bin/phpbrew
2. Simple use
Run the initialization script for your shell environment:
phpbrew init
Set environment variables:
Sudo vi ~ /. Bashrc # Insert the following line of code source ~ /. Phpbrew/bashrc # Save and exit: wq
Show known versions:
phpbrew known===> Fetching release list...[==================================================================] 29.67/29.67KB 100%5.6: 5.6.3, 5.6.2, 5.6.1, 5.6.0 ...5.5: 5.5.19, 5.5.18, 5.5.17, 5.5.16, 5.5.15, 5.5.14, 5.5.13, 5.5.12 ...5.4: 5.4.35, 5.4.34, 5.4.33, 5.4.32, 5.4.31, 5.4.30, 5.4.29, 5.4.28 ...5.3: 5.3.29, 5.3.28, 5.3.27, 5.3.26, 5.3.25, 5.3.24, 5.3.23, 5.3.22 ...You can run `phpbrew update` to get a newer release list.
Show old version:
phpbrew known --old
Update version list:
phpbrew known --update
3. Compile and install PHP
Install PHP by default:
phpbrew install 5.4.0 +default
Test and install:
phpbrew install --test 5.4.0
Display debug information:
phpbrew -d install --test 5.4.0
Install the old version:
phpbrew install --old 5.2.13
Clear the compilation directory:
phpbrew clean
4. PHP compilation Parameters
Display available parameters:
phpbrew variantsVariants: all, apxs2, bcmath, bz2, calendar, cgi, cli, ctype, curl, dba, debug, dom, embed, exif, fileinfo, filter, fpm, ftp, gcov, gd, gettext, gmp, hash, iconv, icu, imap, inifile, inline, intl, ipc, ipv6, json, kerberos, libgcc, mbregex, mbstring, mcrypt, mhash, mysql, opcache, openssl, pcntl, pcre, pdo, pgsql, phar, phpdbg, posix, readline, session, soap, sockets, sqlite, static, tidy, tokenizer, wddx, xml, xml_all, xmlrpc, zip, zlib, ztsVirtual variants: dbs: sqlite, mysql, pgsql, pdo mb: mbstring, mbregex neutral: default: bcmath, bz2, calendar, cli, ctype, dom, fileinfo, filter, ipc, json, mbregex, mbstring, mhash, mcrypt, pcntl, pcre, pdo, phar, posix, readline, sockets, tokenizer, xml, curl, openssl, ziUsing variants to build PHP: phpbrew install php-5.3.10 +default phpbrew install php-5.3.10 +mysql +pdo phpbrew install php-5.3.10 +mysql +pdo +apxs2 phpbrew install php-5.3.10 +mysql +pdo +apxs2=/usr/bin/apxs2
5. other configuration options
phpbrew install 5.3.10 +mysql +sqlite -- \ --enable-ftp --apxs2=/opt/local/apache2/bin/apxs
6. Use and switch
Temporary use:
phpbrew use 5.4.22
Switch version (set the default version ):
phpbrew switch 5.4.18
Close:
phpbrew off
7. display the installed PHP version
phpbrew list
8. Manage FPM
Zookeeper NGINX must be used with php-fpm. ThereforeLNMP
Or you can installNGINX
+PHP
To install PHP, you must add+fpm
Module to usephpbrew
Module management.
phpbrew install 5.6.3 +fpm
Start FPM:
phpbrew fpm start
Stop FPM
phpbrew fpm stop
Display the php-fpm module:
phpbrew fpm module
Test the configuration of php-fpm
phpbrew fpm test
Configure php-fpm
phpbrew fpm config
More plugin extension installation plugin enable extension plugin configuration PHP plugin manage other FPM plugin components (composer, phpunit ).
# Practical notes
OS X notes:
Installation preparation:
brew install automake autoconf curl pcre re2c mhash libtool icu4c gettext jpeg libxml2 mcrypt gmp libevent libpng freetypebrew link icu4cln -s /usr/local/include/freetype2 /usr/local/include/freetype2/freetype
Install phpbrew:
curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrewchmod +x phpbrewsudo mv phpbrew /usr/bin/phpbrewphpbrew initsource ~/.phpbrew/bashrcphpbrew lookup-prefix homebrew
Install php:
# Similar databases cannot be found on other system platforms, manually specify the path phpbrew install 5.3.29 + default + fpm + pdo + mysql + sqlite + gd -- with-gd = shared -- with-jpeg-dir =/usr/local/Cellar -- with-png-dir =/usr/local/Cellar -- enable-gd-native-ttf -- with-freetype-dir =/usr/local/Cellar # print_r (gd_info ());
Note:: If an error is reported during configuration or compilation, check the Requirement page.
Install PHP
Test default config
phpbrew install 5.6.3 --test +defaulttail -f /home/rming/.phpbrew/build/php-5.6.3/build.log
Default Value:
phpbrew install 5.6.3 +default +fpm +pdo +mysql +sqlite +gdtail -f /home/rming/.phpbrew/build/php-5.6.3/build.log
Simplified:
phpbrew install 5.6.3 +fpm +json +dbs +mb +curl +mcrypt +filtertail -f /home/rming/.phpbrew/build/php-5.6.3/build.log
+json
Because phpbrew itself is a phar package and depends on the json function of php
+fpm
Isnginx
, Phpbrew installed php-fpm defaultlisten=127.0.0.1:9000
Therefore, you need to put the previous lnmp configuration filefastcgi_pass
Option changed127.0.0.1:9000
;
+dbs
It is because mysqli extension is not installed and it is difficult to use phpmyadmin;
+mb
The number of bytes encoded in multiple languages. It is used for Chinese Character truncation and matching.
+curl
Curl extensions are very common and you know
+mcrypt
Phpmyadmin needs
+filter
Filter_var Filter Function
Write a script to switch to php-fpm:
function nginxenv(){ phpbrew fpm stop &>/dev/null; phpbrew switch ${1}; phpbrew fpm start &>/dev/null;}
Zookeeper saves the file~/.phpbrew/nginxenv
And then~/.bashrc
Addsource ~/.phpbrew/nginxenv
In the command line, you can usenginxenv 5.3.29
In this way, the version is switched.
Reference:
- PHPbrew Cookbook
- Manual
- Requirement
Original article address: PHP multi-version environment management, thanks to the original author for sharing.