如何在运行不同 php 版本的服务器上安装 Laravel

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29907807/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 11:27:34  来源:igfitidea点击:

How to install laravel on a server running different php versions

phplaravelcomposer-php

提问by Andre Mendes

im having issues to install laravel under my server running php 5.3 by default BUT i'm able to pick a version of php to run under any specific directory.

我在默认情况下在运行 php 5.3 的服务器下安装 laravel 时遇到问题,但我可以选择一个 php 版本在任何特定目录下运行。

guzzlehttp/guzzle 4.1.2 requires php >=5.4.0 -> your PHP version does not satisfy that requirement.

so i choose php 5.4 to run on the directory that im trying to install laravel, but composer do not know that im running PHP 5.4 in that directory.

所以我选择 php 5.4 在我试图安装 laravel 的目录上运行,但作曲家不知道我在那个目录中运行 PHP 5.4。

How to fix this problem?

如何解决这个问题?

回答by kenorb

Try running composercommand with --ignore-platform-reqs, e.g.

尝试运行composer命令--ignore-platform-reqs,例如

composer install --ignore-platform-reqs

回答by ?smail Atkurt

When you execute composer install/updateit runs with your default PHP version of your machine. To make it work with specific versions (that's example path on my Mac) please change it with your executable php path.

当您执行composer install/update它时,它会使用您机器的默认 PHP 版本运行。要使其适用于特定版本(这是我 Mac 上的示例路径),请使用您的可执行 php 路径进行更改。

/usr/local/Cellar/php71/7.1.8_20/bin/php composer.phar install

回答by Flipmedia

This might help some... composer is likely to be using /usr/bin/php, consider the following:-

这可能对某些人有所帮助...作曲家可能正在使用 /usr/bin/php,请考虑以下事项:-

$ which php
/usr/bin/php

$ /usr/bin/php -v
PHP 7.1.33

$ php -v
PHP 7.2.24

$ type -a php
php is aliased to '/usr/bin/php7.2'
php is /usr/bin/php

$ which composer
/usr/local/bin/composer

As you can see our hosting has an alias to ensure the configured version of php (for webserver) is used on command line. But composer is configured to use /usr/bin/php.

正如您所看到的,我们的主机有一个别名,以确保在命令行上使用配置的 php 版本(用于网络服务器)。但是 composer 被配置为使用 /usr/bin/php。

The following is a workaround for the above circumstance.

以下是针对上述情况的解决方法。

Update .bash_aliases file

更新 .bash_aliases 文件

alias php="/usr/bin/php7.2"
alias composer="/usr/bin/php7.2 /usr/local/bin/composer"

Once logged out of terminal and logged back in...

一旦退出终端并重新登录...

$ type -a composer
composer is aliased to '/usr/bin/php7.2 /usr/local/bin/composer'
composer is /usr/local/bin/composer

composer is now using the correct php version.

composer 现在正在使用正确的 php 版本。