php 如何在共享主机上安装 Composer?

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

How do I install Composer on a shared hosting?

phpcomposer-php

提问by ilhan

I have these things:

我有这些东西:

How can I install Composer? (My aim is to install Restler)

如何安装 Composer?(我的目标是安装Restler

Edit: I do not have SSH access.

编辑:我没有 SSH 访问权限。

采纳答案by Kevin Newman

It depends on the host, but you probably simply can't (you can't on my shared host on Rackspace Cloud Sites - I asked them).

这取决于主机,但您可能根本不能(您不能在我在 Rackspace Cloud 站点上的共享主机上 - 我问过他们)。

What you can do is set up an environment on your dev machine that roughly matches your shared host, and do all of your management through the command line locally. Then when everything is set (you've pulled in all the dependencies, updated, managed with git, etc.) you can "push" that to your shared host over (s)FTP.

您可以做的是在您的开发机器上设置一个与您的共享主机大致匹配的环境,并在本地通过命令行完成您的所有管理。然后当一切都设置好了(你已经拉入了所有的依赖项,更新了,用 git 管理等)你可以通过(s)FTP“推送”到你的共享主机。

回答by Johnathan Elmore

This tutorialworked for me, resolving my issues with /usr/local/bin permission issues and php-cli (which composer requires, and may aliased differently on shared hosting).

本教程对我有用,解决了我的 /usr/local/bin 权限问题和 php-cli(作曲家需要,并且在共享主机上的别名可能不同)的问题。

First run these commands to download and install composer:

首先运行这些命令来下载和安装 composer:

cd ~
mkdir bin
mkdir bin/composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar bin/composer

Determine the location of your php-cli (needed later on):

确定 php-cli 的位置(稍后需要):

which php-cli

(If the above fails, use which php)

(如果以上失败,请使用which php

It should return the path, such as /usr/bin/php-cli, /usr/php/54/usr/bin/php-cli, etc.

它应该返回路径,例如/usr/bin/php-cli、/usr/php/54/usr/bin/php-cli等。

edit ~/.bashrc and make sure this line is at the top, adding it if it is not:

编辑 ~/.bashrc 并确保此行位于顶部,如果不是则添加它:

[ -z "$PS1" ] && return

and then add this alias to the bottom (using the php-cli path that you determined earlier):

然后将此别名添加到底部(使用您之前确定的 php-cli 路径):

alias composer="/usr/bin/php-cli ~/bin/composer/composer.phar"

Finish with these commands:

完成这些命令:

source ~/.bashrc
composer --version

回答by niutech

I have successfully installed Composer (and Laravel) on my shared hosting with only FTP access:

我已经在我的共享主机上成功安装了 Composer(和 Laravel),只有 FTP 访问权限:

  1. Download and install PHPShellon a shared hosting

  2. In PHPShell's config.phpadd a user and an alias:

    php = "php -d suhosin.executor.include.whitelist=phar"

  3. Log in to PHPShell and type: curl -sS https://getcomposer.org/installer | php

  4. When successfully installed, run Composer: php composer.phar

  1. 在共享主机上下载并安装PHPShell

  2. 在 PHPShell 中config.php添加一个用户和一个别名:

    php = "php -d suhosin.executor.include.whitelist=phar"

  3. 登录到 PHPShell 并输入: curl -sS https://getcomposer.org/installer | php

  4. 安装成功后,运行 Composer: php composer.phar

回答by Nikolay Traykov

You can do it that way:

你可以这样做:

  • Create a directory where you want to install composer (let's say /home/your_username/composer)
  • Go to this directory - cd /home/your_username/composer
  • Then run the following command:

    php -r "readfile('https://getcomposer.org/installer');" | php

  • After that if you want to run composer, you can do it this way (in this caseyou must be in the composer's dir): php composer.phar

  • As a next step, you can do this:

    alias composer="/home/your_username/composer/composer.phar".

    And run commands like you do it normally: $ composer install

  • 创建一个你想安装 composer 的目录(比如 /home/your_username/composer)
  • 进入这个目录—— cd /home/your_username/composer
  • 然后运行以下命令:

    php -r "readfile('https://getcomposer.org/installer');" | php

  • 之后,如果你想运行作曲家,你可以这样做(在这种情况下,你必须在作曲家的目录中): php composer.phar

  • 作为下一步,您可以执行以下操作:

    alias composer="/home/your_username/composer/composer.phar".

    并像平常一样运行命令: $ composer install

Hope that helps

希望有帮助

回答by Dung

SIMPLE SOLUTION (tested on Red Hat):

简单的解决方案(在红帽上测试):

run command: curl -sS https://getcomposer.org/installer | php

运行命令: curl -sS https://getcomposer.org/installer | php

to use it: php composer.phar

使用它: php composer.phar

SYSTEM WIDE SOLLUTION (tested on Red Hat):

全系统解决方案(在 Red Hat 上测试):

run command: mv composer.phar /usr/local/bin/composer

运行命令: mv composer.phar /usr/local/bin/composer

to use it: composer update

使用它: composer update

now you can call composer from any directory.

现在您可以从任何目录调用 composer。

Source: http://www.agix.com.au/install-composer-on-centosredhat/

来源:http: //www.agix.com.au/install-composer-on-centosredhat/

回答by ZurabWeb

I was able to install composer on HostGator's shared hosting. Logged in to SSH with Putty, right after login you should be in your home directory, which is usually /home/username, where username is your username obviously. Then ran the curl command posted by @niutech above. This downloaded the composer to my home directory and it's now accessible and working well.

我能够在 HostGator 的共享主机上安装 Composer。使用 Putty 登录到 SSH,登录后您应该在您的主目录中,通常是 /home/username,其中 username 显然是您的用户名。然后运行上面@niutech 发布的 curl 命令。这将作曲家下载到我的主目录,现在可以访问并且运行良好。

回答by devphil

Most of the time you can't - depending on the host. You can contact the support team where your hosting is subscribed to, and if they confirmed that it is really not allowed, you can just set up the composer on your dev machine, and commit and push all dependencies to your live server using Git or whatever you prefer.

大多数时候你不能 - 取决于主机。您可以联系订阅您的托管服务的支持团队,如果他们确认确实不允许这样做,您可以在开发机器上设置 Composer,然后使用 Git 或其他方式提交所有依赖项并将其推送到您的实时服务器你比较喜欢。