Lesson 2: Setup Laravel Development Environment

Before we can begin Laravel development, we need to install a few applications on our system and change a few system settings. This is going to be a little long article. However, it is important to follow all the instructions carefully so that you don’t run into problems later.

1. Setup PHP

1.1. PHP Command Setup

We will be using PHP as a command quite often. To make PHP accessible as a command, we need to add PHP executable’s path to our PATH environment variable.

1.1.1. Windows

1. Open Windows command prompt and run the following command:

Skip to the next section if you get output like this:

2. Find out where your PHP executable is located. If you use XAMPP, it should be in C:\xampp\php. For other installations, you can try suggestions in this article: How to determine path to php.exe on windows

3. Once you determine the path, go to Control Panel > System > Advanced System Settings > Environment Variables. You should see a screen like one below:

Environment Variables Window

See the highlighted Path variable in System Variables list (lower half). Select it and click on edit.

4. At the end of the path that is already there, first add a semi-colon (;) and then add the path to your PHP executable. For example, if the path to the executable is C:\xampp\php  then:

Path Before: C:\ProgramData\Oracle\Java\javapath
Path After: C:\ProgramData\Oracle\Java\javapath;C:\xampp\php

5. Click Ok on all windows.

6. Repeat Step 1 to verify if php command now works.

1.1.2. Mac and Linux

1. Open your terminal and run the following command:

Skip to the next section if you get output like this:

2. Find the path to PHP executable. Try searching on Google on how to do so on your OS. If you cannot, let us know in comments with your OS name and version and how you installed PHP. We will try to help you.

3. Run the following command on your terminal:

4. Add following line at the end of file after replacing /path/to/php by the actual path to php.

5. Press Ctrl + O. It will ask which file to write. Simply press Enter. Finally, press Ctrl + X.

6. Restart your terminal and repeat Step 1 to verify if php command runs now.

1.2. PHP Version

Laravel requires us to have latest version of PHP installed on our system. We are going to use Laravel 5.1 which requires PHP 5.5.9 or later.

To check PHP version, run the following command in terminal/command prompt:

It is the same command you ran above to check if PHP is accessible as a command. You will get output like this:

The number after PHP in the second line tells you the PHP version. We have PHP 5.6.12. If your PHP version is lower than 5.5.9, you will need to upgrade it. You can easily find tutorials online telling you how to do the upgrade. Please do it before proceeding.

1.3. Required PHP Extensions

Laravel requires following PHP extensions installed:

  • mbstring
  • openssl
  • mcrypt

A quick way to check if an extensions is installed or not is to run following command:

If it gives the extension name itself as output, it means the extension is installed. If there is no output, then extension is not installed.

If any of the above extensions is not installed, you can install by referring to following pages:

If you have problem installing any extensions, let us know in comments and we will try to help you.

2. Composer

2.1 What is Composer?

Composer is a dependency manager for PHP. It helps us add packages (or libraries) to our project and their dependencies easily. It also does compatibility checks like PHP version, versions of other packages, PHP extensions we need to install, etc., and informs you of any problems.

Composer is a very important tool, and we are going to use it quite often.

Note: Composer is not a package manager. It is only a dependency manager. A package manager installs packages on global basis by default. A dependency manager installs packages on per project basis by default, trying to satisfy dependencies of a particular project.

2.2. Installing Composer

2.1.1. Windows

Installing composer on Windows is pretty straightforward. Download the latest installer from here: https://github.com/composer/windows-setup/releases. Follow the steps and you are done. To test, run following command:

If everything is okay, you should see an output like this:

2.1.2 Mac or Linux

To install on Mac or Linux, run the following command:

Assuming everything goes well, composer should be installed. To test, run:

You should see output like this:

If you get “curl: command not found” or “sudo: command not found” install the respective packages and try again.

3. Laravel

We are now ready to install laravel command. This is not the actual Laravel framework. It’s just a helper command to ease creating of new Laravel projects.

1. Run following command:

2. After command executes successfully, you need to add the laravel executable to your PATH environment variable. The process to follow is exactly same as you followed in Section 1.1 but now with laravel executable path.

For Windows path is: %APPDATA%\Composer\vendor\bin
For Mac or Linux path is: ~/.composer/vendor/bin

To test, run laravel command in your terminal. It should give an output instead of “command not found” error.


Thats it! Congratulations, you are now ready to start developing in Laravel.


Lesson 3: First Laravel Application