In this short tutorial, we will discuss how to install Symfony PHP Framework on Ubuntu 22.04 operating system.
Symfony is a high-performance PHP framework that has gained immense popularity in the world of web development due to its flexibility, scalability, and rich set of features. Launched in 2005 by SensioLabs, Symfony has evolved into a mature and powerful framework that empowers developers to create web applications and websites efficiently and securely. In this article, we will explore the key features and benefits of Symfony, and why it is a top choice for developers around the world.
Key features and benefits of Symfony,are :
- Modularity and Flexibility
One of Symfony’s standout features is its modularity. Symfony is built on a set of standalone and reusable components. This modular architecture allows developers to choose and use only the components they need for their project, making it highly flexible and efficient. Whether you’re building a simple blog or a complex enterprise-level application, Symfony can adapt to your needs.
- Strong Community and Ecosystem
Symfony boasts a thriving and active community. This means a wealth of documentation, tutorials, and third-party bundles are readily available. These bundles provide pre-built functionality for common tasks, reducing development time and effort. Symfony Flex, the official package manager for Symfony, simplifies the installation and management of these bundles.
- Performance and Caching
Symfony is known for its impressive performance. It includes a variety of built-in caching mechanisms, such as HTTP caching and opcode caching, which can significantly enhance the speed of web applications. The ability to cache components and templates ensures that pages load quickly, providing an optimal user experience.
- Security Features
Symfony prioritizes security. It includes built-in features like CSRF protection, XSS protection, and robust authentication and authorization mechanisms. Security is a top concern for web applications, and Symfony’s commitment to security best practices ensures that developers can build applications with confidence.
- Dependency Injection
Symfony utilizes a powerful dependency injection container. This feature simplifies the management and injection of dependencies, making the code more maintainable, testable, and scalable. Dependency injection allows for decoupled and reusable code, which is crucial for modern software development.
- Built-in Testing
Symfony encourages the use of testing with PHPUnit. It provides tools for creating unit tests, functional tests, and acceptance tests. Testing is an integral part of the development process, and Symfony’s testing tools make it easier for developers to ensure the reliability and stability of their applications.
- API Development
Symfony is well-suited for developing RESTful APIs. Its routing and serialization components make it straightforward to expose your application’s functionality as web services. This is vital in today’s interconnected digital landscape, where APIs play a crucial role in data exchange between applications.
- Doctrine ORM Integration
Symfony is often used in conjunction with the Doctrine Object-Relational Mapping (ORM) system. This integration provides a robust and efficient way to interact with databases. Developers can work with databases in an object-oriented manner, simplifying database operations and reducing the need for writing raw SQL queries.
- Scalability and Performance Monitoring
Symfony applications can be scaled horizontally, allowing them to handle increased traffic and load. Monitoring tools and profilers help developers identify and optimize performance bottlenecks, ensuring applications perform efficiently even under heavy use.
- Long-Term Support (LTS)
Symfony releases Long-Term Support versions that receive extended support, including security updates. This provides stability for projects that require long-term maintenance and ensures that your application remains secure and up-to-date.
How To Installing Symfony PHP Framework on Ubuntu 22.04
To install Symfony PHP framework on Ubuntu 22.04 we have to do several tasks as mention below :
- Ensure the system packages are up-to-date
- Install PHP Verify if the system has PHP installed
- Installing Symfony Framework on Ubuntu 22.04
- Creating Symfony Project
- Accessing Symfony Web UI
Step 1. Ensure the system packages are up-to-date
To install new packages in the system, we need to ensure if our system is up-to-date, for this purpose we will submit the following command line :
$ sudo apt update $ sudo apt ugrade
Step 2. Install PHP Verify if the system has PHP installed
Before installing Symfony framework, we need to install required packages. For this purpose we will submit the following command line:
$ sudo apt install php php-json php-ctype php-curl php-mbstring php-xml php-zip php-tokenizer php-tokenizer libpcre3
ramansah@bckinfo:~$ sudo apt install php php-json php-ctype php-curl php-mbstring php-xml php-zip php-tokenizer php-tokenizer libpcre3 Reading package lists... Done Building dependency tree... Done Reading state information... Done Note, selecting 'php8.1-common' instead of 'php-ctype' libpcre3 is already the newest version (2:8.39-13ubuntu0.22.04.1). libpcre3 set to manually installed. The following additional packages will be installed: apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php8.1 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libonig5 libzip4 php-common php8.1 php8.1-cli php8.1-curl php8.1-mbstring php8.1-opcache php8.1-readline php8.1-xml php8.1-zip Suggested packages: apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser php-pear The following NEW packages will be installed: apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php8.1 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libonig5 libzip4 php php-common php-curl php-json php-mbstring
... Setting up php8.1 (8.1.2-1ubuntu2.14) ... Setting up php (2:8.1+92ubuntu1) ... Processing triggers for ufw (0.36.1-4build1) ... Processing triggers for man-db (2.10.2-1) ... Processing triggers for libc-bin (2.35-0ubuntu3.4) ... Processing triggers for php8.1-cli (8.1.2-1ubuntu2.14) ... Processing triggers for libapache2-mod-php8.1 (8.1.2-1ubuntu2.14) ...
Step 3. Installing Symfony Framework on Ubuntu 22.04
At this section we will install Symfony Framework by downloading the soure and install it. We will use the following command lines:
$ curl -sS https://get.symfony.com/cli/installer | bash
ramansah@bckinfo:~$ curl -sS https://get.symfony.com/cli/installer | bash Symfony CLI installer Environment check [*] cURL is installed [*] Tar is installed [*] Git is installed [*] Your architecture (amd64) is supported Download Downloading https://github.com/symfony-cli/symfony-cli/releases/latest/download/symfony-cli_linux_amd64.tar.gz... % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- 0:00:05 --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- 0:00:05 --:--:-- 0 100 5253k 100 5253k 0 0 84803 0 0:01:03 0:01:03 --:--:-- 975k Uncompress binary... Installing the binary into your home directory... The binary was saved to: /home/ramansah/.symfony5/bin/symfony The Symfony CLI was installed successfully! Use it as a local file: /home/ramansah/.symfony5/bin/symfony Or add the following line to your shell configuration file: export PATH="$HOME/.symfony5/bin:$PATH" Or install it globally on your system: mv /home/ramansah/.symfony5/bin/symfony /usr/local/bin/symfony Then start a new shell and run 'symfony'
To pinpoint the exact location fo the Symfony on our system, we will execute following command line :
ramansah@bckinfo:~$ export PATH="$HOME/.symfony5/bin:$PATH" ramansah@bckinfo:~$ source ~/.bashrc
Step 4: Creating Symfony Project
In this short tutorial we also will create a new Symfony project to test if the installation was good or not. For this purpose we will submit the following command line :
$ symfony new project_test01 --full
ramansah@bckinfo:~$ symfony new project_test01 --full * Creating a new Symfony project with Composer [WARNING] The --full flag is deprecated, use --webapp instead. (running /usr/local/bin/composer create-project symfony/website-skeleton /home/ramansah/project_test01 --no-interaction) * Setting up the project under Git version control (running git init /home/ramansah/project_test01) [OK] Your project is now ready in /home/ramansah/project_test01
By running above command line, we will create a new Symfony project will all the recommended packages and configurations. Then we will runt the web server by submitting following command line :
$ cd project_test01 $ symfony server:start
Step 5: Accessing Symfony Web UI
At this section we will access Symfony Web UI which is located at URL : http://127.0.0.1:8001 as shown below.
Symfony has established itself as a leading PHP framework, offering a comprehensive set of tools and features for modern web development. Its modularity, robust security, and strong community support make it an excellent choice for projects of all sizes. Whether you are developing a small website, a complex web application, or a RESTful API, Symfony’s flexibility and reliability make it a solid foundation for your PHP development needs. If you’re a PHP developer, Symfony is certainly a framework worth exploring and integrating into your development toolkit.