PHP調用Elasticsearch之composer安裝

安裝 - *nix


下載 Composer 的可執(zhí)行文件

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

注意: 如果上述方法由于某些原因失敗了蚁袭,你還可以通過 php >下載安裝器:

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

這將檢查一些 PHP 的設置,然后下載 composer.phar 到你的工作目錄中石咬。這是 Composer 的二進制文件揩悄。這是一個 PHAR 包(PHP 的歸檔),這是 PHP 的歸檔格式可以幫助用戶在命令行中執(zhí)行一些操作鬼悠。

局部安裝

你可以通過 --install-dir 選項指定 Composer 的安裝目錄(它可以是一個絕對或相對路徑):

php composer-setup.php --install-dir=bin --filename=composer

全局安裝

你可以將此文件放在任何地方删性。如果你把它放在系統(tǒng)的 PATH 目錄中亏娜,你就能在全局訪問它。 在類Unix系統(tǒng)中蹬挺,你甚至可以在使用時不加 php 前綴维贺。

你可以執(zhí)行這些命令讓 composer 在你的系統(tǒng)中進行全局調用:

mv composer.phar /usr/local/bin/composer

現(xiàn)在只需要運行 composer 命令就可以使用 Composer 而不需要輸入 php composer.phar

[elastic@iZm5ebjvditkx9x8pm3dw4Z bin]$ composer
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 1.5.1 2017-08-09 16:07:22

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.
  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.
  suggests        Shows package suggestions.
  update          Updates 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.
[elastic@iZm5ebjvditkx9x8pm3dw4Z bin]$ 

修改鏡像源地址:


為了提升下載安裝包的速度,建議將composer的鏡像源修改為國內(nèi)的源:

官方推薦有兩種使用方法,使用任意一種均可扑庞。

方法一: 修改 composer 的全局配置文件(推薦方式)

打開命令行窗口(windows用戶)或控制臺(Linux贰拿、Mac 用戶)并執(zhí)行如下命令:
composer config -g repo.packagist composer https://packagist.phpcomposer.com

方法二: 修改當前項目的 composer.json 配置文件:

打開命令行窗口(windows用戶)或控制臺(Linux、Mac 用戶),進入你的項目的根目錄(也就是 composer.json 文件所在目錄),執(zhí)行如下命令:
composer config repo.packagist composer https://packagist.phpcomposer.com

上述命令將會在當前項目中的 composer.json 文件的末尾自動添加鏡像的配置信息(你也可以自己手工添加):

"repositories": {
    "packagist": {
        "type": "composer",
        "url": "https://packagist.phpcomposer.com"
    }
}

以 laravel 項目的 composer.json 配置文件為例,執(zhí)行上述命令后如下所示(注意最后幾行):

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.2.*"
    },
    "config": {
        "preferred-install": "dist"
    },
    "repositories": {
        "packagist": {
            "type": "composer",
            "url": "https://packagist.phpcomposer.com"
        }
    }
}

OK肢簿,一切搞定!試一下 composer install 來體驗飛一般的速度吧蜻拨!

鏡像原理:


一般情況下池充,安裝包的數(shù)據(jù)(主要是 zip 文件)一般是從 github.com 上下載的,安裝包的元數(shù)據(jù)是從 packagist.org 上下載的官觅。

然而纵菌,由于眾所周知的原因,國外的網(wǎng)站連接速度很慢休涤,并且隨時可能被“墻”甚至“不存在”咱圆。

“Packagist 中國全量鏡像”所做的就是緩存所有安裝包和元數(shù)據(jù)到國內(nèi)的機房并通過國內(nèi)的 CDN 進行加速,這樣就不必再去向國外的網(wǎng)站發(fā)起請求功氨,從而達到加速 composer install 以及 composer update 的過程序苏,并且更加快速、穩(wěn)定捷凄。因此忱详,即使 packagist.org、github.com 發(fā)生故障(主要是連接速度太慢和被墻)跺涤,你仍然可以下載匈睁、更新安裝包。

修改composer地址參考文檔: Packagist / Composer中國全量鏡像

附:全局安裝英文原文:


Globally#

You can place the Composer PHAR anywhere you wish. If you put it in a directory that is part of your PATH, you can access it globally. On unixy systems you can even make it executable and invoke it without directly using the php interpreter.

After running the installer following the Download page instructions you can run this to move composer.phar to a directory that is in your path:

mv composer.phar /usr/local/bin/composer

Note:

If the above fails due to permissions, you may need to run it again with sudo.

Note:
On some versions of OSX the /usr directory does not exist by default. If you receive the error "/usr/local/bin/composer: No such file or directory" then you must create the directory manually before proceeding: mkdir -p /usr/local/bin.

Note:
For information on changing your PATH, please read the Wikipedia article and/or use Google.

Now just run composer in order to run Composer instead of php composer.phar.

最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末桶错,一起剝皮案震驚了整個濱河市航唆,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌院刁,老刑警劉巖糯钙,帶你破解...
    沈念sama閱讀 222,183評論 6 516
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異,居然都是意外死亡任岸,警方通過查閱死者的電腦和手機再榄,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,850評論 3 399
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來享潜,“玉大人困鸥,你說我怎么就攤上這事∶着觯” “怎么了窝革?”我有些...
    開封第一講書人閱讀 168,766評論 0 361
  • 文/不壞的土叔 我叫張陵购城,是天一觀的道長吕座。 經(jīng)常有香客問我,道長瘪板,這世上最難降的妖魔是什么吴趴? 我笑而不...
    開封第一講書人閱讀 59,854評論 1 299
  • 正文 為了忘掉前任,我火速辦了婚禮侮攀,結果婚禮上锣枝,老公的妹妹穿的比我還像新娘。我一直安慰自己兰英,他們只是感情好撇叁,可當我...
    茶點故事閱讀 68,871評論 6 398
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著畦贸,像睡著了一般陨闹。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上薄坏,一...
    開封第一講書人閱讀 52,457評論 1 311
  • 那天趋厉,我揣著相機與錄音,去河邊找鬼胶坠。 笑死君账,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的沈善。 我是一名探鬼主播乡数,決...
    沈念sama閱讀 40,999評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼闻牡!你這毒婦竟也來了净赴?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 39,914評論 0 277
  • 序言:老撾萬榮一對情侶失蹤澈侠,失蹤者是張志新(化名)和其女友劉穎劫侧,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,465評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡烧栋,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,543評論 3 342
  • 正文 我和宋清朗相戀三年写妥,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片审姓。...
    茶點故事閱讀 40,675評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡珍特,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出魔吐,到底是詐尸還是另有隱情扎筒,我是刑警寧澤,帶...
    沈念sama閱讀 36,354評論 5 351
  • 正文 年R本政府宣布酬姆,位于F島的核電站嗜桌,受9級特大地震影響,放射性物質發(fā)生泄漏辞色。R本人自食惡果不足惜骨宠,卻給世界環(huán)境...
    茶點故事閱讀 42,029評論 3 335
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望相满。 院中可真熱鬧层亿,春花似錦、人聲如沸立美。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,514評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽建蹄。三九已至碌更,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間躲撰,已是汗流浹背针贬。 一陣腳步聲響...
    開封第一講書人閱讀 33,616評論 1 274
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留拢蛋,地道東北人桦他。 一個月前我還...
    沈念sama閱讀 49,091評論 3 378
  • 正文 我出身青樓,卻偏偏與公主長得像谆棱,于是被迫代替她去往敵國和親快压。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,685評論 2 360

推薦閱讀更多精彩內(nèi)容