Operating system: MAC OS
The script v.php opened by the browser
<?php
phpinfo();
输出的版本是``PHP Version 5.6.30``
The command line executes php v.php, the output version is:
PHP 7.1.6 (cli) (built: Jun 26 2017 00:06:58) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
Is this what is the reason?
为情所困2017-06-26 10:50:55
Maybe there are two versions of PHP on the computer.
The PHP version used by the localhost server mounted by Apache is 5.6;
The PHP version used by the global php command is 7.1.
漂亮男人2017-06-26 10:50:55
Amend this sentence in /etc/apache2/httpd.conf
#LoadModule php5_module /usr/local/Cellar/php56/5.6.15/libexec/apache2/libphp5.so
LoadModule php7_module libexec/apache2/libphp7.so //具体地址也可能不是这个,自己搜下
There is also a function to load configuration
cd /etc/apache2/other/
sudo cp php5.conf php7.conf
chmod 755 php7.conf #原文件只可读不可写
Modify php7.conf
<IfModule php7_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>
Modify httpd.conf
#Include /private/etc/apache2/other/*.conf #注释
添加
<IfModule php5_module>
Include /private/etc/apache2/other/php5.conf
</IfModule>
<IfModule php7_module>
Include /private/etc/apache2/other/php7.conf
</IfModule>