Install Symfony PHP Framework on AlmaLinux 8: Easy Steps
In this guide on the Orcacore website, we will show you how to Install Symfony PHP Framework on AlmaLinux 8. Symfony is an open-source PHP web application framework designed for developers who need a simple and elegant toolkit to create full-featured web applications.
Symfony boasts a vast array of functionalities and benefits from a vibrant, active community. It offers flexible configuration options using YAML, XML, or annotations. Symfony seamlessly integrates with independent libraries and PHP Unit, drawing inspiration from web application frameworks like Ruby on Rails, Django, and Spring. Notably, Symfony components are widely utilized in numerous open-source projects, including Composer, Drupal, and phpBB.
Before diving into the installation process, let’s outline the necessary prerequisites for setting up PHP Symfony on AlmaLinux 8.
Requirements for PHP Symfony Framework
Firstly, you’ll need to log into your AlmaLinux 8 server as a non-root user with sudo privileges. If you haven’t already configured this, refer to our guide on Initial Server Setup with AlmaLinux 8.
Secondly, ensure that you have PHP version 8.1 or higher installed on your server. Follow our guide on Installing PHP 8.2 on AlmaLinux 8 for detailed instructions.
Finally, you’ll require PHP Composer, the dependency manager for PHP, to be installed on your system. You can find instructions on how to do this in our guide on Installing PHP Composer on AlmaLinux 8.
Once you have met these requirements, you can proceed with the following steps. Let’s Install Symfony PHP Framework on AlmaLinux 8.
Set up PHP Symfony Framework on AlmaLinux 8
This guide will walk you through downloading and utilizing the Symfony installer.
The Symfony Installer is the primary tool for creating new web applications based on the Symfony framework. Let’s begin by configuring the Symfony installer.
First, create the necessary directory using the following command:
sudo mkdir -p /usr/local/bin
Next, use the curl command to download the Symfony installer script to your AlmaLinux 8 system:
sudo curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony
After downloading the installer, set the correct permissions for the file:
sudo chmod a+x /usr/local/bin/symfony
Create Symfony Apps with Composer
Now that the Symfony installer is set up, you can create Symfony applications using Composer on AlmaLinux 8. Assuming you have already installed Composer, let’s proceed.
The following command will create a new project using Composer:
$ composer create-project symfony/framework-standard-edition <mark>app_name</mark>
Note: If you need to specify a particular Symfony version, you can include it in the command above. For this example, we will create a project named HelloWorld.
$ composer create-project symfony/framework-standard-edition <mark>HelloWorld</mark>
After the project is created, navigate to the project directory using the command below:
cd HelloWorld
Finally, run your application using the following command:
php bin/console server:run
The output will be similar to this:

Once the server is running, open your web browser and access the URL http://localhost:8000/
. You should see the Symfony welcome screen.
For more detailed information and advanced configurations, consult the official Symfony Documentation page.
Conclusion
Congratulations! You have successfully learned how to Install Symfony PHP Framework on AlmaLinux 8. Symfony on AlmaLinux 8 is a powerful PHP framework ideal for building scalable, high-performance web applications and APIs. It provides reusable components, tools, and best practices for modern PHP development. You are now ready to begin developing your next great application.
Hope you enjoyed this guide. You may also like to read the following articles:
Hide Warning and Error Messages in PHP
Install Symfony PHP on Debian 12
Install LEMP Stack Nginx MariaDB PHP on Debian 12
Install PHP Composer on Ubuntu 22.04
FAQs
What are Symfony Components?
Symfony provides reusable PHP libraries like Routing, Security, and HTTP Foundation, which can be used independently in any PHP project.
What is the difference between Laravel and Symfony?
Symfony is preferred for large, complex applications with high customizability, while Laravel is more beginner-friendly with built-in features for rapid development.
Does Symfony support databases like MySQL and PostgreSQL?
Yes! Symfony works with MySQL, PostgreSQL, SQLite, and more using Doctrine ORM.
Alternative Installation Methods
While the Symfony Installer and Composer provide a streamlined approach, alternative methods exist for setting up the Symfony PHP Framework on AlmaLinux 8. Two such methods involve using Docker and manual installation.
1. Installing Symfony with Docker
Docker provides a containerized environment, ensuring consistency across different operating systems. This approach eliminates potential dependency conflicts and simplifies deployment.
Explanation:
Docker allows you to create a self-contained environment for your application. This includes the operating system, PHP, web server, and any other dependencies. By using a pre-built or custom Docker image, you can guarantee that your Symfony application will run identically regardless of the underlying infrastructure. This is particularly beneficial for development teams working on different operating systems or deploying to various cloud environments.
Steps:
-
Install Docker and Docker Compose: If you haven’t already, install Docker and Docker Compose on your AlmaLinux 8 system. Docker’s official documentation provides comprehensive instructions.
-
Create a
docker-compose.yml
file: This file defines the services that make up your application. For a Symfony application, you’ll typically need a service for PHP, a web server (like Nginx or Apache), and optionally a database service.version: "3.8" services: php: build: context: . dockerfile: Dockerfile volumes: - ./src:/var/www/html/src ports: - "8000:8000" working_dir: /var/www/html nginx: image: nginx:alpine ports: - "80:80" volumes: - ./nginx/default.conf:/etc/nginx/conf.d/default.conf - ./src:/var/www/html/src depends_on: - php
-
Create a
Dockerfile
: This file contains the instructions for building the PHP service’s image.FROM php:8.2-fpm-alpine RUN apk update && apk add --no-cache zip unzip git RUN docker-php-ext-install pdo pdo_mysql WORKDIR /var/www/html COPY composer.json composer.lock ./ RUN composer install --no-interaction --optimize-autoloader COPY . . CMD php -S 0.0.0.0:8000 -t public
-
Create a
composer.json
file: This file lists the PHP dependencies for your project, including Symfony. If you don’t already have one, create a new file and add the following:{ "require": { "symfony/framework-bundle": "^6.0", "symfony/console": "^6.0", "symfony/twig-bundle": "^6.0" }, "autoload": { "psr-4": { "App\": "src/" } } }
-
Create a
src
directory: This directory will hold the actual PHP code of your Symfony application. -
Run
docker-compose up -d
: This command builds and starts the Docker containers in detached mode. -
Access your application: Open your web browser and navigate to
http://localhost
.
This method ensures that your Symfony application runs in a consistent and isolated environment, simplifying deployment and management.
2. Manual Installation of Symfony
While less common, manual installation provides a deeper understanding of the framework’s underlying structure and dependencies.
Explanation:
Manually installing Symfony involves downloading the framework files directly, configuring the web server, and managing dependencies yourself. This approach requires a strong understanding of PHP, web server configuration, and dependency management. It is generally recommended for advanced users who need fine-grained control over the installation process.
Steps:
-
Download Symfony: Download the Symfony framework as a ZIP archive from the official Symfony website or GitHub repository. Choose the desired version (e.g., the Long Term Support (LTS) version).
-
Extract the Archive: Extract the downloaded archive to your desired web server directory (e.g.,
/var/www/html/symfony
). -
Install Dependencies: Navigate to the extracted directory in your terminal and install the dependencies using Composer.
cd /var/www/html/symfony composer install
-
Configure the Web Server: Configure your web server (Nginx or Apache) to point to the
public
directory within the Symfony project. This involves creating a virtual host configuration file.Example Nginx Configuration:
server { listen 80; server_name yourdomain.com; root /var/www/html/symfony/public; index index.php; location / { try_files $uri $uri/ /index.php?$args; } location ~ .php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.2-fpm.sock; # Adjust path if needed } location ~ /.ht { deny all; } }
-
Set Permissions: Ensure that the web server user has the necessary permissions to write to the
cache
andlogs
directories.sudo chown -R www-data:www-data var/cache var/log sudo chmod -R 777 var/cache var/log #Less secure, use ACL instead
-
Access the Application: Open your web browser and navigate to the domain name you configured in the web server.
While this method offers greater control, it demands a deeper understanding of the framework and its dependencies. It’s essential to carefully configure the web server and set the correct permissions to ensure the application runs securely and efficiently.
These alternative methods provide flexibility in setting up the Symfony PHP Framework on AlmaLinux 8, catering to different needs and skill levels. Each approach offers unique advantages and disadvantages, so choose the one that best aligns with your project requirements and expertise.