Laravel vs. Symfony: A Side-by-Side Comparison - Part 2

Laravel vs. Symfony: A Side-by-Side Comparison - Part 2

Introduction

In our last post, we began comparing the PHP frameworks Laravel and Symfony. We went over an overview of each framework, and also what particular advantages each one has. In this post, we’ll continue by discussing the following:

Finally, we’ll go over which framework is right for your particular use case.

Popularity 

With 79% of websites using PHP frameworks as part of their design, it is hard to ignore the popularity of this language. Within that statistic, we need to know how many websites are developed using Laravel or Symphony. It is known that Laravel is more popular, as provided by the graph below, which is taken from Google Trends. It shows that Laravel has been on top, comparing it with other PHP, with Symfony following up, but not as close. 

Secondly, we can also see a comparison that is made here between websites and industries on how many websites are created with Laravel and Symfony. It is clear that apart from the Health industry, Laravel is taking the lead. This is especially true for Business & Industry, Arts, and Entertainment, where Laravel has taken a significant lead in almost all industries. So Laravel has the upper hand when it comes to popularity. 

Here are more stats to support their popularity through some Github stats:

Laravel

Symfony

Github Stars

66.4k

25.7k

Forks

21.4k

8.3k

Commits

6521

56,411

Contributors

570

2414

You can see through these statistics that currently, Laravel is more popular than Symfony in the PHP framework arena. 

Performance

The performance of a framework is judged significantly by how fast the response time is for when a request is made, and the output is given. According to the table, the testing shows that Laravel takes less time than Symfony to respond, with a significantly lesser time difference. The speed itself shows how fast Laravel performs. You can see apart from Nginx testing with 10 requests for a single user, Laravel responded in less than half the time it took for Symfony. 

Installation Process 

We can talk about the two frameworks as much as possible. But how do you install the frameworks in order to start working on it?

Laravel 

Laravel has two methods of installation. One is through Docker Desktop, and the other is through Composer. Whichever you choose, you want to make sure that you install those first on your Mac, Windows, or Linux computer for Laravel Sail. The following information will be strictly related to the installation of Laravel 8. 

Laravel Sail is a lightweight command-line interface that gives a starting point for building an application. This application will use PHP, MySQL, and Redis and does not necessarily need previous experience with Docker. 

If you have Docker installed on your computer, here are the first steps to installing Laravel:

When you are on the Docker terminal, run the following command to create a new directory:

curl -s "https://laravel.build/example-app" | bash

You can switch example-app for any name of the app you would like. In doing so, a new project will be started. On Laravel Sail, you can interact with the Docker configuration by using the following command:

cd example-app

./vendor/bin/sail up

You will then be able to access it on the following URL: http://localhost:8000/

This will be the same process for using Docker, on Mac, Windows, and Linux. However, for Windows, keep in mind that you will need to also make sure that Windows Subsystem for Linux 2, and WSL2 is also installed and enabled. This gives the ability to run Linux binary executables on Windows 10 natively. Once installed, the Docker Desktop needs to be configured to access the WSL2 backend. 

You can also install Laravel through Composer. A Laravel project can be created directly on it. You can create the application as follows:

composer create-project laravel/laravel example-app

cd example-app

php artisan serve

When you do this, make sure to put Composer’s system-wide vendor bin directory in the $PATH so the laravel executable can be easily located by the system. Keep in mind, that depending on the system of your computer, the directory will be different. Here is the list to support you:

You can find more information on Laravel’s Installation process on their website

Symfony

Before we go into installing Symfony, we will have to keep in mind some requirements. There are two things that need to be done before working on Symfony. 

  1. You have to install PHP 7.2.5 or higher. The latest one is PHP 8.0.9, and a beta version of 8.1.0 is also available as a preview right now. You should also have had the following PHP extensions enabled: 
    a. Ctype, iconv, JSON, PCRE, SimpleXML, Session, and Tokenizer
  2. You’re going to have  to install Composer in order to install PHP packages on your computer.
  3. This is optional; however, you can also install Symfony CLI. It creates  the binary symfony that can provide you with all the tools for the development of a Symfony application. It also checks if your computer has  all the requirements  to run the development process.  

In order to create a new Symfony application, open your console terminal on Symfony CLI and use the following command:

> symfony new my_project_name --full

Note: Use this command if you want to build a web application that is traditional. 

Or alternatively, use the following command if you want to build a microservice, console application, or API:

> symphony new my_project_name

If you are on Composer, here are the two ways of starting a Symfony application:

> composer create-project symfony/website-skeleton my_project_name

Note: the above command is to be used for creating a web application that would be traditional. However, if you want to create a microservice, console application or even API, then you can use the following. 

> composer create-project symfony/skeleton my_project_name 

For both options available, you can customize the name my_project_name to your liking. If you would like to get more detailed information on how to install Symfony, you can always check out their documentation on installation and setting up the framework here.

Templates

When using PHP, you’ll find a lot of templates to support you. Depending on whether you use Laravel or Symfony, you’ll notice that they use their own template engine. This provides you with solutions to your web applications according to your needs. 

Laravel

Laravel’s primary engine is Blade. By using Blade, you can easily insert code directly into the template file. It is customizable and allows you to write simple code. Here is an example of a Blade file:

<!DOCTYPE html>

<html>

    <head>

        <title>Blade example file</title>

    </head>

    <body>

        <h1>{{ $page_title }}</h1>


        {% if $user->isLoggedIn() %}

            <p>Hello {{ $user->name }}!</p>

        {% endif %}


        <ul id="navigation">

        @foreach ($navigation as $item)

            <li><a href="{{ $item->href }}">{{ $item->caption }}</a></li>

        @endforeach

        </ul>

    </body>

</html>

Symfony 

Symfony’s primary engine is Twig. The files generated for Symfony will have the .twig extension. On Twig, it uses simple written code to its advantage. Here is an example of a Twig file look like:

<!DOCTYPE html>

<html>

    <head>

        <title>Twig example file</title>

    </head>

    <body>

        <h1>{{ page_title }}</h1>


        {% if user.isLoggedIn %}

            <p>Hello {{ user.name }}!</p>

        {% endif %}


        <ul id="navigation">

        {% for item in navigation %}

            <li><a href="{{ item.href }}">{{ item.caption }}</a></li>

        {% endfor %}

        </ul>


    </body>

</html>


Documentation 

Laravel and Symfony have extensive documentation not just on their website but also on Github. Both frameworks allow you to search for queries that you need on their documentation, so you do not have to go through every page to look for what you need. Laravel’s documentation on their website is a handbook on how to use and find support from within the community. Its minimal and clear website is inviting, and you can easily find what you need on it. 

Symfony also has an extensive and will provide information on bundles, service containers, and components and a sprinkle of other sets of features as well. However, it is not as extensive as Laravel’s documentation. 

Laravel’s original documentation can be found here: Laravel

Symfony’s original documentation can be found here: Symfony

Their Github is also a good supporting place for you if you need help from the community, Laravel - Symfony

Ease of Learning

Laravel is applauded across the board for being easy to learn. This can be attributed to its philosophy of making things easy. With the simplification of tasks, writing and learning the code can be easy. On the other hand, Symfony is slow to learn in the beginning, but it becomes easy when you are familiar with other PHP frameworks as well. 

Community and Support 

You can find a lot of support for Laravel and Symfony. Apart from their own website, here are other places that you can find support for when you are stuck with a conundrum:

Laravel

Symfony

Website

https://laravel.com/ 

https://symfony.com/ 

Blog

https://blog.laravel.com/ 

https://symfony.com/blog/category/community 

Github

https://github.com/laravel 

https://github.com/symfony 

Twitter

@laravelphp

133.8k followers

@symfony 

39.3k followers

Facebook

https://www.facebook.com/LaravelCommunity/

54 k followers

https://www.facebook.com/SymfonyFramework 

12k followers

Youtube

https://www.youtube.com/laravelphp
7.52k subscribers

Videos mostly focus on tutorials

https://www.youtube.com/user/SensioLabs 

8.89k subscribers

Videos mostly focusing on tutorials and events

Reddit

https://www.reddit.com/r/laravel/

63.1k members

https://www.reddit.com/r/symfony/ 

7.3k members

Discord

Laravel

20660 members, with more than 1000 online at a given time

Both accounts are verified on many platforms, so you know you are getting the right support. With more than thousands of community members available at any given time and very strong documentation and tutorials available, both Laravel and Symfony communities can support you when you have a question. Choosing the right framework to use requires you to be able to problem-solve, and with a large community, problem-solving does not become a one-person gig, and it makes things easy for you when you are working on your project. 

Which Framework Wins? 

Laravel PHP framework remains to be the product of Symfony. However, it's the most preferred because of its ability to deliver fast deployment and prototyping. 

However, Laravel can jeopardize if it requires to range higher than you had initially anticipated. This issue will happen because of Laravel's shortcuts, such as the diminished distinction between the framework's design and data. 

On the other hand, Symfony's design integrity offers it the ability to deliver a more significant initial time and money investment with a stable task implementation that can scale. Besides this, several biggest names use this PHP framework as their core framework. 

Moreover, Symfony features less conceptual integrity than its counterpart, Laravel. It makes this possible because of its mission, divided between a cohesive framework and module provision. 

In general, Symfony and Laravel are the perfect options for several website development projects. Laravel is the most preferred because of its rapid speed, performance, and development. 

On the other hand, Symfony is the most preferred because it can help you create large and complex website applications. However, take your time to ensure you choose one that suits all your website project needs.