Home > Article > Backend Development > There are two versions of PHP in the system, which causes problems in the phpunit test.
Today we are setting up a local LAMP development environment. Because the system’s built-in PHP version is 5.5.14, but the development needs to use php 5.6 or above, so PHP 5.6.7 is installed. This results in two versions of php existing in the system.
Normal development is no problem, but if phpunit is used, phpunit will call the system’s own php 5.5.14 for execution. The PHP extensions I installed (such as memcache, redis, etc.) are all installed on the version of PHP 5.6.7.
When using phpunit for unit testing, it will prompt that the extension is not installed. (e.g. memcache function not found). The php that
phpunit calls is /usr/bin/php, so pointing the php in this location to the current php5.6.7 version can solve the problem.
The solution is as follows:
1. Check the currently used php version
php -v PHP 5.6.7 (cli) (built: Apr 20 2015 23:10:47) (DEBUG) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies with Xdebug v2.3.2, Copyright (c) 2002-2015, by Derick Rethans
/usr/bin/php -v PHP 5.5.14 (cli) (built: Sep 9 2014 19:09:25) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
sudo cp /usr/bin/php /usr/bin/php55
sudo rm /usr/bin/php
sudo ln -s /usr/local/Cellar/php56/5.6.7/bin/php /usr/bin/php
/usr/bin/php -v PHP 5.6.7 (cli) (built: Apr 20 2015 23:10:47) (DEBUG) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies with Xdebug v2.3.2, Copyright (c) 2002-2015, by Derick Rethans
After execution, the problem is solved.
The above introduces the solutions to problems caused by the existence of two versions of PHP in the system, including the aspects of phpunit testing. I hope it will be helpful to friends who are interested in PHP tutorials.