Skip to main content

Laravel vs Symfony

The Right Tool for the Job

The phone rings. You pick it up. It’s the national lottery — they tell you that if you can be at their office within 15 minutes, you get the entire pot, upwards of 15 million dollars!

But you’re at home, not so close to that office. You need to decide on the spot how to get there. Right now, in the middle of rush hour, going by car may take more than 15 minutes. But riding your bike might also take more than 15 minutes. You have now 30 seconds to decide and your heart is racing, because the phone call was real and he was serious. What will you choose?

That’s the lottery. 🙂

Now at work, your boss demands that the new site build start immediately and you must decide which framework to use. Probably you have more than 30 seconds to decide, but on some level, the pressure may be as high to decide and make the right decision.

This is the issue we are going to examine today — what is the right tool for the job? A car and a bike are very different tools, but each one has its place. Same for a hammer and a screwdriver — each works great for what it’s made for, and not very well for other things.

Regarding our field, PHP web development, the available tools are a bit more complicated than a hammer or screwdriver and it’s usually far less clear which is the right tool.

PHP Frameworks

In the PHP framework marketplace, there are a lot options, including (more or less in order of popularity) Laravel, Symfony, CodeIgniter, CakePHP, Yii, Silex, Zend Framework, Phalcon, Slim Framework, Nette, FuelPHP, Kohana, li3, PHPixie, Fat Free Framework, Aura, PureMVC, PRADO, Nova Framework (formerly Simple MVC Framework) and Flight.

Over the past few years, Laravel has taken over the field of PHP frameworks, with today a market share of around 3 times that of Symfony or CodeIgniter. Symfony, however, is not strictly a MVC framework like Laravel is. Symfony can be used as a framework, but it’s strength is as a set of decoupled components, which can be used independently, and Laravel itself actually uses several Symfony components.

But the fact remains that the most common question asked in the PHP framework world is what are the differences between Laravel and Symfony?

We will below try to answer this question, in detail, and we will examine these areas:

  1. History – when and how did these two projects get started
  2. Product – what differences exist in the actual product

A Brief History of Laravel

A developer from Arkansas by the name of Taylor Otwell, back in 2011, created Laravel as an alternative to CodeIgniter and his first release was in June of 2011. He was developing in .net and also CodeIgniter and wanted something “better” than CodeIgniter so he made his own framework — only later did it become a fully qualified MVC framework. Over the course of the next 6 years, the project developed and grew and core components such as Blade, Eloquent ORM, Artisan, Bundles, LTS, Scheduler, Dusk and others and including a complete rewrite of the entire project in 2013 which incorporated the dependency manager Composer.

The current version is 5.4 and today Laravel calls itself “The PHP Framework For Web Artisans” and boasts a flourishing ecosystem — see below for more details. The name Laravel is a trademark of Taylor Otwell.

The Laravel framework itself is open-sourced software licensed under the MIT license.

A Brief History of Symfony

In 2004 a French developer by the name of Fabien Potencier created the Sensio Framework to help SensioLabs (his company) develop better websites faster. After he built his first website with it, the decision was made to release it as open source code under the name Symfony.

The first stable Symfony version, however, was released in January 2007. Version 2 was then released in July 2011 and was a rewrite of the entire framework from scratch.

The current version is 3.4 and is supported until 2020.

Symfony is officially sponsored by SensioLabs, a French software developer and service provider. Over 1700 people have contributed to the code base and over 1400 have contributed to the Symfony documentation, however. The name Symfony is a trademark of Fabien Potencier.

Symfony is released under the MIT license.

The Product

Laravel Overview

Laravel is an MVC framework for PHP. As they put it:

Laravel attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as authentication, routing, sessions, and caching. Laravel aims to make the development process a pleasing one for the developer without sacrificing application functionality.

The main forum for Laravel is the Laracasts Discuss site with over 65K threads and there is also the Laravel.io Forum with over 15K threads.

Symfony Overview

What is Symfony? As they put it:

Symfony is a set of reusable PHP components and a PHP framework for web projects.

and they also say:

Symfony is a set of PHP Components, a Web Application framework, a Philosophy, and a Community — all working together in harmony.

Symfony is not actually an MVC framework, however, like Laravel. This is one of the main reasons why comparing Symfony and Laravel is not an issue of which is better, rather which is best for any particular job.

The community around Symfony is a “passionate group of over 300,000 developers from more than 120 countries” and their original forum is now read-only and current forum activity is on StackOverflow with over 50K questions tagged as Symfony questions.

Symfony’s components are used in other very large and active projects, including Drupal, Joomla!, Magento, PrestaShop and of course Laravel.

Server Requirements for Laravel

Laravel requires:

  • PHP >= 5.6.4
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension
  • Composer

Server Requirements for Symfony

Symfony requires:

  • PHP >= 5.5.9
  • JSON Extension
  • ctype Extension
  • Your php.ini needs to have the date.timezone setting

Note that Laravel requires Composer and not all hosts can support that.

Installation

To install Laravel, the easiest way is via Composer, by first downloading Laravel:

composer global require "laravel/installer"

and then making a new Laravel installation with this Composer command:

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

Either of which will create a new Laravel install in a directory called blog. That’s the basic version. For more details, see our guide on How to Install Laravel on Shared Hosting

For Symfony, there are several ways to install. Some are global and some are meant only for development. We will show here one way, probably the simplest one, which is also via Composer:

composer create-project symfony/framework-standard-edition symfony

You must then answer a set of questions, but at the end, this creates a new install of Symfony in a directory called symfony.

For both Laravel and Symfony, an “install” means a set of directories which are not meant to be public. After installing the system, you must set your webroot to be blog/public/ for our Laravel example and symfony/web/ for our Symfony example.

Installation on Shared Hosting

The Composer-based install procedures listed above can work on shared hosting. The host must of course support Composer (you may have to install that yourself) and allow ssh access, and support the other requirements, but anyhow, with a good host, it works. 🙂

Under the Hood

All the above was the broad overview. The real deal, however, is what each package offers a developer, and how they work. The consensus among many developers is that Symfony is more low-level and more complicated, but also more stable and scalable and is thus best for large, involved projects. Laravel, on the other hand, is simpler and easier to use and to learn, development speed can be faster, and it’s great for simpler projects that don’t need to scale too much.

ORM

ORM means Object-Relational Mapping and it’s a system that lets you query and manipulate data without knowing what database system you are using, meaning MySQL, Postgres or SQL Server etc. The ORM provides its own high-level methods to access the data using code that is not unique to any one database system.

Laravel uses the Eloquent ORM and Symfony uses a third-party library called Doctrine.

Some developers claim that “Eloquent is the biggest strength of Laravel.” On the other hand, it uses the Active Record pattern, which is great for small projects, but has received criticism that it won’t work for larger projects. It’s important to note that you can also use Doctrine in Laravel instead of Eloquent via the Laravel Doctrine project, which they call:

A drop-in Doctrine ORM 2 implementation for Laravel 5+

So whereas Eloquent and Doctrine are quite different in many ways, you’re not stuck with Eloquent in Laravel. It’s also worth noting that Doctrine is used in other frameworks, as well, including CodeIgniter, Zend Framework and Yii.

Template Engine

Laravel uses Blade and Symfony uses Twig, developed by Fabien Potencier himself.

Laravel defines Blade as:

Blade is the simple, yet powerful templating engine provided with Laravel. Unlike other popular PHP templating engines, Blade does not restrict you from using plain PHP code in your views. In fact, all Blade views are compiled into plain PHP code and cached until they are modified, meaning Blade adds essentially zero overhead to your application.

Symfony claims:

Twig allows you to write concise, readable templates that are more friendly to web designers and, in several ways, more powerful than PHP templates.

That’s nice — they both like their own products. 🙂

But again here, you are not stuck. You can use Twig in Laravel via the TwigBridge project which they claim:

Allows you to use Twig seamlessly in Laravel 5.

The point here is that Blade and Twig are both good tools and each has it’s advantages — these quotes are not propaganda, they’re true. 🙂

The choice of Twig vs Blade for many developers boils down to two points. One is that you can use regular old PHP code in Blade. Some folks love that because it’s easy and others claim that it encourages developers to mix business logic with presentation, whereas Twig solves these problems. Sounds a lot like what I wrote initially that Laravel is easier and faster and great for small jobs, and Symfony is harder, but has what you need for more serious jobs.

The other issue is portability — Twig is used in other projects as well and knowing it is an advantage.

Internationalization

Both projects support internationalization / translations. Laravel has localization features and Symfony has a translator configuration option.

The main difference here seems to be that Laravel uses PHP and JSON files to store localization data and Symfony “supports lots of different translation formats: PHP, Qt, .po, .mo, JSON, CSV, INI, etc.” and supports more standardized formats such as XLIFF and gettext.

Routing

A route is a map from a URL to a controller, meaning when a visitor to my site visits the “/dogshow” page, a route in my code directs the system to get the content for that page from the correct controller.

The Laravel Routing system works in simple PHP and the Symfony Routing system lets you define routing in “annotation” format or in YAML, XML or PHP. That again may be the main real difference, as both have a set of advanced features which cover most use cases.

Scaffolding

Scaffolding means having a tool generate for you automatically the basic code to CRUD (create, read, update and delete) from your database, effectively treating the templates as a “scaffold” on which to build the application.

Laravel doesn’t natively have a scaffolding tool but several can be integrated into Laravel to accomplish this, such as Yeoman via the generator-laravel package, or InfyOm Laravel Generator or the Scaffold generator for Laravel 5.x.

Symfony comes with a bundle called SensioGeneratorBundle which “provides commands for scaffolding bundles, forms, controllers and even CRUD-based backends” but you can also use the generator-symfony package or the generator-sf package which uses Yeoman to “scaffold out a Symfony PHP app including Browsersync, various CSS preprocessors, jspm, webpack, browserify and Service Worker.”

Given all the various options for each, I certainly wouldn’t base a choice of framework on this issue.

Conclusions

There are other topics on this subject that we haven’t covered, such as Forms and Validation, Configuration, Artisan, the CLI tool for Laravel vs the The Console Component for Symfony, Lumen, the “stunningly fast micro-framework by Laravel” vs Silex a “PHP microframework built on the shoulders of Symfony and Pimple and also inspired by sinatra” and more topics as well.

As noted above, Symfony is generally for larger projects and Laravel for smaller ones, but at the end of the day of course you must use whatever you personally prefer or feel more comfortable with.

Hopefully our review can provide some insight as to the style of each tool and help you find what’s right for you.

About the Author
David Feldman is a Senior Technical Advisor for CiviHosting, your Laravel hosting and Symfony hosting experts. You can contact him via our Contact Us page.

How to Install Laravel on Shared Hosting

If your host has PHP and MySQL, then there is a good chance that they can run Laravel. There are a few other requirements, such as certain PHP extensions, but those are fairly common. The only real issue is Composer. If your host can’t (or won’t) run Composer, then forget about it. 🙁

But if they can, then most likely you can install Laravel. 🙂

If they have Composer already installed, then you’re all set. If not, then you must install yourself, but it’s not too hard. The directions on the Composer Download page are great and they work on many machines. For shared hosting, however, you probably will need to make some small changes.

If you’re using CiviHosting, we of course install Composer for you, but here is the code we use to do it and you can use those on other hosts. It’s from the GetComposer site:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

To get the command composer to work (instead of php ~/private/composer.phar) use this:

echo "alias composer='php71.cli ~/private/composer.phar'" >> ~/.bashrc

Now to install Laravel, we just use Composer, by first downloading Laravel:

composer global require "laravel/installer"

and then making a new Laravel installation with this command:

laravel new blog

But that only works if have you have an alias to the laravel executable, which you may not have. At CiviHosting, we don’t have (nor need) that. And even if you do, then there is the pesky sh: composer: command not found problem that doesn’t always have a solution. 🙁

Therefore the simplest way is to install Laravel via the Composer create-project command:

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

What this does is creates a new Laravel install in a subdirectory called blog. Yes, that’s kind of a silly example but that’s the one used online so we just copied it. In practice, you might want to use this:

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

which installs Laravel in the current directory.

What this does is give you a set of files and directories:

$ ls -l
total 192
drwxr-xr-x  6 civihosting civihosting   4096 May 11 08:42 app
-rwxr-xr-x  1 civihosting civihosting   1646 May 11 08:42 artisan
drwxr-xr-x  3 civihosting civihosting   4096 May 11 08:42 bootstrap
-rw-r--r--  1 civihosting civihosting   1300 May 11 08:42 composer.json
-rw-r--r--  1 civihosting civihosting 122432 Jul 18 11:52 composer.lock
drwxr-xr-x  2 civihosting civihosting   4096 May 11 08:42 config
drwxr-xr-x  5 civihosting civihosting   4096 May 11 08:42 database
-rw-r--r--  1 civihosting civihosting   1062 May 11 08:42 package.json
-rw-r--r--  1 civihosting civihosting   1055 May 11 08:42 phpunit.xml
drwxr-xr-x  4 civihosting civihosting   4096 May 11 08:42 public
-rw-r--r--  1 civihosting civihosting   3420 May 11 08:42 readme.md
drwxr-xr-x  5 civihosting civihosting   4096 May 11 08:42 resources
drwxr-xr-x  2 civihosting civihosting   4096 May 11 08:42 routes
-rw-r--r--  1 civihosting civihosting    563 May 11 08:42 server.php
drwxr-xr-x  5 civihosting civihosting   4096 May 11 08:42 storage
drwxr-xr-x  4 civihosting civihosting   4096 May 11 08:42 tests
drwxr-xr-x 31 civihosting civihosting   4096 Jul 18 11:52 vendor
-rw-r--r--  1 civihosting civihosting    555 May 11 08:42 webpack.mix.js

which is great, but if this is your document root (meaning the directory that is the “home” directory of your site) then you’ve got a problem, because the real document root of Laravel must be the public directory there. We we must change our document root to that directory.

Each host has a different way of allowing you to do that. On CiviHosting’s Control Panel, there is a tab called Document Roots. Click on that. Then find the URL you want to change and click the Change button.

On the next page you will see that you can either type in the directory you want, or you can click the little directory icon to get a popup window with a list of directories you can click on. Just click on the public directory and then click Select and then click Update.

That’s it. Your Laravel site is now ready. 🙂

Laravel Tutorials

Getting started with Laravel is not easy, even for a developer who already understands the MVC model and has worked with it. We have compiled here a brief list of resources with good tutorials to get you started learning Laravel, and some advanced ones also, to keep you going.

Laravel Specific Sites

Below is a set of sites focused only on Laravel, each of which has tutorials:

Laravel.com

The first place for many is Laravel’s own Documentation site at https://laravel.com/docs. Everything there is of course free and text-based.

Laracasts

Laracasts is a paid-for only resource, but it’s one of the biggest and most well known. It’s all videos.

Their tagline is:

It’s Kinda Like Netflix for Your Career!

Learn practical, modern web development, through expert screencasts. Most video tutorials are boring. These aren’t. Ready to binge?

Laravelista

Laravelista has a set of courses and tutorials in text format and video, including both free and paid-for resources. Their tagline is:

Learn Laravel by reading tutorials and completing courses. No more rewinding or pausing videos. Only the most detailed text instructions with open-source applications.

Laravel News

The Laravel News site has a Laravel Tutorials page with a nice set of resources.

Learning Laravel

The Learning Laravel site has literally hundreds of tutorials.

Laravel Best Practices

The Laravel Best Practices is a one-page (but it’s a LONG page) introduction to Laravel with lots of links to other resources.

Laravel Tricks

The Laravel Tricks site has a variety of tutorials, from a wide set of authors, each with his own style.

Other Sites

Below is a set of more sites which are not Laravel-only sites, but they have some useful Laravel tutorials available:

YouTube

On YouTube there are a few channels dedicated to Laravel, but none with a large set of up to date tutorials, that we found. Your best bet is to run a search for Laravel Tutorial there and you will find there a good set of results.

Kode Blog

Kode Blog is an educational website that provides free programming tutorials, articles and complete source code. They have Laravel tutorials on their Laravel 5 Tutorial page.

Hackr.io

Hackr.io is a site for programmers to find and share the best online programming courses & tutorials. They have Laravel tutorials on their Laravel Tutorials and Courses page.

Toptal

Toptal has a tutorial: Laravel API Tutorial: How to Build and Test a RESTful API with good information.

Belitsoft

Belitsoft is an offshore web dev agency, and they have a nice page called Getting Started With Laravel for Beginners with links to a lot of specific tutorials on all kinds of Laravel subjects.

In Conclusion

If you have any comments, including suggestions for additions, just let us know.

About the Author
David Feldman is a Senior Technical Advisor for CiviHosting, your Laravel hosting experts. You can contact him via our Contact Us page.