How to Install Symfony Framework in Linux (for Beginners)

Linux TLDR
Last Updated:
Reading time: 4 minutes

Symfony Framework is a free and open-source PHP framework that includes a collection of reusable PHP components. It’s a vast library of PHP components that can help to speed up the development process, ease maintenance, eliminate repetitive coding, and ensure top-notch security.

Despite being a PHP framework, it surprisingly extends support for JavaScript and Node.js. If you have experience in PHP, you might have heard of Laravel (another PHP framework), but comparatively, Symfony is better for complex web apps as it provides performance-rich features, a wider range of components, flexibility on big databases, and more.

Platforms like Drupal and Magento recommend using the Symfony Framework over others, and Symfony certifications are available to pursue if you fall in love with it. With enough experience in Symfony, you can work for top companies that use it in their tech stacks, such as Accenture, Trivago, Typeform, Oxylabs, and many more.

Features of the Symfony Framework

The Symfony framework is packed with features, with the top ones being:

  • It is free, open-source, has friendly documentation, and has a huge community of developers.
  • It allows you to create complex web applications, APIs, microservices, or web services.
  • It offers a huge PHP component that enables code reusability.
  • Operates on the MVC (Model View Controller) model.
  • Modifiable URI routing is provided.
  • Flexibility in handling large databases.
  • Easily integrate with third-party services.

In this kickstart guide, I’ll take you through the setup to install and configure the Symfony Framework on popular Linux distributions such as Debian, Ubuntu, Red Hat, or Fedora.

How to Install Symfony Framework in Linux

Symfony setup involves installing the Symfony CLI tool, which helps you build, run, and manage your Symfony applications directly from your terminal, as well as PHP Composer, which is used as a dependency manager.

Before installing this tool, you need to also install PHP on your Linux system. Fear not; I’ll guide you through the installation steps in a neat way for Debian-based distributions like Ubuntu and Red Hat-based distributions like Fedora, allowing you to choose the appropriate one for your Linux distribution. Let’s begin now…

1. Update System Packages

Prior to installation, make sure to update your package database and any pending updates on your system. Avoiding it won’t impact Symfony installation; however, it’s considered a good practice to proceed with it.

# On Debian, Ubuntu, Kali Linux, Linux Mint, Zorin OS, Pop!_OS, etc.
$ sudo apt update && sudo apt upgrade

# On Red Hat, Fedora, CentOS, Rocky Linux, AlmaLinux, etc.
$ sudo dnf upgrade

Output:

updating system packages

2. Install PHP in Linux

For installing PHP and the necessary PHP extension for Symfony on Linux, you can use one of the following commands according to your Linux distribution:

# On Debian, Ubuntu, Kali Linux, Linux Mint, Zorin OS, Pop!_OS, etc.
$ sudo apt install php php-cli php-common php-xml libpcre3 git zip unzip

# On Red Hat, Fedora, CentOS, Rocky Linux, AlmaLinux, etc.
$ sudo dnf install php8.2 php8.2-cli php8.2-common php8.2-xml libpcre3 git zip unzip

Output:

installing required php and php extensions for symfony

To verify the installed PHP version, run.

$ php -v

Output:

checking the PHP version

3. Install Composer in Linux

Now that PHP is installed on your system, you need to install Composer, which acts as a dependency manager for Symfony and allows easy and quick installation of various Symfony components in your project.

To begin, run the following commands, which will download the Composer installer script, verify its integrity, install Composer, and remove the installer script. These commands are valid for both Debian and Red Hat-based distributions like Ubuntu and Fedora.

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

Output:;

installing composer on linux

4. Install Symfony CLI in Linux

Now is the moment to install the Symfony CLI tool, which is free, open-source, and allows you to build, run, and manage your Symfony applications directly from your terminal. It’s cross-platform and functions seamlessly on Linux, Windows, and macOS.

To install it on your Linux system, you can run its automatic installation script using either the wget or curl commands:

$ wget https://get.symfony.com/cli/installer -O - | bash

# OR

$ curl -sS https://get.symfony.com/cli/installer | bash

Output:

installing symfony cli

The Symfony CLI tool is installed, but currently its installation directory is not included in your β€œ$PATH” variable, causing a β€œCommand not found” error upon executing the β€œsymfony” command. To ensure smooth functionality, add the following line to your shell configuration file (β€œ~/.bashrc” for Bash) at the end.

export PATH="$HOME/.symfony5/bin:$PATH"

When you’re done with that, make sure to refresh the change by running:

$ source ~/.bashrc

Output:

adding symfony installation directory to system path

5. Check Symfony Status in Linux

Now that almost everything is complete, the only remaining step is to ensure the system meets the requirements for running the Symfony framework, and then you’re all set to start developing your first application.

$ symfony check:req

Output:

checking symfony status

Here, we got the system-ready message with a green signal (oops, a green box).

How to Create Symfony Web Apps in Linux

It is considered a good practice to configure Git on your system before creating a new Symfony web application. To do so, you can use the following commands to set up your Git email address and name:

$ git config --global user.email "[email protected]"
$ git config --global user.name "your_good_name"

Output:

configuring Git on linux

To create a new Symfony web application named β€œmyproj” you can run the following command:

$ symfony new --webapp myproj

Wait for a few seconds to let the project directory get ready.

creating symfony web app

Once the process is complete, you can enter the project directory (in our case, β€œmyprojβ€œ) and start the Symfony server.

$ cd myproj/
$ symfony server:start

Output:

starting symfony web server

Once the Symfony server is started, you can open your favorite browser (either Chrome or Firefox) and visit β€œhttp://127.0.0.1:8000β€œ, where the Symfony server is listening.

accessing the symfony web portal

From here, you can start your journey with the Symfony framework.

Final Word

Symfony is a fantastic PHP framework that you should spend some time learning, and you’ll find how much it simplifies your development experience. If you are a beginner, you may discover a variety of learning sources on the internet, but trust me, nothing beats its official documentation.

If you have any questions or queries related to the topic, then do let me know in the comment section.

Till then, peace!

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.