I would like to test my application on PHP 5.3 up to PHP 7.0.
Where and how can I install the versions and how can I switch them by running a small script?
I found this very good tutorial on how to install and switch php versions on OSX.
I can switch the version like
$ sphp 7.0 => PHP 7.0 $ sphp 7.3 => PHP 7.3 $ sphp 7.4 => PHP 7.4
Exactly what I want!
Show current version
$ php -v
Change to different version
(eg. changing from 5.5.x to version 7.0.latest) :
$ brew unlink php55 $ brew install php70
If you have both versions of PHP installed, you can switch between versions using the
For example, to switch between PHP 7.4 and PHP 7.3
brew unlink firstname.lastname@example.org brew link email@example.com
PS: both versions of PHP have be installed for these commands to work.
If you install PHP with homebrew, you can switch between versions very easily. Say you want
php56 to point to Version 5.6.17, you just do:
brew switch php56 5.6.17
i think unlink & link php versions are not enough because we are often using php with apache(httpd), so need to update httpd.conf after switch php version.
i have write shell script for disable/enable
php_module automatically inside
httpd.conf, look at line 46 to line 54 https://github.com/dangquangthai/switch-php-version-on-mac-sierra/blob/master/switch-php#L46
Follow my steps:
1) Check installed php versions by brew, for sure everything good
> brew list | grep php #output php56 php56-intl php56-mcrypt php71 php71-intl php71-mcrypt
2) Run script
> switch-php 71 # or switch-php 56 #output PHP version  found Switching from [php56] to [php71] ... Unlink php56 ... [OK] and Link php71 ... [OK] Updating Apache2.4 Configuration /usr/local/etc/httpd/httpd.conf ... [OK] Restarting Apache2.4 ... [OK] PHP 7.1.11 (cli) (built: Nov 3 2017 08:48:02) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
3) Finally, when your got above message, check
httpd.conf, in my laptop:
You can see near by LoadModule lines
LoadModule php7_module /usr/local/Cellar/php71/7.1.11_22/libexec/apache2/libphp7.so #LoadModule php5_module /usr/local/Cellar/php56/5.6.32_8/libexec/apache2/libphp5.so
4) open httpd://localhost/info.php
i hope it helpful