menu

Monday, April 11, 2016

Laravel 5 : Getting started for collaborative development

Hey folks,

Laravel, for those who aren't familiar is a php framework that is widely gaining popularity these days. This came into my attention when I had to implement an HR system in PHP. Usually I would have gone with Symfony, which I know has a larger support base. But the issue is that Symfony has a huge learning curve and I have to work with a team. Laravel on the hand has a less difficult learning procedure and it can be used to start implementation rapidly.

But Laravel it self is really confusing sometimes. Mostly if you are not familiar to tools like composer and git (for collaborative development). So here's a quick tutorial in which I mention steps I took to setup Laravel and a git repo for development.


Requirements

1) Git installed 
You can download git for any platform here,
https://git-scm.com/downloads
Make sure if in windows, that you add Git to shell commands when they ask to, so that you can access git from command prompt at any place.

2) LAMP / WAMP installed
Linux Apache MySQL PHP (LAMP)
Windows Apache MySQL PHP (WAMP)
You can do this per your liking

3) phpMyAdmin installed
If you are a windows user using popular WAMP like XAMPP, you will have phpMyAdmin already installed. LAMP users need to add it manually.

4) Composer installed
Composer is a dependency management tool for Laravel. Much like Maven  (if you are familiar) it will take a list of necessary dependencies and download these to the computer which removes the need of uploading all the 3rd party libraries everywhere.
Download and install composer according to the instructions given here
https://getcomposer.org/download/


Oookay now we are officially ready to start off with the things.

Steps

1) Make an online repository to host your source code
For collaborative development, first thing you need it to host your code somewhere. Since we are using git for source control, we need a host that supports git.
Github : will let you have public repos for free
Bitbucket : will let you have private repos for free (plus team integration with limits)

I went with bitbucket since our code is SUPER SECRET!
So goto bitbucket.org, make a new repo. let's say "AwesomeHR"
Now ask all your team members to sign up with bitbucket as well and in your repo settings, add all of the team members and give them write / read access.

2) Clone your repo to the local drive
It's time to get your repo to your hard drive. Goto your webroot directory (usually www, htdocs, etc depends according to your server) and clone the repo using this command,


git clone https://manzzup@bitbucket.org/manzzup/awesomehr.git


3) Installing Laravel

There are 2 ways of installing Laravel,
One is the official guide in their installation page using composer and laravel installer
https://laravel.com/docs/5.2

Second one is the hard code way in which we download the Laravel master branch from their github repository and extract it where we want. I had more success with this method in several platforms than using the installer (which has varying steps depending on the platform)

i. First download the Laravel master repo as a zip file from their Github repo
You can also use the following link for a direct download
https://github.com/laravel/laravel/archive/master.zip

ii. Next extract it to your newly cloned directory so that when you go into your AwesomeHR folder, it shown all the php files (not laravel-master folder, in that case move everything inside laravel-master to outside)


NOTE:
Now comes a very critical understanding. Laravel has 1000 different 3rd party libraries in use. Those libraries as well as the Laravel core source are NOT included in the zip file you just downloaded. why?

  • Because doing such would make it a very big file
  • We can't always have the latest version of the library if you pre bundle it with the Laravel source, any bug fixes won't reach once downloaded.

So here's how composer come into play. Composer's job is to download all those other libraries into the directory named "vendor" in your Laravel installation and setup them so that it works smoothly.
But keep in mind that you SHOULD NOT copy this vendor directory when you are sharing your code. In other words, the vendor directory be default has a .gitignore file which prevents ANY file inside that folder being uploaded to your remote repo.
Any collaborator using your code has to follow the steps of cloning your repo and then using composer to download the additional libraries.

iv. After that loong discussion, you use the following command while being inside of the extracted folder (AwesomeHR)

composer install

It will take some time for this to complete. Be patient my friend.

To check if all went good, goto http://localhost/AwesomeHR/public/ and you see this



Ta-Daaa you have a fresh Laravel installation now!


4) Configuring Laravel
Still the shit ain't working. Obviously you need to follow an installation procedure.
You need a database for Laravel to store all the data to start with.
Goto phpMyAdmin and make a new database called "laravel"
I will assume our database configuration is as follows

Database name : laravel
Database user : root
Database pass : root
Database host : 127.0.0.1

To make Laravel use these settings, open the .env.example file in your laravel root directory using your IDE or something like SublimeText. (Notepad won't work)
Edit the lines 5 - 8 to match your configuration

DB_HOST=127.0.0.1
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=root

Officially, you can start development with Laravel. You can try a few simple migration codes and make sure the installation is okay. Before you forget, you need to upload the code to the remote repo in bitbucket. Use the following command,

git add .
git commit -m "initial commit"
git push origin master

5) Collaborative development
To use the above code in a team mate's disk, follow these steps

i) Clone the bitbucket repo

git clone https://manzzup@bitbucket.org/manzzup/awesomehr.git

ii) Use composer to install the vendor files

composer install

iii) Do configurations as in step 4


Happy Laravel-ing folks!













6 comments:

  1. Thilina Ashen GamageApril 14, 2016 at 9:21 PM

    Great article machang! Btw GitHub guys have an education support programme for undergraduates and research community, and now you can have private repos for free by entering your college/uni email (eg- name@cse.mrt.ac.lk).

    ReplyDelete
  2. Laravel Development Company: ExpressTech Software Solutions offering Custom Laravel Development Services like Laravel RESTful API Development with Integration solution. +91-9806724185 or Contact@expresstechsoftwares.com

    ReplyDelete