How to create a new project from CLI in Laravel?

Laravel is an open-source and free PHP Framework for Web Artisans. It is based on Symfony, which helps craft Web Applications following the MVC (Model View Controller) design pattern. In Laravel applications we mainly work with Models, Views and Controllers. Let’s learn how to create a new project from CLI in Laravel,

There are two ways to create a new Laravel application, one is using the Laravel installer. The other requires a Laravel package to be used via a composer and a create-project command.

Create a New Project Via Laravel Installer

Firstly, you can download the Laravel installer using the Composer package.

composer global require "laravel/installer=~1.1"

You should place the  ~/.composer/vendor/bin directory in your PATH variable. If you are working with windows, you can also add in C:\%HOMEPATH%\AppData\Roaming\Composer\vendor\bin. This finds laravel executablewhen running the laravel  command in terminal.

Once Laravel is installed, the laravel new command creates a fresh Laravel installation in any directory you specify. For example, laravel new posts creates a directory named posts which contains a fresh Laravel installation with all required dependencies installed. This installation method is pretty faster than installation via Composer.

Create a New Project Via Composer

The Laravel framework utilizes Composer for installation and dependency management. If you haven’t already, start by installing Composer.

Laravel framework makes use of the Composer for installations and to manage dependencies. You can start this process by installing a composer.

Secondly, you can install Laravel by passing the command below from your terminal.

composer create-project laravel/laravel posts

This will download and install a fresh copy of Laravel with your project’s name (posts) folder within your current directory. You can cd to any directory and run this command. Laravel project folder will be create in that directory.

If you want to, you can also download a copy of the Laravel repository from GitHub manually. Then run the composer install command in the root of this manually created project directory. The command will download and install Laravel framework’s dependencies.