JSON REST API which is built on top of Symfony framework.
This application is meant to be used as an API that frontend applications or
different backend applications can use as needed. One example frontend is
this Angular template,
though you can use any frontend solution.
git clone https://github.com/tarlepp/symfony-flex-backend.git
cd symfony-flex-backend
make startThen open https://localhost:8000 in your browser. For more details, see
Installation.
Requirements ᐞ
- Docker Engine
- Docker Compose v2 (included with Docker Desktop)
If you are not using Docker Engine, follow this.
Recommendations ᐞ
*nix platform- most likely you're going to host your application on *nix platform - so I would recommend to do development also on that platform.WSL2 on Windows- if you develop on Windows, use WSL2 to get a Linux-like development environment for Docker and tooling.Dev Container capable IDE- recommended for the quickest setup (e.g. VS Code or JetBrains IDEs with Dev Container support).Makefilesupport - recommended if you run containers with Make commands; if you do not havemake, checkMakefileto see equivalent Docker commands.
Installation ᐞ
This installation guide expects that you're using Docker Engine.
1. Clone repository ᐞ
Use your favorite IDE and check out the repository from GitHub, or use the following command:
git clone https://github.com/tarlepp/symfony-flex-backend.git2. Start containers ᐞ
You can run this project either with Dev Containers (for example in VS Code or JetBrains IDEs) or with Make commands.
For Dev Containers, open this repository in your IDE and use its Dev Container workflow to reopen/start the project in a container (see Dev Containers section for details).
If you want to use Make commands instead, run the following command, which will start all the containers:
make startIf you want to start containers in the background, use the following command:
make daemonThese commands will create following containers to run this backend application:
- php (this is for actual application)
- nginx (this will serve application)
- mariadb (MariaDB 10.7 which will store all the data of application)
- dozzle (to see your docker container logs)
- adminer (to manage your database via browser)
For next steps (application URLs, shell access, and rebuilding containers), see Running the application.
Running the application ᐞ
These instructions are shared for both Make-based and Dev Container-based workflows.
Using application ᐞ
When containers are running (either via Make commands or Dev Containers),
following ports are exposed on localhost on your host machine:
- symfony-backend-nginx - https://localhost:8000 (nginx)
- PHP-FPM status page - https://localhost:8000/status
- SSL with self-signed certificates
- symfony-backend-nginx - http://localhost:8080 (nginx)
- PHP-FPM status page - http://localhost:8080/status
- Normal HTTP
- symfony-backend-php-fpm - this is not exposed to host machine (php-fpm)
- symfony-backend-mariadb -
localhost:33060(mariadb) - symfony-backend-dozzle - http://localhost:8100 (dozzle)
- symfony-backend-adminer - http://localhost:8200 (adminer)
And this application is usable in your browser at https://localhost:8000.
When you open that site for the first time, you will see a "Your connection is
not private" warning - see this to resolve that.
Another choice is to use http://localhost:8080, which does not use SSL.
MariaDB credentials:
user: root
password: passwordNote: These credentials are for local development only and should never be used in production.
Getting shell to container ᐞ
After you've started containers (make start / make daemon or via Dev
Containers), you can list all running containers with docker ps.
To get shell (bash or fish) access inside one of those containers, run the following command:
make bashor
make fishIf you are using Dev Containers, you can also use the IDE terminal that is
already attached to the php container.
Building containers ᐞ
From time to time you probably need to build containers again. This is something that you should do every time if you have some problems getting containers up and running.
If you use Make commands, rebuild/start containers with:
make daemon-buildIf you want to see container logs directly, use the following command:
make start-buildIf you use Dev Containers, use your IDE's Dev Container rebuild action (for example, "Rebuild Container" / "Rebuild and Reopen in Container").
If you prefer CLI, you can rebuild with:
docker compose -f compose.yaml -f .devcontainer/docker-compose.devcontainer.yml build
docker compose -f compose.yaml -f .devcontainer/docker-compose.devcontainer.yml up -d php mariadb nginx dozzle adminerHealth check ᐞ
To verify your setup is working correctly, you can check:
# Check container status
docker compose ps
# Test HTTP endpoint
curl -I http://localhost:8080
# Test HTTPS endpoint (ignore SSL warning)
curl -k -I https://localhost:8000Alternatively, you can use Dozzle (container log viewer) to monitor all services:
- Open http://localhost:8100 in your browser
- View real-time logs for all running containers
- Check container status and resource usage
Dev Containers ᐞ
This project also includes a Dev Container setup in .devcontainer/ that can
be used from VS Code and JetBrains IDEs with Dev Container support.
When you reopen the repository in a container, it starts the full Docker Compose stack:
phpnginxmariadbdozzleadminer
For application URLs, shell access, and rebuild commands, see Running the application.
For detailed usage, UID/GID notes, and port mappings, see
.devcontainer/README.md.
Frontend? ᐞ
This backend API can be consumed by any frontend technology or framework. You can use React, Vue, Angular, Svelte, or any other frontend solution that can make HTTP requests.
As a reference example, I've created an Angular NgRx powered frontend template project that works with this backend. It demonstrates how to integrate with this API, but you're free to use any technology stack that fits your project needs.
With this backend, it should be quite easy to start building your own application with the frontend technology of your choice.
Resources ᐞ
- Resource index
- Application commands
- GitHub Actions update guide
- Concepts and features
- Custom configuration
- Development guide
- Installation without docker
- PhpStorm configuration
- Speed problems with Docker Engine?
- Testing guide
- Usage checklist
- Using Xdebug
- Scripts
External links / resources ᐞ
- Symfony Flex set to enable RAD (Rapid Application Development)
- Symfony 4: A quick Demo
- composer-version
- Symfony Recipes Server
Authors ᐞ
License ᐞ
Copyright © 2024 Tarmo Leppänen
