📜 ⬆️ ⬇️

Phpbrew PHP Version Manager. (+ install and use in Ubuntu 13.10)

Lyric number 1


PHP is steadily growing up and acquiring various useful additions, and some of them are already quite like older ones (although the word “younger” will be better in many cases).

In this vein, it is worthwhile, for example, to recall such wonderful things as the dependency manager composer, the built-in web server, the appearance of namespaces and closures.

It so happened that as the working OS I have the latest version of Ubuntu (13.10). For a long time I was content with the latest stable version of PHP from the repositories (apparently lucky), but then the project came to work on 5.3 (or even 5.2, but under 5.3 got started), which did not want to start on the last 5.5.3, which is from official repositories and I was saddened (I already have experience installing irrelevant PHP on Ubuntu, albeit successful, but very sad), but then I remembered ruby ​​and rvm.io and decided to do a little research. As a result, a colleague suggested the thing sounded in the title.
')
The end of the lyric. To the facts.

In short, the only purpose of phpbrew is the ability to use different versions of PHP on the same machine. Quickly, simply, practically without dancing with folk musical instruments. (not production, not parallel work, but instant switching between versions during development).


In order not to spread the thought on the tree I will give (poorly) translated excerpt from the official readme :

phpbrew is able to build and install several different versions of PHP into the current user's home directory.
Also phpbrew helps to manage environment variables - using the use and switch commands you can easily switch between versions of PHP.

What phpbrew can do:


It is worth adding that it does not know how to automatically integrate into nginx .

Installation


1) Install dependencies according to the official requirements document.

# apt-get build-dep php5 # apt-get install -y php5 php5-dev php-pear autoconf automake curl build-essential libxslt1-dev re2c libxml2 libxml2-dev php5-cli bison libbz2-dev libreadline-dev # apt-get install -y libfreetype6 libfreetype6-dev libpng12-0 libpng12-dev libjpeg-dev # libjpeg8-dev libjpeg8 libgd-dev libgd3 libxpm4 # apt-get install -y libssl-dev openssl # apt-get install -y gettext libgettextpo-dev libgettextpo0 # apt-get install -y libicu48 libicu-dev # apt-get install -y libmhash-dev libmhash2 # apt-get install -y libmcrypt-dev libmcrypt4 # apt-get install -y mysql-server mysql-client libmysqlclient-dev libmysqld-dev 

Most likely, you will not need ALL of these dependencies, so it makes sense to set the minimum required to build a clean PHP set, and then focus on the messages of the PHP's configure, which will still be called to verify the system requirements.

2) Install phpbrew itself , all using the same instructions

 $ cd /tmp/ $ curl -O https://raw.github.com/c9s/phpbrew/master/phpbrew $ chmod +x phpbrew $ sudo cp phpbrew /usr/bin/phpbrew 

3) Continue with instructions, initialization

 $ phpbrew init 

4) Add the following line in .bashrc (or .zhrc)

 source ~/.phpbrew/bashrc 

After that, you need to close and reopen the console (or just logout / login, depending on the situation) in order for the new commands to initialize in bashrc. Or self-run in the console

 $ source ~/.phpbrew/bashrc 

Is done. You can use.

Customization


Information from this item is also available in the official readme. And part of it on official troubleshooting .

 $ phpbrew known 

Show a list of available versions (there are versions and older - for them you need to add the –old key to the command)

 $ phpbrew variants 

Show a list of available options for installing PHP. (in fact - extensions with which PHP will be built)
phpbrew install [version] [variants] installs the PHP version with the specified extensions. Variants are listed through space, each starting with a “+”. For example the command:

 $ phpbrew install 5.3.28 +default 

Download and build PHP 5.3.28 with a basic set of components (various zip, json, mbstring and other everyday utilitarian)

 $ phpbrew install 5.3.28 +default +dbs +icu +intl 

* It is worth noting that (most likely, nothing will come together in you, see the Troubleshooting section of this article.

It will load and build PHP 5.3.28 with a basic set of components as well as with icu and intl (intl quite logically fails without ICU, and without intl for some reason PHP 5.3 does not build on Ubuntu)

Here is the lyric number 2, about the root:

To add an automatically compiled module for apache2, the phpbrew install command needs to pass the + apxs2 option . But.
The problem is that Apache and its modules are not in user directories, and therefore phpbrew simply cannot put its module anywhere and will fall when trying to do it.

Workaround'a two - both are quite officially proposed by the author in the section coockbook and both of them do not like me:
1) Install phpbrew and all related things not into the home directory, but system-wide (everything is almost the same as root only) - it turns out that somehow contradicts the original ideology of the project. Detailed in coockbook.
2) Temporarily allow yourself to write to the necessary directories. Then do not forget to ban back. Well, it's just somehow wrong.

For Ubuntu 13.10 and apache 2.4.6, / usr / lib / apache2 / modules / and / etc / apache2 / mods-available / will be needed

 # chmod a+w /usr/lib/apache2/modules/ # chmod a+w /etc/apache2/mods-available/ 

After these preparatory procedures, we install PHP 5.3.28 with a basic set of components, with the apache module, as well as with icu and intl:

 $ phpbrew install 5.3.28 +default +dbs +apxs2 +icu +intl 

Now check what happened:

 $ php -v PHP 5.5.3-1ubuntu2.1 (cli) (built: Dec 12 2013 04:24:35) $ phpbrew use php-5.3.28 $ php -v PHP 5.3.28 (cli) (built: Jan 29 2014 00:55:42) 

Restart apache2 and check it:

 # service apache2 restart 



Add another version in exactly the same way:

 $ phpbrew install 5.5.8 +default +apxs2 +dbs +icu +intl $ phpbrew use php-5.5.8 $ php -v PHP 5.5.8 (cli) (built: Jan 29 2014 01:53:33) 

Restart apache2 again and check:



Everything is ready, it remains to clean up the tails. We return access to the apache system directories to the normal state and transfer ownership of the collected modules to root (well, so that they do not get out of the general flow):

 # chmod aw /usr/lib/apache2/modules/ # chmod aw /etc/apache2/mods-available/ # chown root:root /usr/lib/apache2/modules/libphp5.* 

Install Extensions


Another point is the installation of extensions. Everything is easy - phpbrew is integrated with PEAR.
Just use the command:

$ phpbrew ext install [extension_name]
And then phpbrew will do everything himself. It downloads the extension, builds it and activates for the active version of php. For example:

 $ phpbrew ext install apc 

or:

 $ phpbrew etx install xdebug 

Version switching

Actually further, if you need to switch the CLI version - use phpbrew use [version] (or phpbrew switch [version]), if you need to switch the version for apache2 - look for where our apache module is loaded (in the case of Apache 2.4.6 and Ubuntu 13.10 it will be /etc/apache2/mods-available/php5.load (or simlink in mods-enabled), open it with any text editor and in the line (for example):

 LoadModule php5_module /usr/lib/apache2/modules/libphp5.5.8.so 

change the version to the one we need (and, of course, installed on the system, for example)

 LoadModule php5_module /usr/lib/apache2/modules/libphp5.3.28.so 

Restart apache and:


(yes, you are right, in fact this is the same screenshot as in the first case, nevertheless it reflects objective reality.)

Alternatives:


In addition to this solution, there are also (at a minimum) phpenv and php-version . I suggest to familiarize with them independently (there will be such need)

Troubleshooting


In general, everything is in the official guide. Two things that I personally encountered:

1) The config check complains about missing libpcre. (A | so) and collects nothing under such unseemly pretext.

This is not a phpbrew problem, this problem lies at the junction of ubuntu and php - php and does not try to search for libraries using non-standard paths, Ubuntu, for some reason, keeps them in an off-standard arrangement.

Fortunately, phpbrew allows using the key to pass additional parameters to make. You just have to find these libraries and feed them to the phpbrew install command.

For Ubuntu 13.10 (most likely for all Debian-based distributions), the real command to install php in the version from the article will look like this:

 $ phpbrew install 5.3.28 +default +dbs +apxs2 +icu +intl -- --with-libdir=/usr/lib/x86_64-linux-gnu/ 

2) When building php 5.3, an error like this appears:

 libtool: unrecognized option `-export-dynamic' Try `libtool --help' for more information. 

The bug is specific to 5.3. Just add the options "+ icu + intl" to phpbrew install (as is done everywhere in this article).

Once again, official sources:
  1. phpbrew: github.com/c9s/phpbrew
  2. Readme: github.com/c9s/phpbrew/blob/master/README.md
  3. Troubleshooting: github.com/c9s/phpbrew/wiki/Troubleshooting
  4. Coockbook: github.com/c9s/phpbrew/wiki/Cookbook

Source: https://habr.com/ru/post/210764/


All Articles