1.安装Composer
安装Composer有两种方式:
全局安装
下载Windows环境下composer安装包局部安装
使用手工方式安装Composer,首先下在composer.phar文件。
使用文本编辑器打开composer.phar可发现如下代码:
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view
* the license that is located at the bottom of this file.
*/
// Avoid APC causing random fatal errors per https://github.com/composer/composer/issues/264
if (extension_loaded('apc') && ini_get('apc.enable_cli') && ini_get('apc.cache_by_default')) {
if (version_compare(phpversion('apc'), '3.0.12', '>=')) {
ini_set('apc.cache_by_default', 0);
} else {
fwrite(STDERR, 'Warning: APC <= 3.0.12 may cause fatal errors when running composer commands.'.PHP_EOL);
fwrite(STDERR, 'Update APC, or set apc.enable_cli or apc.cache_by_default to 0 in your php.ini.'.PHP_EOL);
}
}
Phar::mapPhar('composer.phar');
define('COMPOSER_DEV_WARNING_TIME', 1492865599);
require 'phar://composer.phar/bin/composer';
__HALT_COMPILER(); ?>
创建名为source的项目目录,将composer.phar拖放到项目根目录下。
2. 安装Laravel
Laravel托管在Github中的laravel/laravel项目,同样可使用托管在Packagist上laravel/laravel。
在项目根目录下打开命令行,使用php命令安装Laravel。
(1)全局安装Laravel,指定项目名称为zhihu。
composer create-project laravel/laravel zhihu
(2)局部安装Laravel,指定项目名称为zhihu。
php composer.phar create-project laravel/laravel zhihu
若发现使用Composer安装Laravel下载文件缓慢,可使用中国全量镜像。使用单个项目安装方式,在当前项目中的 composer.json 文件末尾添加镜像配置信息。
"repositories":{
"packagist":{
"type":"composer",
"url":"https://packagist.phpcomposer.com"
}
}
3. 开启web服务器
在命令行中使用php命令开启自带web server,默认网站根路径设置为public目录。
php -S localhost:8000 -t public
项目入口目录位于下载的laravel的public目录下,所有的文件的执行都是从public目录下的index.php文件开始。