How to Install Symfony on RHEL 7
Symfony is a mature, enterprise-grade PHP framework built around reusable components that power projects ranging from small APIs to large-scale e-commerce platforms. Many PHP projects, including Drupal, Laravel, and Magento, depend directly on Symfony components. Installing Symfony on RHEL 7 follows a similar pattern to other PHP frameworks: you need a recent PHP version, Composer, and a web server. Symfony offers two installation paths — a minimal symfony/skeleton project that you build up with only the components you need, or the full symfony/website-skeleton that includes a complete set for traditional web applications. This guide covers both the Symfony CLI tool and Composer-based installation, along with Nginx configuration, environment setup, and production deployment considerations specific to RHEL 7.
Prerequisites
- RHEL 7 server with root or sudo access
- PHP 7.4 or newer from the Remi repository
- PHP extensions:
php-fpm,php-xml,php-mbstring,php-intl,php-curl,php-zip,php-opcache,php-pdo - Composer installed globally at
/usr/local/bin/composer - Nginx installed and running
- MySQL or PostgreSQL database (for applications requiring persistence)
Step 1: Install the Symfony CLI (Optional but Recommended)
The Symfony CLI provides a local development server, dependency checker, and cloud deployment integration. Download and install it:
curl -1sLf 'https://dl.cloudsmith.io/public/symfony/stable/setup.rpm.sh' | sudo bash
sudo yum install -y symfony-cli
Verify the installation:
symfony version
Use the built-in requirements checker to confirm your PHP environment meets Symfony’s needs:
symfony check:requirements
The checker will report missing extensions or misconfigured settings with instructions for fixing each issue.
Step 2: Create a New Symfony Project
Option A: Using the Symfony CLI
Create a new Symfony skeleton application (API or microservice):
cd /var/www
sudo symfony new myapp --version="6.4.*"
For a full web application with Twig, forms, and security components:
sudo symfony new myapp --version="6.4.*" --webapp
Option B: Using Composer
If you prefer not to install the Symfony CLI, use Composer directly:
cd /var/www
sudo composer create-project symfony/skeleton:"6.4.*" myapp
For the full webapp skeleton:
sudo composer create-project symfony/website-skeleton:"6.4.*" myapp
Step 3: Set Directory Ownership and Permissions
Assign ownership to the nginx user so PHP-FPM can read and write application files:
sudo chown -R nginx:nginx /var/www/myapp
Symfony writes compiled code, logs, and cache to the var/ directory. Ensure it is writable:
sudo chmod -R 775 /var/www/myapp/var
Step 4: Configure the .env File
Symfony reads environment variables from .env files in the project root. The base .env file ships with the project and contains non-sensitive defaults. Create .env.local for machine-specific overrides that should not be committed to version control:
sudo vi /var/www/myapp/.env.local
APP_ENV=dev
APP_SECRET=your_32_character_random_string_here
# Database connection (Doctrine DSN format)
DATABASE_URL="mysql://symfonyuser:StrongP@[email protected]:3306/symfony_db?serverVersion=5.7&charset=utf8mb4"
# Mailer DSN
MAILER_DSN=smtp://localhost
Generate a secure random APP_SECRET:
php -r "echo bin2hex(random_bytes(16)) . PHP_EOL;"
Step 5: Run the Development Server
For local development, the Symfony CLI includes a PHP-based development server that requires no Nginx configuration:
cd /var/www/myapp
symfony server:start --no-tls
Access the application at http://localhost:8000. The development server watches for file changes and does not need to be restarted between edits.
To run it in the background:
symfony server:start --no-tls -d
Stop it with:
symfony server:stop
If you are not using the Symfony CLI, use PHP’s built-in web server pointed at the public/ directory:
cd /var/www/myapp
php -S 127.0.0.1:8000 -t public/
Step 6: Configure Nginx for Symfony (Production)
For production or staging environments, configure Nginx to serve the Symfony application. The public entry point is public/index.php:
sudo vi /etc/nginx/conf.d/symfony.conf
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/myapp/public;
index index.php;
access_log /var/log/nginx/symfony_access.log;
error_log /var/log/nginx/symfony_error.log;
location / {
# Route all requests through the Symfony front controller
try_files $uri $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;
fastcgi_read_timeout 300;
internal;
}
# Block access to all other .php files
location ~ .php$ {
return 404;
}
location ~ /.(?!well-known).* {
deny all;
}
client_max_body_size 32M;
}
Test the configuration and reload Nginx:
sudo nginx -t
sudo systemctl reload nginx
Step 7: Configure the Production Environment
For production, set APP_ENV=prod in .env.local and install dependencies without development packages:
sudo -u nginx composer install --no-dev --optimize-autoloader
Clear and warm up the Symfony cache for the production environment:
cd /var/www/myapp
sudo -u nginx php bin/console cache:clear --env=prod
sudo -u nginx php bin/console cache:warmup --env=prod
Run any pending database migrations:
sudo -u nginx php bin/console doctrine:migrations:migrate --no-interaction
Step 8: Configure SELinux for Symfony on RHEL 7
RHEL 7’s SELinux in enforcing mode will block PHP-FPM from writing to var/ unless the correct file context is applied:
sudo setsebool -P httpd_unified 1
sudo setsebool -P httpd_can_network_connect 1
sudo setsebool -P httpd_can_network_connect_db 1
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/myapp/var(/.*)?"
sudo restorecon -Rv /var/www/myapp/var
Step 9: Set var/ Directory Permissions Properly
Symfony requires write access to var/cache/, var/log/, and sometimes var/sessions/. The recommended approach on systems where multiple users may run console commands is to use the POSIX ACL:
sudo setfacl -dR -m u:nginx:rwX -m u:$(whoami):rwX /var/www/myapp/var
sudo setfacl -R -m u:nginx:rwX -m u:$(whoami):rwX /var/www/myapp/var
If setfacl is not available, install acl:
sudo yum install -y acl
Step 10: Useful Symfony Console Commands
The Symfony console is the primary CLI for managing the application:
# List all available commands
php bin/console list
# Check environment requirements
php bin/console about
# Clear cache
php bin/console cache:clear
# Show routing table
php bin/console debug:router
# Show registered services
php bin/console debug:container
# Create a new controller
php bin/console make:controller HomeController
# Run database migrations
php bin/console doctrine:migrations:migrate
Conclusion
Symfony is now installed and configured on RHEL 7 with Nginx, PHP-FPM, and a proper production environment setup. The var/ directory permissions are correctly configured for both the web server and any console users, SELinux booleans allow PHP to connect to the database and network, and the production cache is warmed up for optimal performance. From here, you can install additional Symfony bundles through Symfony Flex by running composer require, scaffold entities and repositories with the Maker bundle, configure Doctrine ORM for database abstraction, and set up the Symfony profiler for debugging in development environments.