PHP MVC: The Laravel Framework


The Laravel project has made a pretty smart move, that now is also in their quick start guide. They enable you to install it directly through composer! I’ve written about composer once when I ran into a little quirky bug on MacOS.

Using composer, which is a general dependency manager for PHP seems like a big step towards more interchangeable code between different PHP frameworks. I’ve briefly looked into Sparks some time ago, but it’s pretty specifically aimed at the CodeIgniter framework.

Looking at the node.js community, the codex there is to have small, interchangeable modules, that like in the Unix philosophy should only do one thing, but that one thing, it should do well.

In contrast to other PHP MVC frameworks, it is recommended to install laravel through the terminal, which isn’t a big deal, because it’s just very few commands:

Installing composer

I’ve aliased the composer download command and also the usage of it with two bash aliases:

# download Composer
alias getcomposer="curl -s | php"
# alias composer
alias composer="php composer.phar"

You can find more on my github repository for dotfiles.

public_html: $ getcomposer
#!/usr/bin/env php
All settings correct for using Composer

Composer successfully installed to: /home/geronimo/public_html/laravel/composer.phar
Use it: php composer.phar

The output of the installation command reminds me a lot of other package managers like gem/bundler or npm.

Some prominent dependencies installed with composer are doctrine and parts of the symfony framework.

Installing Laravel with Composer

public_html: $ composer create-project laravel/laravel
Installing laravel/laravel (v4.0.0)
  - Installing laravel/laravel (v4.0.0)
    Loading from cache

Created project in /home/geronimo/public_html/laravel
Loading composer repositories with package information
Installing dependencies
  - Installing doctrine/lexer (dev-master bc0e1f0)
    Cloning bc0e1f0cc285127a38c6c8ea88bc5dba2fd53e94

  - Installing doctrine/annotations (v1.1.1)
    Loading from cache

  - Installing doctrine/collections (dev-master 3db3ab8)
    Cloning 3db3ab843ff76774bee4679d4cb3a10cffb0a935

  - Installing doctrine/cache (dev-master 4512314)
    Cloning 45123145f70dd79618963a72a5271b4f389712e4

  - Installing doctrine/inflector (dev-master 8b4b3cc)
    Cloning 8b4b3ccec7aafc596e2fc1e593c9f2e78f939c8c

  - Installing doctrine/common (dev-master 2169b0c)
    Cloning 2169b0ce1d253d448c60b7d40bbe4e4b5afe22fe

  - Installing doctrine/dbal (2.3.x-dev 6a62fef)
    Cloning 6a62fefefde6b2c0d8b3df70151d6a81fc028d28

  - Installing symfony/translation (2.3.x-dev v2.3.0-RC1)
    Cloning v2.3.0-RC1

  - Installing psr/log (1.0.0)
    Loading from cache

  - Installing symfony/routing (2.3.x-dev v2.3.0)
    Cloning v2.3.0

  - Installing symfony/process (2.3.x-dev v2.3.0-RC1)
    Cloning v2.3.0-RC1

  - Installing symfony/debug (2.3.x-dev v2.3.0)
    Cloning v2.3.0

  - Installing symfony/http-foundation (2.3.x-dev v2.3.0-RC1)
    Cloning v2.3.0-RC1

  - Installing symfony/event-dispatcher (2.3.x-dev v2.3.0-RC1)
    Cloning v2.3.0-RC1

  - Installing symfony/http-kernel (2.3.x-dev 4f0f648)
    Cloning 4f0f6485abe0e2e8b8a94369fb98b8447fb1e3cc

  - Installing symfony/finder (2.3.x-dev v2.3.0)
    Cloning v2.3.0

  - Installing symfony/dom-crawler (2.3.x-dev 3cf81e7)
    Cloning 3cf81e7a021853183aa303181afc6e6868bf48ce

  - Installing symfony/css-selector (2.3.x-dev v2.3.0)
    Cloning v2.3.0

  - Installing symfony/console (2.3.x-dev v2.3.0)
    Cloning v2.3.0

  - Installing symfony/browser-kit (2.3.x-dev v2.3.0-RC1)
    Cloning v2.3.0-RC1

  - Installing swiftmailer/swiftmailer (v5.0.0)
    Loading from cache

  - Installing predis/predis (0.8.x-dev aa458a1)
    Cloning aa458a1922a99611d7f81795bedff88459bc8753

  - Installing patchwork/utf8 (v1.1.8)
    Loading from cache

  - Installing nesbot/carbon (1.2.0)
    Loading from cache

  - Installing monolog/monolog (1.5.0)
    Loading from cache

  - Installing filp/whoops (1.0.6)
    Loading from cache

  - Installing ircmaxell/password-compat (1.0.x-dev v1.0.3)
    Cloning v1.0.3

  - Installing nikic/php-parser (dev-master 5ccf619)
    Cloning 5ccf6196d6925e66568e3b8460c262e9512e4b92

  - Installing symfony/filesystem (dev-master 3567f5f)
    Cloning 3567f5f48305098044c6d6a383f5cefec9c45efa

  - Installing classpreloader/classpreloader (dev-master 62c99d5)
    Cloning 62c99d52ce2f1b0b8449c61e2d94f48d918222eb

  - Installing laravel/framework (4.0.x-dev 236c8e5)
    Cloning 236c8e5c6955c88b9713e77c9df9b8205211fc00

symfony/translation suggests installing symfony/config ()
symfony/translation suggests installing symfony/yaml ()
symfony/routing suggests installing symfony/config ()
symfony/routing suggests installing symfony/yaml ()
symfony/debug suggests installing symfony/class-loader ()
symfony/event-dispatcher suggests installing symfony/dependency-injection ()
symfony/http-kernel suggests installing symfony/class-loader ()
symfony/http-kernel suggests installing symfony/config ()
symfony/http-kernel suggests installing symfony/dependency-injection ()
predis/predis suggests installing ext-phpiredis (Allows faster serialization and deserialization of the Redis protocol)
predis/predis suggests installing ext-curl (Allows access to Webdis when paired with phpiredis)
monolog/monolog suggests installing mlehner/gelf-php (Allow sending log messages to a GrayLog2 server)
monolog/monolog suggests installing raven/raven (Allow sending log messages to a Sentry server)
monolog/monolog suggests installing doctrine/couchdb (Allow sending log messages to a CouchDB server)
monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required))
monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server)
Writing lock file
Generating autoload files

If the installation process shows

Laravel requires the Mcrypt PHP extension.

at the bottom of the installation, make sure to install it. On Debian based systems it’s a simple:

sudo apt-get install php5-mcrypt

If you try to run laravel or the accompanying artisan tool it will just output the requirement again, if you don’t have Mcrypt installed.

Accessing Laravel

To take a look at the freshly installed framework, you can now visit the place you installed it and append /public/, in my case: http://localhost/~geronimo/laravel/public/ and you should see something like this:


If you see something like the error message below, you have to quickly change the permissions on the app/storage/sessions/ directory like so:

chmod 777 app/storage/sessions/

(Don’t just 777 stuff in production, I expect you to only do this locally)

Session error message:

SessionHandler::read(): open(/home/geronimo/public_html/laravel/app/storage/sessions/sess_aqt7j4oqnd5bonl4jm42kq3jg4, O_RDWR) failed: Permission denied (13)
open: /home/geronimo/public_html/laravel/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Storage/Proxy/SessionHandlerProxy.php

So far I really like the approach of the framework and I’m looking forward to play with it some more! It’s gotten some attention on tutsplus and I understand why!

Thank you for reading! If you have any comments, additions or questions, please leave them in the form below! You can also tweet them at me

If you want to read more like this, follow me on feedly or other rss readers

Leave a Reply

Your email address will not be published. Required fields are marked *