Symfony is a mature, enterprise-grade PHP framework and a collection of reusable components that power many of the world’s largest PHP applications, including Drupal and parts of Laravel itself. It emphasises strict standards, comprehensive testing support, and long-term support releases that align well with RHEL 8’s stability-first philosophy. This tutorial covers installing the Symfony CLI on RHEL 8, creating a full web application skeleton, configuring Nginx for production, and applying best practices for deploying Symfony in an enterprise environment.
Prerequisites
- PHP 8.0 or 8.1 installed via AppStream with
php-fpm,php-cli,php-mbstring,php-xml,php-intl,php-pdo, andphp-mysqlnd - Composer installed globally at
/usr/local/bin/composer - Nginx installed (
sudo dnf install nginx) - A database server (MariaDB, MySQL, or PostgreSQL) running and accessible
- A user account with
sudoprivileges
Step 1 — Install the Symfony CLI
The Symfony CLI is a developer productivity tool that provides a local development server, project creation commands, and environment checks. Install it by downloading and running the official installer script.
curl -sS https://get.symfony.com/cli/installer | bash
sudo mv "$HOME/.symfony5/bin/symfony" /usr/local/bin/symfony
symfony --version
After installation, run symfony check:requirements to verify that your PHP environment meets all Symfony’s requirements. The CLI will report any missing extensions or configuration issues.
symfony check:requirements
Step 2 — Create a New Symfony Web Application
Use the Symfony CLI to scaffold a full web application with the standard set of bundles for a web project, including Twig, Doctrine ORM, and the web profiler.
cd /var/www
sudo symfony new myproject --webapp
sudo chown -R nginx:nginx /var/www/myproject
The --webapp flag installs the full web application skeleton. If you only need a minimal API project, omit that flag. The chown step transfers ownership to the Nginx user so the web server can read project files.
Step 3 — Configure the Environment and Database
Symfony uses a .env file for environment configuration and a .env.local override for machine-specific values that should not be committed to version control.
cd /var/www/myproject
cp .env .env.local
sudo vi .env.local
Set the database DSN in .env.local to match your database server. For MariaDB or MySQL, use a value like the following — replace the credentials and database name with your own:
DATABASE_URL="mysql://db_user:[email protected]:3306/myproject?serverVersion=10.4"
After configuring the database, create the schema and run any bundled migrations:
php bin/console doctrine:database:create
php bin/console doctrine:migrations:migrate
Step 4 — Start the Development Server
During development, use the Symfony CLI’s built-in HTTPS-enabled development server instead of configuring Nginx. It automatically reloads when files change and proxies the PHP-FPM worker.
cd /var/www/myproject
symfony serve --no-tls
Open the URL printed in the terminal (typically http://127.0.0.1:8000) in a browser to see the Symfony welcome page. Press Ctrl+C to stop the server.
Step 5 — Configure Nginx for Production
For a production deployment, configure Nginx to serve Symfony’s public/ directory and route all requests through the index.php front controller.
sudo vi /etc/nginx/conf.d/myproject.conf
Add the following server block, adjusting server_name and document root to match your deployment:
server {
listen 80;
server_name myproject.example.com;
root /var/www/myproject/public;
index index.php;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/index.php(/|$) {
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_split_path_info ^(.+.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
include fastcgi_params;
internal;
}
location ~ .php$ {
return 404;
}
}
sudo nginx -t && sudo systemctl reload nginx
Step 6 — Optimise for Production Deployment
Symfony has a dedicated production optimisation step that warms the DI container cache and installs only production dependencies. Run these commands after every code deployment.
cd /var/www/myproject
composer install --no-dev --optimize-autoloader
APP_ENV=prod APP_DEBUG=0 php bin/console cache:clear
php bin/console cache:warmup
The --no-dev flag skips development-only packages, and --optimize-autoloader generates an authoritative classmap that avoids filesystem checks on every class load. Ensure APP_ENV=prod is set in your actual environment or server configuration rather than on the command line for a running application.
Conclusion
You have installed the Symfony CLI and framework on RHEL 8, created a full web application skeleton, configured Nginx to serve the project through PHP-FPM, and applied production optimisations. Symfony’s strict architecture and long-term support releases make it an excellent choice for enterprise workloads on RHEL 8. Your application is now ready for feature development and further deployment automation.
Next steps: How to Install Laravel on RHEL 8, How to Configure PHP-FPM with Nginx on RHEL 8, and How to Install Composer on RHEL 8.