Tutorial
Composer

Composer is a dependency management tool in PHP. For any PHP project you need to use your library of codes. Composer easily manages that task on your behalf, helping you to declare those codes. You can also install or update any code in your library through Composer. Please visit https://getcomposer.org for more details.
For Windows OS Users

To install composer is very easy. Click on Composer-Setup.exe to download the installer for windows OS.
For Linux / Unix / macOS

In the Figure shown above you will find two links: ‘locally’ and ‘globally’. It stands for two options. Suppose you don’t want to run Composer globally or centrally in your system. In that case, you have to download and install Composer each time for every project. But the global option is always preferable because once Composer is installed in your system bin folder, you can call it anytime for any project. If you are already accustomed to any Linux distribution like Ubuntu, you know that for any local PHP project we used to go to ‘/var/www/html’ folder. Suppose we are going to build a simple Laravel project and we want to name it ‘FirstLaravelProject’. Open up your Ubuntu terminal (ctrl+alt+t) and go to that folder first. To reach there, you need to type the following command on your terminal:
Note:cd /var/www/html/
Once you’ve reached it, you can now make a directory here with the below command:
sudo mkdir FirstLaravelProject
It will ask for your ‘root’ user password. Type the password and a folder called ‘FirstLaravelProject’ will be created. Next in this folder we’ll download and install ‘composer’. Considering you are a beginner, for the sake of brevity I want to download and install Composer locally on our Laravel project
Next Step:
Run these two commands, accordingly as following:
sudo php -r "copy('https://getcomposer.org/installer','composer-setup.php');"
It’ll take some time. Once the installation complated. Run the scond command:
sudo php composer-setup.php
It’ll organize your Composer setup file to go further. Actually your Composer is ready to download packages for your coming project. You can test it by creating a ‘composer. json’ file inside your ‘FirstLaravelProject’ folder. In that ‘composer.json’ file type this:
{"require":{"monolog/monolog": "1.0.*"}}
What does this mean? It means you’re installing ‘monolog’ PHP package for your Laravel project. Will it come to any immediate use? The answer is ‘NO’. We’re actually testing our Composer installer and want to see how it works. Now you can issue the command that will install ‘monolog’ package for you. Type this command on your terminal:
sudo php composer.phar install
It’ll take a little time to install the ‘monolog’ package. It depends on your Internet speed. After the installation is over you’ll find a ‘vendor’ folder and a few ‘composer’ files inside your project. Feel free to discover what is inside the ‘vendor’ folder. There you’ll find two folders: ‘composer’ and ‘monolog’. Again you can see what they have inside them. As a beginner it’s an endless journey to discover new things. Try to get acquainted with everything new you have found. The time has come to install Laravel 5.2 through Composer. You can install Laravel just like monolog. It means that you can write that instruction in your ‘composer.json’ file and just update your Composer. But as a beginner I recommend following the simplest method.
Now! We already installed and test our composer and all is working fine.Next Step:
Installing frsh new Laravel Project!
Open up your terminal and write the following command:
sudo composer create-project --prefer-dist laravel/laravel blog
It’ll install Laravel latest version in the folder ‘blog’ in your Laravel project ‘FirstLaravelProject’. Once it’s done you’ll get the below message on your terminal:
Application key [base64:RUTDKSIUE+2+bZ/ieA8InA4KjA9N4A44AMbqas=] set successfully.
It’s a random key generated each time you install Laravel. It means you have successfully created your first Laravel project.
Congratulation !!!!Installation step completed: you’ve installed Laravel in the ‘/var/www/ html/FirstLaravelProject/blog’ folder. Now you can go inside that folder by writing the following Linux command in the terminal
to see what’s inside. You can type the following command to run your first Laravel application!ls -la
Then you can visit the application by using below link!php artisan serve
to see the welcome page. This installation has been done locally.http://localhost:8000
Bonus Tip:
There is another, easier method. That you use to install Composer globally in your Linux system. Open your terminal and make a directory named ‘Code’ on the desktop. Open up your terminal and type the following command:
cd /Desktop
Now you are inside your desktop. You’re going to make the ‘Code’ directory on your desktop by writing the following command:
mkdir Code
Now you must go inside your ‘Code’ directory by writing the following command on your terminal:
cd Code
Next Step:
Inside ‘Code’ folder make a directory ‘test’, where you’ll create your first Laravel application. to create that write the following command:
mkdir test
Now let’s install Composer globally by writing the following command.
sudo php -r "copy('https://getcomposer.org/installer','composer-setup.php');"
Then follow by the below command
sudo php composer-setup.php
And
sudo php composer.phar install
It’ll take a few minutes to install Composer globally. Once you have done it, you can create any Laravel project anywhere.
Next Step:
Create your first Laravel project inside the ‘Code/test’ folder by writing the foloowing command:
sudo composer create-project --prefer-dist laravel/laravel blog
When Installation is complated, inside the ‘test’ folder, you will see the Laravel project in a folder called ‘blog’. While installing, you can change this name to your choice. It’ll take a few minutes depending on the speed of your Internet connection.
Once it done, you will see the following message:Application key [base64:FrbQTSPezY8wQq+2+bZ/ieA8InA4KjA9N4A44AMbqas=] set successfully.
You have installed the latest version of Laravel 5 on your ‘/Desktop/Cd/test/ blog’ folder. And you have done it globally. Feel free to create any folder and subfolders anywhere in your machine and install Laravel through Composer
Congradulation !!!!You've completed this step: Now laravel is installed inside ‘/Desktop/Code/test/ blog’ folder, and you’ve done it globally.
<button>Press Me!</button>
button {
width:20px;
height:28px;
color:#fff;
font-size:28px;
padding:11px 15px;
border-radius:5px;
background:#14ADE5;
}
<button onclick="myFunction()">Post</button>
<script>
function myFunction() {
document.write(5 + 6);
}
</script>
$(document).ready(function{
jQuery.cssRule(".post", "display", "block");
});