Should I download Laravel for every project?

2019-02-22 20:04发布

I created a project with Laravel and downloaded from git via this command:

git clone -b develop git://github.com/laravel/laravel.git

The file size was about 21MB,

I want to know should I download Laravel for every project with this command?

2条回答
时光不老,我们不散
2楼-- · 2019-02-22 20:35

Already Leng gave a nice answer.

Installing Laravel since version-4.1* via Laravel Installer is faster than composer

First, download the Laravel installer PHAR archive. For convenience, rename the file to laravel and move it to /usr/local/bin. Once installed, the simple laravel new command will create a fresh Laravel installation in the directory you specify. For instance, laravel new blog would create a directory named blog containing a fresh Laravel installation with all dependencies installed. This method of installation is much faster than installing via Composer.

查看更多
劫难
3楼-- · 2019-02-22 20:56

What you have done is cloned the framework itself, which you should only do if you're going to fork and develop the Laravel core.

What you should do instead is use Composer to install your Laravel projects. You'll also be using Composer for other dependency-related actions in said projects (including autoload). This is the proper way of installing a fresh Laravel framework for developing a website:

composer create-project laravel/laravel --prefer-dist

http://laravel.com/docs/installation

Then, any future Laravel projects you create will be loaded from your Composer cache without needing to re-download.

The Composer package also sets up all your vendor-related .gitignore information and includes several other really useful management features. This is important, because you only want to keep your application-specific code under git version control, not the framework itself or any other dependencies. (Otherwise, your diffs and commits will get polluted with the dependencies' development changes.)

Once you've created a repository for your project, and installed Laravel with Composer, and created your first few commits (with some migrations, models, and controllers, for instance), cloning your project usually works something like this:

cd /clone-here
git clone /myproject # Location of current project
# /clone-here now has only the application-specific files from /myproject.  It is 
# still missing the framework itself and other dependencies.
composer install  # Composer now looks at the dependencies in 
                  # /clone-here/composer.json and installs them into /clone-here/vendor
                  # including the Laravel framework.
# Now the framework and other dependencies are good to go.
php artisan migrate # Laravel makes all your DB schemas from your migrations
php artisan db:seed # Seed your lovely new DB tables

It's really elegant and fun once you get used to it.

Edit: See Sheikh's answer to save some time in the Composer install process!

查看更多
登录 后发表回答