Installation and Setup of Laravel 5.1

Access all tutorials in sprocket icon.

June 13, 2015 from author Bill Keck.

Let’s do a fresh install of Laravel 5.1. I’m going to assume you have a development environment setup. If not, check out my previous post on
development environments before continuing.

Please note that you need to use a minimum PHP build of 5.5.9. You can set this by opening MAMP, selecting preferences, then PHP.

In my fresh install of MAMP, I’m using PHP 5.6.7, so you should choose this as well if you are using MAMP. If you do make a change, remember to restart the servers, so the change will take effect.

Also note: While you can certainly install Laravel 5.1 on a windows machine using MAMP or some other development environment, the instructions I’m giving here are for Mac OSX, using the development tools I listed in my development environments
post, which includes MAMP.

Also, for convenience, you can reference the Laravel install docs directly
here, should you need to refer to them.

Ok, let’s jump in:

Step 1. Create Local Host Entry

We will modify our hosts file.

From the command line, type:



sudo vim /private/etc/hosts

Remember when using vim, we use i for insert, so we can begin typing. Then create an entry for:



127.0.0.1       www.mydomain.com   mydomain.com

Obviously mydomain represents your project name. You can also use the extension .dev instead of .com if you choose, a lot of developers like to do it that way.

Then hit escape on the keyboard, then :wq and enter to write and quit. That local host entry should now be saved.

Step 2. Listen for Vhosts in httpd.conf

If you placed your MAMP build in your applications folder, go to applications/MAMP/conf/apache/httpd.conf and open the file using your IDE or other suitable text editor. Make sure the following line is uncommented:



# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf

Now we’re listening for our vhosts entries.

Step 3. Configure Vhost For Our Application

Go to Applications/MAMP/conf/apache/extra/httpd-vhosts.conf and open the file using your IDE or other suitable text editor and add the following:



    <VirtualHost *:80>
   ServerAdmin webmaster@dummy-host2.example.com
   DocumentRoot "/Users/billk/var/www/mydomain/public"
   ServerName mydomain.com
   ErrorLog "logs/dummy-host2.example.com-error_log"
   CustomLog "logs/dummy-host2.example.com-access_log" common
    </VirtualHost>

The important thing to note here is the DocumentRoot. In my case, I have my project folder on /Users/billk/var/www. You should set yours accordingly, /path/to/mydomain/public.

Also note the ServerName is set to mydomain.com, which obviously you will replace with your projectname.com.

Ultimately, it’s the public folder within our application that is accessible via the web. We’re leaving the example entries for the logs as we will not be using them in our tutorial.

Step 4. Start or restart MAMP. If you have not previously created shortcut on the dock, you should do so now. MAMP should be in your applications folder and you can drag it to the dock for future use.

Open the application and click the start servers button. If MAMP was previously running, you must restart it in order for the changes in the host entry and the vhosts to take effect.

Step 5. Use composer inside the billk/var/www directory to install a new build of laravel

Obviously if your path is different, you would use your path, you are not going to have a billk directory, for example.

To navigate to the correct directory from the command line, first type:



cd ~

That will get you to the base directory. From there type:



cd var/www/

Gotcha: Do not put a backslash in front of the first folder, if you start with /var, it will bring you to the wrong location.

Ok, now that we’re in the right folder, we can pull in Laravel via composer, assuming you have installed composer. If you have not installed composer, do so now. You can pull it down from getcomposer.org.

Let’s assume you have composer installed globally and can use it in this directory. Type the following:



composer create-project laravel/laravel mydomain --prefer-distribution

It will likely take a couple of minutes to download. This will also create the project folder and place laravel within it.

Step 6. Create project in PHP Storm or your IDE.

These instructions are for PHPStorm. If you do not have it, you can download a free trial PHPStorm.

Now, select create new project from existing files. Then select the last option on the first screen, which is Source files are in a local directory no web server is configured. Click Next.

In the directory tree, navigate to your project folder, highlight it by clicking on it, then click the Project Root near the top left of the dialog. Then click finish.

And that’s pretty much it for basic install. If you navigate your browser to mydomain.com, again using your project name, it should pull up the Laravel welcome page.

In my next Laravel tutorial, we will configure the database and continue to setup a basic application in Laravel 5.1. I hope you have enjoyed this tutorial and found it useful. Click on the sprocket icon at the top of the page to see all tutorials. Please comment, share, and like if you can, thanks!

I don’t have a donate button, but If you would like to support my work and learn more about Laravel, you can do so by buying one of my books, Laraboot: laravel 5* For Beginners, I really appreciate it.