如何在Windows使用Composer
1个回答
展开全部
Composer 是PHP的包管理工具,非常方便。但是安装使用,却没有官方教程那么简单,尤其是在中国,还有Windows下......本篇经验将教你如何正确安装Composer 及正确使用。
使用Composer中文镜像网站,替代国外网站,当你安装完Composer后,使用时,缺发现不能下载包,这是一个众所周知的原因。所以,我们要什么国内的镜像站点进行代替,常用方法有两种:
1. 修改全局配置:全局配置的文件一般放在 C:\Users\XXX\AppData\Roaming\Composer\config.json;
{
"config": {
},
"repositories": [
{"type": "composer", "url": "http://pkg.phpcomposer.com/repo/packagist/"}, {"packagist": false}
]
}
2. 修改当前配置:即项目当前的composer.json文件;
以 laravel 项目的 composer.json 配置文件为例:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"laravel/framework": "4.2.*"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable",
"repositories": [
{"type": "composer", "url": "http://pkg.phpcomposer.com/repo/packagist/"}, {"packagist": false}
]
}
使用Composer中文镜像网站,替代国外网站,当你安装完Composer后,使用时,缺发现不能下载包,这是一个众所周知的原因。所以,我们要什么国内的镜像站点进行代替,常用方法有两种:
1. 修改全局配置:全局配置的文件一般放在 C:\Users\XXX\AppData\Roaming\Composer\config.json;
{
"config": {
},
"repositories": [
{"type": "composer", "url": "http://pkg.phpcomposer.com/repo/packagist/"}, {"packagist": false}
]
}
2. 修改当前配置:即项目当前的composer.json文件;
以 laravel 项目的 composer.json 配置文件为例:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"laravel/framework": "4.2.*"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable",
"repositories": [
{"type": "composer", "url": "http://pkg.phpcomposer.com/repo/packagist/"}, {"packagist": false}
]
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询