使用国内镜像安装laravel (亲测有效)

首先确保,电脑里安装了composer,php.exe,并配好了环境变量。在任何一个目录的CMD里都能运行。

 

同样的也有两种安装方法。

①、修改 composer 的全局配置文件(推荐方式)

        打开命令行窗口(windows用户)或控制台(Linux、Mac 用户)并执行如下命令:

    composer config -g repo.packagist composer https://packagist.phpcomposer.com   //配置国内镜像站点1

    composer config repo.packagist composer https://packagist.laravel-china.org          //配置国内镜像站点2
        然后输入安装命令:

    composer create-project --prefer-dist laravel/laravel blog
        这个速度比较快一点,稍等一会就完成了。

       注意:如果在切换镜像之后,出现(Composer\Downloader\TransportException] The "https://packagist.phpcomposer.com/p/provider-2018-07%249f3939260fd4182fa3207eb59c83753ac2d6df592b1b182dee650e611e119375.json" file could not be downloaded (HTTP/1.1 404 Not Found))这样的报错,则应该去到composer的安装目录,删除config.json

②、修改当前项目的 composer.json 配置文件

        打开命令行窗口(windows用户)或控制台(Linux、Mac 用户),进入你的项目的根目录(也就是 composer.json 文件所在目录),执行如下命令:

    composer config repo.packagist composer https://packagist.phpcomposer.com
        上述命令将会在当前项目中的 composer.json 文件的末尾自动添加镜像的配置信息(你也可以自己手工添加):

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

}
        以 laravel 项目的 composer.json 配置文件为例,执行上述命令后如下所示(注意最后几行):

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.2.*"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~4.0",
        "symfony/css-selector": "2.8.*|3.0.*",
        "symfony/dom-crawler": "2.8.*|3.0.*"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "pre-update-cmd": [
            "php artisan clear-compiled"
        ],
        "post-update-cmd": [
            "php artisan optimize"
        ]
    },
    "config": {
        "preferred-install": "dist"
    },
    "repositories": {
        "packagist": {
            "type": "composer",
            "url": "https://packagist.phpcomposer.com"
        }
    }
}
--------------------- 
感谢作者:Zhihua_W 
来源:CSDN 
原文:https://blog.csdn.net/zhihua_w/article/details/53484562 
版权声明:本文为博主原创文章,转载请附上博文链接!

参考文档:

https://learnku.com/laravel/composer 

本文章于 2019.4.24 修改过

 

 

 

其他的重要composer命令:

composer create-project topthink/think=5.1.* tp5.1 --prefer-dist    composer安装tp5框架

你可能感兴趣的:(Laravel,Composer)