How to Install Symfony Framework in Linux

The Symfony is a free, full-stack PHP framework used for building web applications. It’s well-known for its self-contained components that seamlessly integrate into any PHP project. Symfony also supports multiple languages, including JavaScript and Node.js.

Many open-source developers rely on Symfony for creating high-performance, complex web applications. Additionally, Symfony offers a Command Line Interface (CLI) tool that assists developers in various tasks such as database management, code generation, and executing commands.

Symfony Framework Features

Symfony offers numerous interesting features, which include:

  • Full functionality database classes
  • MVC (Model View Controller) architectural pattern
  • Code reusability
  • Modifiable URI routing
  • Seamless integration with third-party services
  • Error logging

In this article, we will demonstrate the steps to install and set up the Symfony Framework on RHEL-based and Debian-based distributions.

How to Install Symfony Framework in Linux

Before installing the Symfony framework on our system, we need a user with sudo or root privileges to install PHP and the required PHP extensions as shown.

Install PHP in Linux

---------------- On RHEL-based Systems ---------------- 
sudo dnf install php-ctype php-iconv php-pcre php-session php-simplexml php-tokenizer

---------------- On Debian-based Systems ----------------
sudo apt install php-ctype php-iconv php-pcre php-session php-simplexml php-tokenizer

Next, verify that PHP and the extensions are installed correctly.

php -v

PHP 8.2.16 (cli) (built: Feb 13 2024 15:22:59) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.16, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.16, Copyright (c), by Zend Technologies

The above command should display the PHP version installed on your system, along with information about the installed extensions.

Install Composer in Linux

Installing Composer for Symfony is essential as Symfony relies on Composer as its dependency manager to simplifies the management of PHP libraries and dependencies needed by Symfony and its projects.

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');"

Install Symfony Framework

Run the following wget or curl command to download and install Symfony using its automatic installation script.

wget https://get.symfony.com/cli/installer -O - | bash
Or
curl -sS https://get.symfony.com/cli/installer | bash
Install Symfony Framework in Linux
Install Symfony Framework in Linux

Next, execute the following commands to add the Symfony path variable and apply the changes.

$ export PATH="$HOME/.symfony5/bin:$PATH"
$ source ~/.bashrc

Finally, verify the system meets the requirements for running Symfony applications by running the following command, which will check various aspects of the system, such as the installed PHP version, enabled PHP extensions, and other system configurations necessary for Symfony to function properly.

symfony check:req
Check Symfony Status
Check Symfony Status

Now that our Symfony framework is installed and ready for running a Symfony project, we must set it up to run a project.

How to Create Symfony Web Applications in Linux

It is considered a good practice to configure Git before setting up a new development environment or beginning work on a new project.

We can use the following Git config commands to configure our Git:

git config --global user.email "email_address"
git config --global user.name "full_name"

Now, we’ll execute the following command to create a new Symfony web application project.

symfony new demo --webapp
Create Symfony Project
Create Symfony Project

Once our project is ready, we’ll navigate inside the project directory (“demo”) and start the Symfony server.

cd demo
symfony server:start
Start Symfony Server
Start Symfony Server

We can notice that our web server is listening at http://127.0.0.1:8000, indicating that we’ve successfully created a new Symfony project.

Access Symfony Web Portal
Access Symfony Web Portal

Thus, we can observe the Symfony Welcome page successfully. Furthermore, from the above output, we also notice the address of our project, indicating that we can view any webpage located in that project directory.

That concludes the process. You can now begin creating your first Symfony page in this project directory using its official documentation.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

11 Comments

Leave a Reply
  1. This article has been updated to incorporate Symfony instead of Zend Framework, following the deprecation of Zend. Symfony is recommended as a modern alternative, ensuring continued support and enhanced features for web development projects.

    Reply
  2. I have already created project with zend using netbeans with latest component and new version of php 7.
    but after creating when I am running my software it is giving me some error like “The requested URL /lca/public was not found on this server.”
    Please help me out

    Reply
    • @Supriya,

      On which Linux distribution you are getting such error, if it’s CentOS, make sure to disable SELinux mode. If it’s already disabled, make sure to check logs for the solution..

      Reply
  3. Doing above steps have worked fine, but unfortunately they have changed my PHP version from 5.3 to 5.4 without any consent ! :(

    I wish to go with php 5.3 version !
    HOw can i DO the same ?

    SOme-one please reply .

    Reply
    • It’s due to latest Zend Framework depends on newest PHP version, that’s the reason it automatically upgraded your PHP version. Going with latest PHP doesn’t harm your any application.

      Reply
  4. Hi, thanks for the tutorial ..
    I have a problem with the next step: # zf show version

    I do not see the version.

    ***************************** ZF ERROR ******************* *************
    In order to run the zf command, you need to Ensure That Zend Framework
    is inside your include_path. There are a variety of ways That you can
    Ensure That this zf command line tool knows where the Zend Framework
    library is on your system, but not all of them can be Described here.

    ….

    I use Centos 6.3. The installation has been completed successfully.

    Any ideas?

    Thanks for sharing.

    Reply
  5. Perfect instructions. I have never used the remi and epel packages. Can you explain what’s so unique about them that they helped with the installation.

    I tried the instructions on the zend site, but I must have missed a few packages as it couldn’t figure out where the zf.php file was it.

    I am still missing the phpunit package, but I think I can handle this on my own.

    Thanks for PERFECT instructions!

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.