scotch-io / scotch-box

Scotch Box is a preconfigured Vagrant Box with a full array of LAMP Stack features to get you up and running with Vagrant in no time.
http://box.scotch.io
2.7k stars 548 forks source link

Install More Specific PHP Version #404

Open XedinUnknown opened 5 years ago

XedinUnknown commented 5 years ago

Very often, there is a need to change the patch version of PHP installed. For example, my team's policy is that we support at least PHP 7.0.33 (latest patch), and therefore the development environment must be at that version.

A. Update OS Package

One way of doing this is described here. Basically, after logging into your environment (vagrant ssh), you find out what PHP versions are available to you:

sudo apt show -a php7.0 | grep Version

This will produce output, e.g.

Version: 7.0.33-0ubuntu0.16.04.2
Version: 7.0.18-0ubuntu0.16.04.1
Version: 7.0.4-7ubuntu2

Once you know this, you can install a specific version:

sudo apt-get install php7.0=7.0.33-0ubuntu0.16.04.2

B. Build for Specific Requirements

If you have very specific requirements, especially if you need PHP compiled in a certain way, one good solution is using phpbrew. This will allow you to build any PHP version. Be aware, however, that since you are building PHP in your dev environment, that environment will need to contain build requirements, which are very often devel-level packages. There is no definitive list of packages you need, because build requirements for each specific PHP version is different. You can find an example of doing this here.

  1. Install build requirements. These are the different OS packages that are needed to build my specific version, which in that example is PHP 5.5.10.
  2. Install phpbrew. Pretty straight-forward sequence according to the manual, which will result in it having an up-to-date version of recipes.
  3. Compile PHP. Creates a new version available to PHPBrew with specific extensions, and also adds code to the startup script. This helps with running phpbrew in the future.
  4. Switch to new PHP version. This means that the version will now become available.

Another similar approach is by using phpenv, which is gaining popularity.