环境:ubuntu14.04
官方文档:
http://www.golaravel.com/laravel/docs/4.2/installation/
1.第一步安装 Composer
终端命令(推荐)
4步曲
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
先下载一个composer-setup.php文件,然后校验,然后安装,最后把composer-setup.php文件删掉
我选择手动安装,就是下载一个文件 ,Composer 的 PHAR 打包文件( composer.phar )
https://getcomposer.org/download/
选择最近版本吧
Latest Snapshot
1.2.0 (2016-07-18)
1.2.0-RC (2016-07-04)
1.1.3 (2016-06-26)
1.1.2 (2016-05-31)
1.1.1 (2016-05-17)
1.1.0 (2016-05-10)
下载好后把它放到usr/local/bin
2.第二步安装 Laravel
通过 Laravel 安装器安装
首先,通过 Composer 下载 Laravel 安装器。
wangxiong@Dell:~/Soft/laravel$ /usr/local/bin/composer.phar global require "laravel/installer=~1.1"
/usr/bin/env: php: No such file or directory
噢噢,报错了,没有php这个环境变量,那就连接一个php全局变量吧(ln -s)
我的第一次做法,跑到bin目录下
wangxiong@Dell:/www/wdlinux/php/bin$ sudo ln -s php /usr/local/bin
然后又出现了下面的错误
wangxiong@Dell:~/Soft/laravel$ /usr/local/bin/composer.phar global require "laravel/installer=~1.1"
/usr/bin/env: php: Too many levels of symbolic links
嗷嗷,太多的符号连接
网上解释:
ln -s 源文件 目标文件
源文件和目标文件没有使用绝对路径导致出错
好吧,放大招了
sudo ln -s /www/wdlinux/php/bin/php /usr/local/bin
老司机开车了
wangxiong@Dell:~/Soft/laravel$ /usr/local/bin/composer.phar global require "laravel/installer=~1.1"
Changed current directory to /home/wangxiong/.config/composer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing symfony/process (v2.8.9)
Downloading: 100%
- Installing symfony/polyfill-mbstring (v1.2.0)
Downloading: 100%
- Installing symfony/console (v2.8.9)
Downloading: 100%
- Installing react/promise (v2.4.1)
Downloading: 100%
- Installing guzzlehttp/streams (3.0.0)
Downloading: 100%
- Installing guzzlehttp/ringphp (1.1.0)
Downloading: 100%
- Installing guzzlehttp/guzzle (5.3.1)
Downloading: 100%
- Installing laravel/installer (v1.3.3)
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
最后留意一下安装目录哦~
终端第一句给出了答案~
我的是
/home/wangxiong/.config/composer
最后把vendor/bin这个路径添加到环境变量里
全路径
/home/wangxiong/.config/composer/vendor/bin
打开~/.bashrc
sudo vim ~/.bashrc
添加行:
export PATH=/home/wangxiong/.config/composer/vendor/bin
跑一跑,异常了,oh no
wangxiong@Dell:~/Documents$ laravel new blog
Crafting application...
[GuzzleHttp\Exception\ConnectException]
cURL error 6: See http://curl.haxx.se/libcurl/c/libcurl-errors.html
[GuzzleHttp\Ring\Exception\ConnectException]
cURL error 6: See http://curl.haxx.se/libcurl/c/libcurl-errors.html
new [--dev] [--] [<name>]
吃了个饭回来,重新开车了
wangxiong@Dell:~/Documents$ laravel new blog
Crafting application...
sh: composer: command not found
Application ready! Build something amazing.
虽然提示了一个命令找不到,但还是启动了,不多说了,看帮我们创建了哪些依赖模板
wangxiong@Dell:~/Documents$ cd blog/
wangxiong@Dell:~/Documents/blog$ ls
app composer.json database phpunit.xml resources tests artisan composer.lock gulpfile.js public server.php
bootstrap config package.json readme.md storage
如果检测自己是否Laravel安装成功了,跑跑下面的命令
wangxiong@Dell:/usr/local/bin$ php composer.phar
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 1.2.0 2016-07-19 01:28:52
Usage:
command [options] [arguments]
小插曲:
运行 php artisan env查看当前环境时报错
PHP Fatal error: require(): Failed opening required '/home/wangxiong/Public/workspace_php/my_web/bootstrap/../vendor/autoload.php'
提示少了vendor/autoload.php ,我到项目根目录下一看少了vendor这个文件夹,解决
composer.phar dump-autoload
最后介绍三条重要命令composer dump-autoload, composer update and composer install
composer install installs the vendor packages
composer.lock if not present),
composer update always regenerates composer.lock
packages based on composer.json
composer dump-autoload won’t download a thing. It
to be included in the project (autoload_classmap.php).
Ideal for when you have a new class inside your
project.
Ideally, you execute composer dump-autoload -o
reason it is not default, is because it takes a bit
longer to generate (but is only slightly noticable)
ps:如果新建项目的时候,出现连接异常
[GuzzleHttp\Exception\ConnectException]
cURL error 6: See http://curl.haxx.se/libcurl/c/libcurl-errors.html
链接失败,被墙了,可以更改到国内镜像
composer config -g repo.packagist composer https://packagist.phpcomposer.com