Symfony is a mature, enterprise-grade PHP framework built on reusable, decoupled components. Unlike Laravel’s all-in-one approach, Symfony emphasises architectural flexibility — many of its components (HttpFoundation, Console, Validator, Security, DependencyInjection) are used independently by other frameworks including Laravel itself. Symfony’s Dependency Injection Container, event dispatcher, and strict coding standards make it the preferred framework for complex, long-lived enterprise applications. The Symfony Console component powers many PHP CLI tools including Composer. This guide covers installing Symfony 7 on RHEL 9 using the Symfony CLI, deploying a web application with Nginx and PHP-FPM, and configuring the environment.
Prerequisites
- PHP 8.2+ and Composer installed on RHEL 9
- Nginx installed
Step 1 — Install the Symfony CLI
# Install the Symfony CLI for local development and deployment tooling
curl -1sLf 'https://dl.cloudsmith.io/public/symfony/stable/setup.rpm.sh' | bash
dnf install -y symfony-cli
symfony check:requirements
Step 2 — Create a New Symfony 7 Application
cd /var/www
# Full web application (includes all bundles)
symfony new myapp --version="7.1.*" --webapp
# Or minimal skeleton for APIs/microservices
# symfony new myapi --version="7.1.*"
chown -R nginx:nginx /var/www/myapp
Step 3 — Configure the Environment
# /var/www/myapp/.env.local (not committed to version control)
APP_ENV=prod
APP_SECRET=$(php -r "echo bin2hex(random_bytes(16));")
DATABASE_URL="mysql://myapp_user:[email protected]:3306/myapp_db?serverVersion=8.0"
REDIS_URL=redis://127.0.0.1:6379
Step 4 — Configure Nginx Virtual Host
# /etc/nginx/conf.d/myapp.conf
server {
listen 80;
server_name myapp.example.com;
root /var/www/myapp/public;
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)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ .php$ {
return 404;
}
error_log /var/log/nginx/myapp_error.log;
access_log /var/log/nginx/myapp_access.log;
}
nginx -t && systemctl reload nginx
Step 5 — Install Dependencies and Warm Up Cache
cd /var/www/myapp
# Install production dependencies only
composer install --no-dev --optimize-autoloader
# Warm up the Symfony container (DI compilation, config processing)
APP_ENV=prod php bin/console cache:warmup
# Create database and run migrations
php bin/console doctrine:database:create
php bin/console doctrine:migrations:migrate --no-interaction
Step 6 — Configure SELinux Contexts
setsebool -P httpd_can_network_connect 1
semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/myapp/var(/.*)?"
restorecon -Rv /var/www/myapp/var
Conclusion
Symfony 7 on RHEL 9 provides a robust foundation for enterprise PHP applications. Symfony’s strict environment separation (.env, .env.local, .env.prod) and the compiled Dependency Injection container make it well-suited for deployment pipelines where the same code runs in development, staging, and production with different configurations. Always run cache:warmup after deployment — compiling the DI container at deploy time rather than on the first request eliminates the cold-start latency for all users.
Next steps: How to Install Laravel on RHEL 9, How to Configure PHP-FPM with Nginx on RHEL 9, and How to Harden PHP on RHEL 9.