window/linux composer安裝/卸載


packagist庫:https://packagist.org/

window  安裝

參考地址:https://www.kancloud.cn/thinkphp/composer/35668

1.composer下載 

https://getcomposer.org ,詳細地址:https://getcomposer.org/Composer-Setup.exe

2.安裝 (全局安裝/局部安裝)

2.1雙擊exe文件

 

安裝完畢

 

檢測是否安裝成功

 

3.使用composer

3.1建立composer文件夾(管理所有composer項目)

3.2建立composer/composer.json,切換國內鏡像

{
    "config": {},
    "repositories": [
        {"type": "composer", "url": "https://packagist.phpcomposer.com"},
        {"packagist": false}
    ]
}

3.3 下載thinkphp文件到 tp5 (tp文件夾要為空,否則會報錯)

composer create-project topthink/think tp5

 

 

 

常見問題:

1.openssl報錯

The openssl extension is required for SSL/TLS protection but is not available. If you can not enable the openssl extension, you can disable this error, at your own risk, by setting the 'disable-tls' option to true.

這是要開啟openssl

解決辦法:

//  查看當前php版本
php -v
// 定位 php.ini位置
php --ini

定位到php.ini位置后,啟用 extension=php_openssl.dll (去掉前面冒號)

備注:使用phpstudy的時候,啟用的是php7.0版本。但是在定位php -v的時候,顯示的php7.2。可能是經常切換的時候,沒有修正過來。

 

 

 

 

linux安裝

21212

 

 

卸載:

卸載依賴包:composer remove phpoffice/phpexcel

刪除composer:

where composer,然后刪除文件即可

 

 

 

鏡像原理(加速,切換國內鏡像 )

參考:https://pkg.phpcomposer.com/

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

然而,由於眾所周知的原因,國外的網站連接速度很慢,並且隨時可能被“牆”甚至“不存在”。

“Packagist 中國全量鏡像”所做的就是緩存所有安裝包和元數據到國內的機房並通過國內的 CDN 進行加速,這樣就不必再去向國外的網站發起請求,從而達到加速 composer install 以及 composer update 的過程,並且更加快速、穩定。因此,即使 packagist.org、github.com 發生故障(主要是連接速度太慢和被牆),你仍然可以下載、更新安裝包。

 

方法一:修改composer配置文件(全局,推薦使用)

1.1 命令修改:

cmd命令:composer config -g repo.packagist composer https://packagist.phpcomposer.com

1.2 手動修改:

 cmd命令:composer config -l -g

 [home] 后面就是配置文件地址

composer.json內容

{
    "config": {},
    "repositories": [
        {"type": "composer", "url": "https://packagist.phpcomposer.com"},
        {"packagist": false}
    ]
}

 

方法二:修改當前項目的 composer.json 配置文件 ,此配置文件是當前項目下的composer.json(E:\wamp64\www\composer\composer.json)

命令修改:

composer config repo.packagist composer https://packagist.phpcomposer.com

此命令是在項目末尾追加代碼,如

{
    "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"
        }
    }
}
View Code

 

手動修改:

composer.json末尾追加

***此處是項目其他代碼 ***
"
repositories": { "packagist": { "type": "composer", "url": "https://packagist.phpcomposer.com" } }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM