laravel - 安装laravel框架

Composer 安装 Laravel 有两种方式:

第一种是通过 Composer 的 create-project 命令安装 Laravel 框架,
第二种是先通过 Composer 安装 Laravel 安装器,然后通过安装器安装 Laravel 框架。

为什么 Composer 可以安装 Laravel 框架呢?

其实 Laravel框架也是一个 Composer包,我们可以通过如下命令查看:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
uiste:~ uiste$ composer show --all laravel/laravel
No composer.json found in the current directory, showing available packages from packagist
name : laravel/laravel
descrip. : The Laravel Framework.
keywords : framework, laravel
versions : dev-master, v5.3.10, v5.3.0, 5.2.x-dev, v5.2.31, v5.2.29, v5.2.27, v5.2.24, v5.2.23, v5.2.15, v5.2.0, 5.1.x-dev, v5.1.33, v5.1.11, v5.1.4, v5.1.3, v5.1.1, v5.1.0, 5.0.x-dev, v5.0.22, v5.0.16, v5.0.1, v5.0.0, v4.2.11, v4.2.0, v4.1.27, v4.1.18, v4.1.0, v4.0.9, v4.0.8, v4.0.7, v4.0.6, v4.0.5, v4.0.4, v4.0.0, v4.0.0-BETA4, v4.0.0-BETA3, dev-develop
type : project
license : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
source : [git] https://github.com/laravel/laravel.git f4606d2bb94dc9579488df61fa3744b17e91be62
dist : [zip] https://packagist.phpcomposer.com/files/laravel/laravel/f4606d2bb94dc9579488df61fa3744b17e91be62.zip f4606d2bb94dc9579488df61fa3744b17e91be62
names : laravel/laravel

autoload
classmap
database
psr-4
App\ => app/

requires
php >=5.6.4
laravel/framework 5.3.*

requires (dev)
fzaninotto/faker ~1.4
mockery/mockery 0.9.*
phpunit/phpunit ~5.0
symfony/css-selector 3.1.*
symfony/dom-crawler 3.1.*

create-project

第一种通过 Composer的 create-project 命令安装 Laravel 框架,

$ composer create-project laravel/laravel --prefer-dist [别名]

Laravel 安装器

第二种是先通过 Composer 安装 Laravel 安装器,然后通过安装器安装 Laravel 框架。

  1. 使用 composer 全局安装 Laravel 安装器

$ composer global require "laravel/installer"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
uiste:~ uiste$ composer global require "laravel/installer"
Changed current directory to /Users/uiste/.composer
Using version ^1.3 for laravel/installer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing symfony/process (v3.1.4)
Downloading: 100%

- Installing symfony/polyfill-mbstring (v1.2.0)
Downloading: 100%

- Installing symfony/console (v3.1.4)
Downloading: 100%

- Installing guzzlehttp/promises (1.2.0)
Downloading: 100%

- Installing psr/http-message (1.0.1)
Downloading: 100%

- Installing guzzlehttp/psr7 (1.3.1)
Downloading: 100%

- Installing guzzlehttp/guzzle (6.2.1)
Downloading: 100%

- Installing laravel/installer (v1.3.4)
Downloading: 100%

symfony/console suggests installing symfony/event-dispatcher ()
symfony/console suggests installing psr/log (For using the console logger)
Writing lock file
Generating autoload files
  1. 配置PATH环境变量

~/.composer/vendor/bin 添加到 PATH 环境变量中,这样可执行文件 laravel 就能被你的系统检测到了。

编辑 ~/.bash_profile 文件, vim ~/.bash_profile 加入如下代码:

export PATH="~/.composer/vendor/bin:$PATH"

  1. 检测是否配置成功

新打开一个终端,输入如下命令:

1
2
uiste:~ uiste$ laravel --version
Laravel Installer version 1.3.3

如果出现该信息,说明安装器已安装成功。

  1. 安装Laravel

打开终端,输入如下命令即可安装:

$ laravel new blog

1
2
3
4
5
6
7
8
uiste:~ uiste$ laravel new blog


[RuntimeException]
Application already exists!


new [--dev] [--5.2] [--] [<name>]
  1. 安装最新的开发版本

如果童鞋们对最新的开发版本比较感兴趣,可以下载进行测试,加上 –dev 参数即可:

$ laravel new demo –dev


报错如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
uiste:~ uiste$ laravel new blog
Crafting application...
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Your requirements could not be resolved to an installable set of packages.

Problem 1
- This package requires php >=5.6.4 but your PHP version (5.5.36) does not satisfy that requirement.
Problem 2
- Installation request for laravel/framework v5.3.15 -> satisfiable by laravel/framework[v5.3.15].
- laravel/framework v5.3.15 requires php >=5.6.4 -> your PHP version (5.5.36) does not satisfy that requirement.
Problem 3
- Installation request for phpunit/php-code-coverage 4.0.1 -> satisfiable by phpunit/php-code-coverage[4.0.1].
- phpunit/php-code-coverage 4.0.1 requires php ^5.6 || ^7.0 -> your PHP version (5.5.36) does not satisfy that requirement.
Problem 4
- Installation request for phpunit/phpunit 5.5.5 -> satisfiable by phpunit/phpunit[5.5.5].
- phpunit/phpunit 5.5.5 requires php ^5.6 || ^7.0 -> your PHP version (5.5.36) does not satisfy that requirement.
Problem 5
- Installation request for phpunit/phpunit-mock-objects 3.2.7 -> satisfiable by phpunit/phpunit-mock-objects[3.2.7].
- phpunit/phpunit-mock-objects 3.2.7 requires php ^5.6 || ^7.0 -> your PHP version (5.5.36) does not satisfy that requirement.
Problem 6
- Installation request for sebastian/code-unit-reverse-lookup 1.0.0 -> satisfiable by sebastian/code-unit-reverse-lookup[1.0.0].
- sebastian/code-unit-reverse-lookup 1.0.0 requires php >=5.6 -> your PHP version (5.5.36) does not satisfy that requirement.
Problem 7
- Installation request for sebastian/object-enumerator 1.0.0 -> satisfiable by sebastian/object-enumerator[1.0.0].
- sebastian/object-enumerator 1.0.0 requires php >=5.6 -> your PHP version (5.5.36) does not satisfy that requirement.
Problem 8
- Installation request for sebastian/resource-operations 1.0.0 -> satisfiable by sebastian/resource-operations[1.0.0].
- sebastian/resource-operations 1.0.0 requires php >=5.6.0 -> your PHP version (5.5.36) does not satisfy that requirement.
Problem 9
- Installation request for sebastian/version 2.0.0 -> satisfiable by sebastian/version[2.0.0].
- sebastian/version 2.0.0 requires php >=5.6 -> your PHP version (5.5.36) does not satisfy that requirement.

Application ready! Build something amazing.

Mac OS X 升级PHP版本

方法一:

  1. 查询本机PHP版本
1
2
3
4
uiste:~ uiste$ php -v
PHP 5.5.36 (cli) (built: May 29 2015 01:07:06)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
  1. 然后我们根据实际需求去升级

curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6.4

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
uiste:~ uiste$ curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6.4
Detected OS X El Capitan 10.11. All ok.
Get packager.tgz
Unpack packager.tgz
Please type in your password, as we want to install this into /usr/local

WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.

To proceed, enter your password, or type Ctrl-C to abort.

Password:
Start packager (may take some time)
downloading https://s3-eu-west-1.amazonaws.com/php-osx.liip.ch/install/5.6.4-frontenddev-latest.dat
downloading https://s3-eu-west-1.amazonaws.com/php-osx.liip.ch/<?xml version="1.0" encoding="UTF-8"?>

downloading https://s3-eu-west-1.amazonaws.com/php-osx.liip.ch/5.6.4-frontenddev.tar.bz2
downloading https://s3-eu-west-1.amazonaws.com/php-osx.liip.ch/5.6.4-frontenddev.tar.gz
downloading https://s3-eu-west-1.amazonaws.com/php-osx.liip.ch/5.6.4-frontenddev.tgz
Did or could not download package: 5.6.4-frontenddev

中途会提示你输入密码,下载的 PHP 会放置到 /usr/local 下,但不会覆盖原系统 PHP
如上所升级的 5.5,PHP 会位于 /usr/local/php5 中,并自动链接到 /etc/apache2/ 下的配置文件
然后再新建一个 PHP 文件,写上 phpinfo(); 浏览器访问看看,版本已经升级。