安裝 Laravel 遇到問題?你需要更新 composer.json 文件
<pre class="markdown-doc">
~~~ url
轉載自 https://9iphp.com/web/laravel/laravel-install-fail-update-composer.html
~~~
在使用最新版 Composer 安裝 Laravel 的時候,你可能會遇到下面的問題而安裝失敗:
~~~ shell
$ php composer.phar create-project --prefer-dist laravel/laravel blog
Installing laravel/laravel (v5.2.15)
- Installing laravel/laravel (v5.2.15)
Created project in blog
> php -r "copy(‘.env.example‘, ‘.env‘);"
> php artisan clear-compiled
PHP Warning: require(/home/vagrant/laraveltest/blog/bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in /home/vagrant/laraveltest/blog/bootstrap/autoload.php on line 17
Script php artisan clear-compiled handling the pre-update-cmd event returned with an error
[RuntimeException]
Error Output: PHP Warning: require(/home/vagrant/laraveltest/blog/bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in /home/vagrant/laraveltest/bl
og/bootstrap/autoload.php on line 17
PHP Fatal error: require(): Failed opening required ‘/home/vagrant/laraveltest/blog/bootstrap/../vendor/autoload.php‘ (include_path=‘.:/usr/share/pear:/usr/share/php‘) in /home/vagr
ant/laraveltest/blog/bootstrap/autoload.php on line 17
create-project [-s|--stability STABILITY] [--prefer-source] [--prefer-dist] [--repository REPOSITORY] [--repository-url REPOSITORY-URL] [--dev] [--no-dev] [--no-plugins] [--no-custom-installers] [--no-scripts] [--no-progress] [--keep-vcs] [--no-install] [--ignore-platform-reqs] [--] [<package>] [<directory>] [<version>]
~~~
這是由於 Composer 最近更新了 pre-update-command 的工作方式,而這會使得 Laravel 安裝失敗。
@Jordi Boggiano 給出的原因如下:
這是由於缺少 composer.lock 文件,因此最初的 install 命令被 update 操作替代,因為它會觸發 pre-update-cmd,而在這之前是觸發的 pre-install-cmd。
幸運的是,修復這個問題非常簡單,只需要把 php artisan clear-compiled 移動到 post-update-command 即可:
![圖片](https://static.9iphp.com/wp-content/uploads/2016/03/laravel-composer-change.png)
</pre>
安裝 Laravel 遇到問題?你需要更新 composer.json 文件