laravel 需要在 hostgator 上的 ssh 上运行“composer update”,但 php -v 为低

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

Need to run 'composer update' on ssh on hostgator, but php -v to low

phplaravelssh

提问by Ehtasham Malik

Need Help

需要帮忙

Framework - Laravel

框架 - Laravel

Hosting - Hostgator

托管 - Hostgator

Problem Statement :- I need to run the 'composer update'. All dependencies required minimun php -v of 5.5.9. I have manualy Upgrade the php version of Project directory to 5.6 from cpanel using 'Php configration' plugin. But when i logged in using ssh, then i got the php -v of 5.4.45. Ofcourse It targeting the deafult php version of the server. Is there any way to update php to 5.6 or above on ssh also. No root user access. No help from support team also.

问题陈述:- 我需要运行“作曲家更新”。所有依赖项都需要 5.5.9 的最小 php -v。我已经使用“Php 配置”插件手动将项目目录的 php 版本从 cpanel 升级到 5.6。但是当我使用 ssh 登录时,我得到了 5.4.45 的 php -v。当然,它针对服务器的默认 php 版本。有没有办法在 ssh 上将 php 更新到 5.6 或更高版本。没有root用户访问权限。支持团队也没有帮助。

回答by Adnan

Use this command in ssh

在 ssh 中使用此命令

$ nano ~/.bashrc

then paste these lines, you can change php version after opt/php55 is 5.5, 71 is 7.1 accordingly

然后粘贴这些行,您可以在 opt/php55 为 5.5 后更改 php 版本,71 相应地为 7.1

alias php='/opt/php71/bin/php'
alias composer='/opt/php71/bin/php ~/bin/composer'
export DRUSH_PHP='/opt/php71/bin/php'

Now, re-source the file so the command line gets the new aliases

现在,重新获取文件的源,以便命令行获取新别名

 $ . ~/.bashrc

now check version

现在检查版本

$ php --version

simple easy trick is if you want to run artisan commands using php7.1 then use this command

简单的技巧是,如果您想使用 php7.1 运行 artisan 命令,请使用此命令

   $ /opt/php71/bin/php artisan

回答by Rama Durai

Recently i update composer and also php in my mac_system
And used these commands by terminal

最近我更新了我的mac_system 中的composer 和 php
并通过终端使用了这些命令

-Local php update in Mac os curl -s http://php-osx.liip.ch/install.sh| bash -s 7.0

-Mac os 中的本地 php 更新 curl -s http://php-osx.liip.ch/install.sh| bash -s 7.0

-export PATH=/usr/local/php5/bin:$PATH (change php version to create project)

-export PATH=/usr/local/php5/bin:$PATH(更改php版本以创建项目)

php update

更新

This above link.. i Used.. So try with command or the link. I think you will get some knowledge on it.

上面的链接..我用过..所以尝试使用命令或链接。我想你会对此有所了解。

回答by brybry

There is actually a workaround to get newer versions of php and composer working via ssh on shared hosting env such as hostgator.

实际上有一种解决方法可以通过 ssh 在共享托管环境(例如 hostgator)上获取较新版本的 php 和 composer。

Try to add the following lines to your .bash_profile or .bashrc and resource your bash shell. The default version of PHP should now be changed to whatever version you specified.

尝试将以下行添加到您的 .bash_profile 或 .bashrc 并为您的 bash shell 提供资源。PHP 的默认版本现在应该更改为您指定的任何版本。

alias php='/opt/php{VERSION_NUMBER}/bin/php'
alias composer='/opt/php{VERSION_NUMBER}/bin/php ~/bin/composer'
export DRUSH_PHP='/opt/php{VERSION_NUMBER}/bin/php'

Use php -v to check the version of php and test if composer works. If composer still doesn't work install it in the ~/bin/composer folder following the instructions First install composer using the instruction https://getcomposer.org/download/.

使用 php -v 检查 php 版本并测试 composer 是否有效。如果 composer 仍然不起作用,请按照说明将其安装在 ~/bin/composer 文件夹中首先使用说明https://getcomposer.org/download/安装 composer 。

At least thats what I did!

至少那是我所做的!

回答by Best K.M.

Just for others who are suffering like me.

只为那些像我一样受苦的人。

You can use my trick in Hostgator command line (CLI). It works for me every time when I want to use CLI with Laravel 5.6 (required PHP 7.1) on Hostgator shared hosting.

您可以在 Hostgator 命令行 (CLI) 中使用我的技巧。每次我想在 Hostgator 共享主机上使用带有 Laravel 5.6(需要 PHP 7.1)的 CLI 时,它都对我有用。

$ /opt/php71/bin/php /home/{your_directory}/composer.phar update

I have a few Laravel projects on the same shared hosting so {your_directory}can be change depending on your project directory path.

我在同一个共享主机上有几个 Laravel 项目,因此{your_directory}可以根据您的项目目录路径进行更改。

回答by user1185554

Using aliases did not work for me. Actually composer did work, but when it called ran artisan, errors such as "Parse error: syntax error, unexpected 'class'" appeared (php5 was used instead of php7)

使用别名对我不起作用。其实composer确实可以工作,但是当它调用ran artisan时,出现了诸如“解析错误:语法错误,意外的'类'”之类的错误(使用php5而不是php7)

Instead I had to copy /opt/php71/bin/phpto ~/home/binthen modify ~/.bash_profileto use my local bin path first

相反,我不得不复制/opt/php71/bin/php~/home/bin然后修改~/.bash_profile先用我的本地bin路径

PATH=~/bin:$PATH

(and I ran . ~/.bash_profileafterwards to apply changes)

(然后我跑去. ~/.bash_profile应用更改)

Would have prefered a symbolic link with ln -s /opt/php71/bin/php ~/binbut it did not work (permission denied).

本来希望使用符号链接,ln -s /opt/php71/bin/php ~/bin但它不起作用(权限被拒绝)。