Install Laravel PHP by Composer

As we all know Laravel is becoming one of the best php framework nowadays, if you have not know about this php framework, let’s go to Laravel official page then if you want to try this framework let’s go to Install Laravel Homestead to know how to install laravel homestead. This article also provide you another way to install Laravel PHP by Composer.

Laravel series articles

What is composer?

Composer is the most useful tool for dependency management in PHP nowadays. With Composer you can declare the libraries that your project depends on and it will manage (install/update) them for you. For example: phpoffice/excel or phpspec or even Laravel.
Install Laravel php by Composer

How to use composer?

You firstly have to install it, there are a few ways to do this stuff. You can download and install by cURL or you can download the install package. In order to install by cURL you need to install cURL then run the command below or you can go to Composer page for more detail about install composer on window

curl -sS https://getcomposer.org/installer | php

You can check whether you installed Composer or not by run the composer command in terminal, if you see the screen similar to below then you are done!
Install Laravel by Composer

Try to use Composer

Let’s create a folder for you laravel project

cd code
mkdir laravel-example
composer require phpoffice/common
  • In the above command, we have just created a laravel-example folder in the code folder.
  • add library phpoffice dependency by composer

You may wonder why do I know exactly the package have that format syntax. Let’s go to Packagist page and search for phpoffice in the search box then you will see the PHPOffice Common package. The first path is vendor name then after the forward slash is the package name.
Install Laravel by Composer
Just wait a minute for downloading. Composer will download all the dependency that the package required.

After the package has downloaded, let’s check the composer.json file which specify all the information of the package.

cat composer.json
{
   "required": {
       "phpoffice/common": "^0.2.3"
   }
}

so, if we want to give the project for other people we just need to give the composer.json file is enough. They just need to run

composer install

Then they will have all the same package that specify in composer.json, Is that cool?

All the package will be stored in the folder Vendor and we also have some dependencies that those packaged required.

Install Laravel PHP by Composer

Let’s search laravel packagist.org’s search box, you will see the format package for laravel then we can run the command

composer create-project laravel/laravel first-laravel-5

We will need to wait a moment to pull all the source code. In the meanwhile let’s see the syntax of command above

  • composer create-project: we use this to create new project
  • laravel/laravel is the vendor/package code that we mention above
  • first-laravel-5 is the project name, you can name it whatever you want

After the package has downloaded, we go to project folder in this case is “first-laravel-5” then we will see all the base source code.

Let’s start the environment and check the Laravel 5

php -S localhost:8000 -t public

you can use any port you want, in this case I use port 8000. Then open you browser and go to http://localhost:8000 you will see the default Laravel home screen with the text “Laravel 5

Conclusion

We’re done now, let’s summary what we go though in this article

  • We know how to install cURL
  • How to install composer
  • How to use composer to pull the package dependencies and create laravel project as well
  • How to start Laravel 5 environment

That’s, now we all know how to Install Laravel php by Composer – quite fun and easy stuff. We will go though to learn about laravel in the next article. I hope you can follow and install Laravel by Composer yourself. If you have any question, don’t hesitate to leave the comment.

Related Post

Leave a Reply