Practical guide
How to start a Symfony project for a real production application
Do not start with an empty folder only. Set up healthy foundations for local development, tests, and deployment from day one.
First, the short version
What does a production foundation mean?
Symfony is a framework for PHP applications. It gives you a ready-made structure, a console, configuration, and sensible defaults.
Composer keeps track of packages and their exact versions. A production foundation is not complicated: code goes to Git, secrets stay outside the repository, and each environment has its own configuration.
Get ready
What you need
You do not need a cloud account or a finished database for the first pass. A clean local environment is enough.
Steps 1 to 3
Create the project and set up its environment
Use small, verifiable steps. After each one, you know exactly what works.
1. Create a clean Symfony project
- Choose a short directory name without spaces. The command creates the project, downloads dependencies, and prepares the basic structure.
- For a regular web application, then add webapp. It brings forms, security components, and other common foundations.
- Choose the framework version deliberately. For a long-lived application, the current LTS is often more useful than a random command found online.
composer create-project symfony/skeleton my-app Official Symfony project setup guide 2. Keep settings separate from code
- Open .env, but do not put production secrets there. Treat it as a list of expected variables and safe default values.
- Use .env.local on your computer. Do not commit it. On the server, set environment variables in your host, container, or secret manager.
- Read database connections, API keys, and service addresses from environment variables. The same code can then run locally, in testing, and in production.
composer require webapp Official Symfony configuration and .env documentation 3. Add the first production safeguards
- Commit composer.lock. It makes the server install the same tested package versions that you use locally.
- Make deployment run composer install without development packages, optimise the autoloader, and warm up the cache.
- Always turn APP_DEBUG off in production. An error page must not reveal paths, configuration, or an exception trace to visitors.
APP_ENV=prod APP_DEBUG=0 php bin/console cache:warmup Official Composer introduction Step 4
Check that the foundation actually holds
These three short checks catch most early mistakes.
-
Inspect the project
Symfony shows the version, active environment, and installed packages. Run it from the project root.
php bin/console about -
Check Composer files
Before sharing the code, check the composer.json format and consistency with the dependency lock file.
composer validate --strict -
Try the production cache
This is not a replacement for deployment, but it quickly exposes a production configuration problem or a missing variable.
APP_ENV=prod APP_DEBUG=0 php bin/console cache:clear
If something goes wrong
Common problems
The command reports an unsupported PHP version
Compare php -v with the requirements of the Symfony version you chose. Do not randomly change composer.json; first fix PHP locally or choose a supported framework version.
php -v A password or API key made it into Git
Revoke the key and create a new one immediately. Deleting the line is not enough because the secret stays in history. Then move the value to an environment variable and ignore .env.local.
It works locally but not in production
Compare the list of variables, permissions for var/cache, and APP_ENV. Production must not copy a developer’s entire .env.local.
php bin/console debug:container --env-vars Every developer has different packages
Check that composer.lock is versioned and install dependencies with composer install. Use composer update deliberately during a planned update.
git status --short Done
The project has a foundation you can build on.
Your Symfony project now has separate configuration and its first production checks. Add features in small units and keep verifying them as you go.