在 php 7.0 上使用 Laravel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51793311/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using Laravel on php 7.0
提问by lucasvm1980
I have installed Laravel 5.5 and I'm getting the same error, documentation says this:
我已经安装了 Laravel 5.5 并且遇到了同样的错误,文档是这样说的:
- PHP >= 7.0.0
- OpenSSL PHP Extension
- PDO PHP Extension
- Mbstring PHP Extension
- Tokenizer PHP Extension
- XML PHP Extension
- PHP >= 7.0.0
- OpenSSL PHP 扩展
- PDO PHP 扩展
- Mbstring PHP 扩展
- 分词器 PHP 扩展
- XML PHP 扩展
I ran:
$ php artisan --version`
$ Laravel Framework 5.5.42
我跑了:
$ php artisan --version`
$ Laravel Framework 5.5.42
and I'm getting this error:
我收到此错误:
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_PARSE)
Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE)
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_PARSE)
Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE)
Is the documentation wrong? I'm using: https://laravel.com/docs/5.5/installation#installing-laravelMy server can only use PHP 7.0. Not 7.1. Is there no way to run Laravel on 7 anymore?
文档有错吗?我正在使用:https: //laravel.com/docs/5.5/installation#installing-laravel我的服务器只能使用 PHP 7.0。不是 7.1。有没有办法在 7 上运行 Laravel 了?
I'm installing via composer.
我正在通过作曲家安装。
Is there a way to download a compatible version with 7.0?
有没有办法下载与 7.0 兼容的版本?
回答by Ignacio Alles
If you have PHP 5.5 (actually 5.5.9 or greater) you should use Laravel 5.2.
如果您有 PHP 5.5(实际上是 5.5.9 或更高版本),您应该使用Laravel 5.2。
If you have PHP 7.0 you can use Laravel 5.5.
如果你有 PHP 7.0,你可以使用Laravel 5.5。
The error you mentioned is because you are using PHP 5.5 which does not support PHP 7 Null coalescing operator (??) and it is being used somewhere in Laravel code.
您提到的错误是因为您使用的是 PHP 5.5,它不支持 PHP 7 Null 合并运算符 (??) 并且它正在 Laravel 代码中的某处使用。
As you said your server supports PHP 7.0, you might have more than one PHP versions installed on your system. Check PHP version running php --version
.
正如您所说,您的服务器支持 PHP 7.0,您的系统上可能安装了多个 PHP 版本。检查正在运行的 PHP 版本php --version
。
回答by Niraj Shah
The issue could be that the command line version of PHP differs to the Apache version of PHP. Run php --version
and verify that you're using PHP 7.0.0 or greater.
问题可能是 PHP 的命令行版本与 PHP 的 Apache 版本不同。运行php --version
并验证您使用的是 PHP 7.0.0 或更高版本。
Laravel 5.5.* has no issues running on PHP 7.0.*. I currently have a project running Laravel 5.5.43 on PHP 7.0.15 and this issue does not occur.
Laravel 5.5.* 在 PHP 7.0.* 上运行没有问题。我目前有一个在 PHP 7.0.15 上运行 Laravel 5.5.43 的项目,但没有发生此问题。
If the command line version of PHP is not up to date or if you have access to multiple versions of PHP, you should contact your hosting provider for help. You may also be able to run a command similar to the following to see if you can access a different version of PHP:
如果 PHP 的命令行版本不是最新的,或者如果您可以访问多个版本的 PHP,您应该联系您的托管服务提供商寻求帮助。您还可以运行类似于以下内容的命令来查看是否可以访问不同版本的 PHP:
locate bin/php
The above may give you an idea of the installation location. For example, I see three different versions of PHP installed, but the default version (/usr/bin/php
) is 7.0.15:
以上可能会让您对安装位置有所了解。例如,我看到安装了三个不同版本的 PHP,但默认版本 ( /usr/bin/php
) 是 7.0.15:
/opt/cpanel/ea-php56/root/usr/bin/php
/opt/cpanel/ea-php70/root/usr/bin/php
/opt/cpanel/ea-php71/root/usr/bin/php
/usr/bin/php
回答by lucasvm1980
It was an issue with the Symfony Translation stack, i had to disable for the moment, also i have downgraded the carbon package to make it work, not sure why. It has some php7.1 code.
这是 Symfony Translation 堆栈的一个问题,我暂时不得不禁用,而且我已经降级了 carbon 包以使其工作,不知道为什么。它有一些 php7.1 代码。