Home  >  Article  >  Backend Development  >  There are two versions of PHP in the system, which causes problems in the phpunit test.

There are two versions of PHP in the system, which causes problems in the phpunit test.

WBOY
WBOYOriginal
2016-08-08 09:25:291017browse

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

2. Check the version of /usr/bin/php

/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

3. Back up the version of /usr/bin/php, which can be restored when there is a problem

sudo cp /usr/bin/php /usr/bin/php55

4. Delete /usr/bin/php

sudo rm /usr/bin/php

5. Create a softlink pointing to /usr/bin/php php5.6.7 php

sudo ln -s /usr/local/Cellar/php56/5.6.7/bin/php /usr/bin/php

6. Check whether /usr/bin/php has been updated

/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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHPer+Next article:PHPer+