安装
$ sudo php -r "readfile('https://getcomposer.org/installer');" | php$ sudo mv composer.phar /usr/local/bin/composer
使用
以 为例,先看一下他的composer.json文件的内容:
{ "name": "mikecao/flight", "description": "Flight is a fast, simple, extensible framework for PHP. Flight enables you to quickly and easily build RESTful web applications.", "homepage": "http://flightphp.com", "license": "MIT", "authors": [ { "name": "Mike Cao", "email": "mike@mikecao.com", "homepage": "http://www.mikecao.com/", "role": "Original Developer" } ], "require": { "php": ">=5.3.0" }, "autoload": { "files": [ "flight/autoload.php", "flight/Flight.php" ] }, "require-dev": { "phpunit/phpunit": "~4.6" }}
注意 autoload
。
$ cd /var/www/html$ touch index.php$ touch .htaccess
.htaccess
内容如下:
RewriteEngine on RewriteBase / RewriteRule !\.(js|html|ico|gif|jpg|png|css)$ index.php
下载flight:
$ composer require mikecao/flight
看下目录结构:
和index.php
同一级的composer.json
的内容如下:
{ "require": { "mikecao/flight": "^1.2" }}
编写index.php
:
浏览器访问http://127.0.0.1
、http://127.0.0.1/foo
可以看到效果。
修改composer.json后
$ composer install# 或者$ composer update