Please note that this chapter was written for VERSION 3 of the Laravel PHP Framework.
Laravel is a PHP 5.3 web application framework written by Taylor Otwell. It was written with PHP 5.3 features in mind. The combination of these features and its very expressive syntax has led to the framework gaining in popularity.
In this book we will be exploring Laravel from the ground up starting with its installation, which I am sure you will agree is a breeze.
In order to use any PHP Framework (not just Laravel) you will need to have a PHP enabled web server, I would recommend installing a web server on your local development machine, to allow you to test your work without needing to upload your files each time you make a change.
This chapter makes the following assumptions:
- You have a working Apache-based web server with PHP5.3+.
- You are familiar with the server's file system, and how to move / copy files.
- You have access to modify Apache configuration files.
If you are using a different web server, you will be able to find many articles on-line on how to accomplish the tasks found below for your server.
First we will need a copy of the framework's source code, simply head over to Laravel.com and hit the big orange download button. For added security, I would recommend extracting the contents of the package to somewhere other than your web root. Make a mental note of where you extracted the source to (or find a sticky note!).
We now have two options to allow the framework to execute as expected, I would advise trying the first method as it is the "real" way of installing the framework and will allow us to specify a more thorough configuration. However I find the second method much quicker when working with many projects on a development server.
Method 1 Create a new VirtualHost
We will need to create a new Apache configuration file. On most standard installations creating a
myproject.conf file in the Apache
conf.d directory will include it by default, please see the documentation for your current set-up for more information.
Inside our new configuration file, paste or type the following VirtualHost declaration:
<VirtualHost 127.0.0.2> DocumentRoot "/path/to/laravel/project/public" ServerName myproject <Directory "/path/to/laravel/project/public"> Options Indexes FollowSymLinks MultiViews AllowOverride all </Directory> </VirtualHost>
We must update the IP address to one which is not currently in use. (Best not to use
127.0.0.1, this is your loop-back address, and you may have something else using it.) Change the two paths to point to your Laravel source package's
public directory. Now restart your web server.
Next we will create a new local DNS entry to point a project name to your VirtualHost. First open the hosts file normally found at
c:\windows\system32\drivers\etc\hosts on a Windows machine or
/etc/hosts on unix-based operating systems.
Add the following line using the IP address and server name you used in your VirtualHost declaration:
You should now be able to navigate to
http://myproject with your web browser to see the Laravel welcome page.
Method 2 Symbolic link the public directory.
If you are familiar with using symbolic links on a unix-based system, this method will prove rather simple.
Inside the extracted Laravel source code (you remember where you put it, right?) you will find a sub directory called 'public'. This directory contains the Laravel bootstrap file and all public assets. We will be symbolic linking this directory to your public web root (possibly /var/www/html/).
To create the symbolic link simply execute the following command in your terminal of choice, replacing the paths where necessary.
ln -s /path/to/laravel/public/directory /path/to/web/root/subdirectory
For example :
ln -s /home/dayle/laravel/myapp/public /var/www/html/myapp
Note: You could also symbolic link the public directory directly to your web root, but I prefer using a subdirectory so I can work on several projects.
You should now be able to navigate to
http://localhost/myapp with your web browser to see the Laravel welcome page.
Getting back on track..
At this point you should now be able to see your Laravel welcome page, if so..
Congratulations! You have a brand new Laravel project, you are now ready to get coding!
In the next chapter we will be covering the Laravel project structure, and providing an explanation of each of the important files and directories.
If you happen to find any of the topics covered in this book confusing, the following links can be used to find the help and support you need, or simply post a new comment on DayleRees.com.
Why not come and join our ever expanding community by using an IRC client to connect to
irc.freenode.net:6667 and joining the
My books are available online for free to encourage learning. However, if you'd like for me to keep writing, then please consider buying a digital copy over at Leanpub.com.
It's available in PDF, ePub, and Kindle format, and contains a bunch of extras that you won't find on the site. I have a full-time job, and I write my books in my spare time. Please consider buying a copy so that I can continue to write new books from the comfort of my sofa!