简体   繁体   English

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

[英]How do I install Composer on a shared hosting?

I have these things:我有这些东西:

How can I install Composer?如何安装 Composer? (My aim is to install Restler ) (我的目标是安装Restler

Edit: I do not have SSH access.编辑:我没有 SSH 访问权限。

This tutorial worked 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

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将它“推送”到你的共享主机。

I have successfully installed Composer (and Laravel) on my shared hosting with only FTP access:我已经在我的共享主机上成功安装了 Composer(和 Laravel),只有 FTP 访问权限:

  1. Download and install PHPShell on a shared hosting在共享主机上下载并安装PHPShell

  2. In PHPShell's config.php add a user and an alias:在 PHPShell 的config.php添加一个用户和一个别名:

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

  3. Log in to PHPShell and type: curl -sS https://getcomposer.org/installer | php登录 PHPShell 并输入: curl -sS https://getcomposer.org/installer | php curl -sS https://getcomposer.org/installer | php

  4. When successfully installed, run Composer: php composer.phar安装成功后,运行 Composer: php composer.phar

You can do it that way:你可以这样做:

  • Create a directory where you want to install composer (let's say /home/your_username/composer)创建一个你想安装 composer 的目录(比如 /home/your_username/composer)
  • Go to this directory - cd /home/your_username/composer转到此目录 - 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之后如果你想运行composer,你可以这样做(在这种情况下你必须在composer的目录中): php composer.phar

  • As a next step, you can do this:作为下一步,您可以执行以下操作:

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

    And run commands like you do it normally: $ composer install并像往常一样运行命令: $ composer install

Hope that helps希望有帮助

I was able to install composer on HostGator's shared hosting.我能够在 HostGator 的共享主机上安装 Composer。 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.使用 Putty 登录 SSH,登录后您应该在您的主目录中,通常是 /home/username,其中 username 显然是您的用户名。 Then ran the curl command posted by @niutech above.然后运行上面@niutech 发布的 curl 命令。 This downloaded the composer to my home directory and it's now accessible and working well.这将作曲家下载到我的主目录,现在可以访问并且运行良好。

SIMPLE SOLUTION (tested on Red Hat):简单的解决方案(在红帽上测试):

run command: curl -sS https://getcomposer.org/installer | php运行命令: 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/

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 或其他方式提交所有依赖项并将其推送到您的实时服务器你比较喜欢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM