It seems like you are using an ad blocker. To enhance your experience and support our website, please consider:

  1. Signing in to disable ads on our site. Our users don't see ads
  2. Or, Sign up if you don't have an account yet
  3. Or, disable your adblocker by doing this:
    • Click on the adblocker icon in your browser's toolbar.
    • Select "Pause on this site" or a similar option for lancecourse.com.

Laravel for tortoises - part 3: Installation in toto

By zooboole

Introduction

We're here finally. It's time to get in touch with the Laravel framework. I have dedicated a whole chapter to the installation because it's a very important step in using any framework. You will not do anything if you have a corrupted application or a bad installation. Worse, if you don't have it installed, they won't be coding.

Beside, when installing an application, there are some few things that matter a lot like:

  • The type of your operating system (iOS,Windows,Linux)
  • The version/distribution of the operating system
  • The type of machine you are using(PC, Mac, etc)
  • The shell type (Linux users) you are using
  • etc

These seem to be the source of a lot of confusion and cause many installation problems.

What's installing Laravel?

This may sound weird but I believe there are still people who don't understand what it means to install a framework, especially Windows users. The common habit when it comes to installing softwares is to double click on the launcher and follow the installation process by clicking next, next etc. At the end, there is always a folder that is deposited in your system (in c:programFiles usually on windows.) in which the software resides and you can start it from there or through a shortcut.

When it comes to frameworks, there is no launcher to double click on. We just have the folder/folders to copy into our computer directly. So, actually the Laravel framework is a set of files and folders located in a remote computer(server) that we need to get in our own computer. The folder is like a finished website folder like the ones you are used to have when you build a website. Once you have it in your machine You can just point to it with your local URL(http://localhost/mySite) and launch/run it. The difference is that from the basic files of the framework you can create any type of website/application.

Server Requirements

The server requirement is what your web server should have before it runs very well the laravel php framework. So in order to use the laravel framework properly, you need to have the following installed or enabled:

  • PHP version 5.5.9 or higher
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension

System Requirements: Composer

Since Laravel uses third party packages(like symfony modules) it uses composer to manage those. Laravel framework is also a composer package that has to be downloaded via Composer. Plus, Laravel uses composer autoloading to load classes. All this makes Composer an important piece you should have in your system before installing Laravel. So, head over to composer's website to see how to install it if it's not installed yet in your system. Make all your possible to get it installed because it's very important for you to continue following this tutorial.

Install Laravel

Remember I said that Laravel is just a set of files and folders we're going to grab it and save it in our machine. Actually there are two main places the Laravel project is hosted: in composer's website and in Github.

So to get Laravel we can use composer method which consists of this command line:

composer create-project NAME/OF/PROJECT/IN/COMPOSER/SITE -FLAG

The NAME/OF/PROJECT/IN/COMPOSER/SITE looks like folder/project in composer system. Laravel's is laravel/laravel

Either you are on Windows, Linux, or iOS this command will work once you have composer correctly installed.

So let's use it to install Laravel. Choose a location where the Laravel framework will be placed after dowload. It might be the c:/wamp/www/Laravel if you are using WAMP on windows or your web root on linux systems. Then cd or move to the folder on your command line and enter the following command:

composer create-project laravel/laravel --prefer-dist

After the download is done check your Laravel folder in your system; you should see many folders and files appear. That's it!

Now another thing you could do is not to create the Laravel folder in your web root. You could just cd to your web root like cd c:/wamp/www then you enter the following composer command:

composer create-project laravel/laravel Laravel --prefer-dist

This will automatically create the folder Laravel in www and put all laravel framework files and folder inside. So you will have this at the end c:/wamp/www/Laravel.

Laravel Installer

With the version 5, laravel has brought its own installer that makes the installation much easier. All you have to do with Laravel installer is the enter the following command:

laravel new NameOfTheFolderWhereToPlaceLaravel

If I want to create the same thing as we did with composer above I would do:

laravel new Laravel

Of course you have to cd to the folder where you want to install Laravel before.

But if you entered this command you should receive a message like command not found. It's normal because you must install the laravel installer first. To do that we'll also be using composer:

composer global require "laravel/installer=~1.1"

Then place ~/.composer/vendor/bin in your PATH. By adding it to your PATH, your operating system will be able to find the Laravel executable application.

After that if you want a fresh installation of laravel you could just do:

laravel new MyNewWebSite

And you are good to go. Check the Drowbacks section bellow in case you have problems with this.

Laravel Homestead

If you've heard of VMware, Virtual box, or OS virtualisation you should know that instead of you to work directly on your system, you could set up a virtual machine and do everything on it without affecting your machine.

Laravel is always fighting to help developers work easy and simple. Laravel has set a great development environment that fits the most the laravel framework using vagrant. With Vagrant you will be able to setup a virtual machine in a minute with all softwares requirements and the OS you want.

So there is a well set Vagrant virtual machine that fits Laravel requirements called "Laravel Homestead". So you can just grab it and use it for your development and trainings. The machine has following installed:

  • Ubuntu 14.04
  • PHP 5.6
  • HHVM
  • Nginx
  • MySQL
  • Postgres
  • Node (With PM2, Bower, Grunt, and Gulp)
  • Redis
  • Memcached
  • Beanstalkd
  • Laravel Envoy
  • Blackfire Profiler

Post Installtion Configuration

Good! by now you should have a fresh Laravel installation. Now we just have to do some settings to make everything ready.

Directory Permissions

Grant administrative rights to the following folders storage and bootstrap/cache by running:

chmod -R 777 storage

chmod -R 777 bootstrap/cache

Application Key

If everything went fine with the installation, an application key would have been set for you. It is a string of 32 characters. The is very important for the protection of your data. It's used for the encryption of your data(sessions, database, passwords, etc.). To verify if the key is set open the .env file. You should see somethning like: APP_KEY=O394Bn8xsN1FZsnHP3ArkQtjKvV405Nk. Or you can check it in the config/app.php. If instead of that you have something like: APP_KEY=someRandomString then you need to ask for a key. And to do that, cd to your laravel installation folder and run:

php artisan key:generate

Then copy the key and paste it at those places where you have 'someRandomString';

Drawbacks

Often people meet some little problems especially with the laravel installer. I honestly searched for more than a months a solution to get right. The problem appears usually when it comes to adding the executable to the system PATH. So I went round on the web to look for some cool solutions that worked fine for many people.

If you are on windows read the following feeds concerning how to add the installer to the PATH:

How to install laravel via laravel installer on windows

If you are on Linux especially on ubuntu, and you are having problems with the Laravel installer, try this, it saved me some time:

Check the shell you are using by running echo $0.

If you are using bashrc check this out: laravel installation how to place the composer vendor bin directory in your PATH

If you are using zsh or Laravel Homestead: use this: zsh command not found homestead

For any other problem, you can ask in the forum.

Starting Laravel

With Artisan

Laravel ships a little development server. You can easily use it to start the Laravel framework. To do so just run

php artisan serve

The server will start and give you the url on which you can access the application. It's something like: Laravel development server started on http://localhost:8000/

With Gulp for gurus

Define a gulp task as following:

var gulp         = require('gulp');
var connect      = require('gulp-connect-php');

// PHP Server task

gulp.task('laravel', function(){
    connect.server({ base: './app', keepalive:true, hostname: 'localhost', port:8000, open: true});
});

Now run gulp laravel

Manually

If any of the methods above did not go well for you, you can still go to http://localhost/laravelInstallationFolder/public. So, in case you are using wamp, with our folder used in above command samples, we can have:

http://localhost/laravel/public

Conclusion

If everything is ok, you should have seen this screen when you run Laravel:

Laravel 5

If we all have that, we are good to go. See you in the next part of the tutorial where we're really going to start the basics of coding with Laravel php framework.

If you like this tutorial please share it or comment.

Last updated 2024-01-17 UTC