Saturday, August 13, 2016

Laravel Project Setup Using Composer

In this tutorial i’ll write the key points that are necessary to create a laravel project/setting a laravel project with the help of composer.

Composer Setup

First We have to understand what is composer?
Well, Composer is a tool used in PHP for dependency management. It allows us to declare the dependent libraries our project needs and it will install them in our project for us.
Basically we tell composer about the files our project requires and composer will find these files for us.
Composer does this in two ways.Which are :
1.Finding the appropriate version of the file
2.Install them for us
Now, we need to set up composer in order to create a new Laravel project.
We can set up composer in two ways in our local machine: Locally or globally.

Locally setting up composer for *nix system

1. Run the following command in terminal
curl -sS https://getcomposer.org/installer | php
if it fails we can download the installer with php instead,
php -r "readfile('https://getcomposer.org/installer');" | php
we can install composer in a specific directory using –install-dir option and providing a target directory
curl -sS https://getcomposer.org/installer | php -- --install-dir=bin
Globally setting up Composer
2. Run the following code In terminal
curl -sS https://getcomposer.org/installer | php
Now move the composer.phar file to /usr/local/bin/composer directory using the following command
mv composer.phar /usr/local/bin/composer
Now you can run composer from your terminal without using
php composer.phar
just run composer
That’s it!
Window’s Installation
In windows you have to download composer and install it like other software.
Download composer from this link Composer
Now Install it. After installing Composer find composer.phar file and copy it to your laravel project. You can download Laravel framework here.
Laravel Framework

Laravel Set Up in Windows

Now unzip the downloaded file.Copy composer.phar file here.
Then run this command in command line
php composer.phar install

Laravel Set Up in Linux


Now you have composer set up in your machine.
Now we will create a new laravel project using composer.
Write the following command in your terminal and see the magic of composer!!!
composer create-project laravel/laravel your-project-name --prefer-dist
Now you’ll see that composer will download and set up all the necessary files required for laravel project.
Instead of using your-project-name , use your other name as project name.
.

Running laravel

Now you have a laravel project created by composer. To start building application , first you have to give read write permission to /app/storage directory in your project (Linux).
In linux environment, you can do that using chmod command.
Now go to the project directory from command line. You can do that by using cd command.
Then run this command:
php artisan serve
You can see that you got a local server running on port 8000.
After that go to the web browser and write localhost:8000
Note
8000 is the port number where my local server is running. You can change the port number if you like. Use this command to change the port number
php artisan serve --port=8080
You can use other number as port number.
Now you will see a welcome message notifying you that laravel framework is working fine in your machine.

0 comments:

Post a Comment