dsfovbm931034814
dsfovbm931034814
2016-09-24 21:20
浏览 33
已采纳

服务器与CLI上的不同版本的PHP

I am running a Mac, and unfortunately have the different versions of PHP running in the CLI and on Apache. I have searched and can find instances of this question before but have not been able find a reason this occurs or how to resolve the issue.

When I run phpinfo(); and load it in the browser I get the following:

Version 5.6.24

Loaded config file: /etc/php.ini

Server Path: /usr/bin:/bin:/usr/sbin:/sbin

But when I run php -v & php --ini in the command line, I get the following:

Version 5.6.0

Loaded config file: /usr/local/lib/php.ini

When I run 'whereis php' it shows /usr/bin/php and when I run 'which php' I get /usr/local/bin/php.

Can anyone explain why this has happened? And does anyone know how this can be resolved? I would like to, if possible, resolve the underlying issue rather than find a workaround. I'd also like to uninstall the version of PHP that is not being used.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dttnb997315
    dttnb997315 2016-09-24 22:07
    已采纳

    Your path is set to the wrong/older version. Do a export PATH=/usr/local/php5/bin:$PATH

    Restart the terminal and php -v

    Alternatively have a look at Have a look at: Mac upgraded PHP to 5.6, but CLI php -v get 5.3.28? and follow @mark-reed comment on the @bing answer.

    点赞 评论
  • dpvomqeu396484
    dpvomqeu396484 2018-12-19 08:05

    Same issue with my computer.

    When i check php version on terminal

    Nanhes-MacBook-Pro:~ nanhekumar$ php -v
    

    PHP 7.1.16 (cli) (built: Apr 1 2018 14:10:37) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

    http://localhost/info.php

    PHP Version 7.1.25

    Solution

    you can view installed php through brew list in my case it is showing php@7.1

    Nanhes-MacBook-Pro:~ nanhekumar$ brew link php@7.1
    
    
    If you need to have this software first in your PATH instead consider running:
      echo 'export PATH="/usr/local/opt/php@7.1/bin:$PATH"' >> ~/.bash_profile
      echo 'export PATH="/usr/local/opt/php@7.1/sbin:$PATH"' >> ~/.bash_profile
    

    Then run this on terminal

    echo 'export PATH="/usr/local/opt/php@7.1/bin:$PATH"' >> ~/.bash_profile
    echo 'export PATH="/usr/local/opt/php@7.1/sbin:$PATH"' >> ~/.bash_profile
    

    Restart terminal and again check your php version both php version are same.

    点赞 评论

相关推荐