レンタルサーバーにおけるComposerのインストール、アンインストール方法


前提:servernameは、ユーザー名に置き換えてください。
   場所は、/home/servernameです。

1.Composerのインストール方法

 レンタルサーバーは、linuxのものが多いです。そんな中、サーバを借りると
 ターミナルでログインする際、telnetもしくはSSHでの接続になります。
 もともとレンタルサーバーでは、yumコマンドは、許可されていません。
 そこで、使用するのが、curlコマンドです。実際、この操作は、何を行うか
 というと、サイトから物をダウンロードし、ディレクトリに展開・格納する
 というもの。実際、下記のコマンドを打ち、Composerを入れます。

 [servername@sv1 ~]$ curl -sS https://getcomposer.org/installer | php
 All settings correct for using Composer
 Downloading...

 Composer (version 1.6.5) successfully installed to:  /home/servername/composer.phar
 Use it: php composer.phar

 「curl -sS https://getcomposer.org/installer | php」と入力してください。
 すると、ダウンロードが始まりインストール成功の文字が英語で表示されます。
 使用可能かの確認は、以下のコマンドを入力してください。

[servername@sv1 ~]$ ./composer.phar -v
~Composerロゴ~
Composer version 1.6.5 2018-05-04 11:44:59
Usage:
command [options] [arguments]

Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--profile Display timing and memory usage information
--no-plugins Whether to disable plugins.
-d, --working-dir=WORKING-DIR If specified, use the given directory as working directory.
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
about Shows the short information about Composer.
archive Creates an archive of this composer package.
browse Opens the package's repository URL or homepage in your browser.
check-platform-reqs Check that platform requirements are satisfied.
clear-cache Clears composer's internal package cache.
clearcache Clears composer's internal package cache.
config Sets config options.
create-project Creates new project from a package into given directory.
depends Shows which packages cause the given package to be installed.
diagnose Diagnoses the system to identify common errors.
dump-autoload Dumps the autoloader.
dumpautoload Dumps the autoloader.
exec Executes a vendored binary/script.
global Allows running commands in the global composer dir ($COMPOSER_HOME).
help Displays help for a command
home Opens the package's repository URL or homepage in your browser.
info Shows information about packages.
init Creates a basic composer.json file in current directory.
install Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
licenses Shows information about licenses of dependencies.
list Lists commands
outdated Shows a list of installed packages that have updates available, including their latest version.
prohibits Shows which packages prevent the given package from being installed.
remove Removes a package from the require or require-dev.
require Adds required packages to your composer.json and installs them.
run-script Runs the scripts defined in composer.json.
search Searches for packages.
self-update Updates composer.phar to the latest version.
selfupdate Updates composer.phar to the latest version.
show Shows information about packages.
status Shows a list of locally modified packages, for packages installed from source.
suggests Shows package suggestions.
update Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.
upgrade Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.
validate Validates a composer.json and composer.lock.
why Shows which packages cause the given package to be installed.
why-not Shows which packages prevent the given package from being installed.

「./composer.phar -v」と入力してください。

なぜ、Composerを挙げたかというと、現在、PHPで人気が出そうなframeworkは、
Laravelです。Composerは、必須です。また、日本で主流なのは、CakePHPです。
こちらも、物によっては、Composerが必要になってきます。
次は、アンインストール手順について説明します。

2.Composerのアンインストール方法

Composerをインストールすると、下記の場所にファイルが置かれます。
それを削除します。

・composer.phar
・.composerフォルダ

削除するには、以下のコマンドを打ちます。
cd /home/servername/
rm -i composer.phar →yを入力します。
rm -r /home/servername/.composer/

これでComposerのアンインストールは全て完了しました。お疲れ様でした。
レンタルサーバーを使用しているとなにをインストールしたかわからなくなりますので
使用しないときには、アンインストールを行ってきれいにしておきましょう。