Sign inSign up

kprimecity/docker-symfony-php

By kprimecity

•Updated about 1 year ago

Run Symfony framework using PHP:8.4-fpm.

Image
Languages & frameworks
Developer tools
Web servers
1

1.0K

kprimecity/docker-symfony-php repository overview

⁠docker-symfony 🎁

A Dockerized Symfony application using PHP 8.4 (via php:8.4-alpine⁠) and Nginx (via nginx:alpine⁠). This setup is ideal for local development, testing, and production environments. The container comes with: bash, nano, curl and compose packages, so you can use them directly in the container terminal. You can install Symfony CLI⁠ and Composer⁠ in your host machine if you want to install some packages in your project.

GitHub GitHub Stars GitHub Release GitHub Package Repository Docker Pulls Docker Stars

docker-symfony

⁠Symfony inside PHP + Nginx Docker Images 🐳

A lightweight Docker image combining PHP 8.4 (php:8.4-alpine⁠) and Nginx (nginx:alpine⁠) for running a latest version of Symfony⁠ PHP applications. Perfect for local development, testing, or production environments.

  • Nginx⁠ is a simple and powerfull webserver used to serve your php files. The config files reside in /etc/nginx/conf.d for easy user customization.
  • PHP⁠ is a popular general-purpose scripting language that powers everything from your blog to the most popular websites.
  • Symfony⁠ is a web application framework that makes it easy to develop robust and scalable web applications. The index file of your project resides in /var/www/html/public
  • Alpine Linux⁠ is a lightweight and security-focused Linux distribution known for its minimal size. This small footprint makes the Alpine image a popular choice for creating compact and efficient Docker containers.

nginx php symfony docker


⁠📦 Features

  • Lightweight: Built on Alpine Linux for minimal size.
  • PHP 8.4: Full PHP 8.4 support with FPM (FastCGI Process Manager).
  • Nginx: High-performance web server with reverse proxy capabilities.
  • Symfony Ready: Out-of-the-box support for Symfony apps in /var/www/html.
  • Easy Configuration: Customizable Nginx and PHP-FPM settings.
  • Ready to Use: Out-of-the-box support for PHP applications.

⁠⚙️ Supported Architectures

The architectures supported by this image are:

ArchitectureAvailableTag
x86-64✅amd64-<version tag>
arm64✅arm64v8-<version tag>

⁠🛠️ Configuration

This is the description of the Docker Compose file configuration.

[!NOTE] PHP_SERVICE_NAME must be the same as php service name. You must use https://xx.xx.xx.xx:8043 to access your project if you need the Symfony Web Debug Toolbar.

You can also put your project (The Port you used to Bind to Port 80) under a Reverse Proxy, you can use Nginx Proxy Manager⁠.

📌 Ports📚 Description
8008Bind Port 80: Symfony Web Debug Toolbar Not Loading
8043Bind Port 443: Symfony Web Debug Toolbar loads correctly
🏷️ Environment📚 Description
PGIDProcess Group ID, Linux command: id
PUIDProcess User ID, Linux command: id
PHP_SERVICE_NAMEHis value must be the same as the php service name in your Docker Compose file
📁 Volume📚 Description
./path/to/web/confMount Nginx configuration folder: /etc/nginx/conf.d
./path/to/web/htmlMount symfony framework folder: /var/www/html

⁠🚀 Getting Started

To help you get started creating a container from this image you can either use docker-compose or the docker cli. The easy way is to follow this steps:

  1. Clone or download the Repository: git clone https://github.com/kprimecity/docker-symfony.git,
  2. Go in the folder: cd docker-symfony
  3. Modify the docker-compose file according to your needs: sudo nano docker-compose.yaml,
  4. Run sudo docker compose up --wait -d to set up and start a fresh Symfony project,
  5. Wait a few minutes for the Symfony framework to be downloaded, you can check the php container log to see the progress,
  6. Open https://localhost:8043 in your favorite web browser to access your project,
  7. Replace localhost by your local ip address.
⁠1. Clone the Repository
git clone https://github.com/kprimecity/docker-symfony.git
cd docker-symfony
⁠2. Set your configuration
sudo nano docker-compose.yaml

[!NOTE] Modify the Docker Compose file before running it; so you can adjust your containers (Nginx and PHP) according to your needs. Run the containers using: sudo docker compose up --wait -d. Wait a few minutes for the Symfony framework to be downloaded.

Docker compose file:

name: docker-symfony
services:
    nginx-8008: # Your Nginx service name
        image: kprimecity/docker-symfony-nginx:latest
        container_name: docker-symfony-nginx-8008 # Your Container name
        restart: unless-stopped
        environment:
            - PGID=1000
            - PUID=1000
            - PHP_SERVICE_NAME=php-8008 # This Value MUST be as the php service name bellow
        ports:
            - 8008:80 # Bind Port 80: Symfony Web Debug Toolbar Not Loading
            - 8043:443 # Bind Port 443: Symfony Web Debug Toolbar loads Correctly
        volumes:
            - ./path/to/web/conf/8008:/etc/nginx/conf.d # Mount Nginx config
        depends_on:
            - php-8008 # Same as PHP_SERVICE_NAME environment and php service name bellow
        networks:
            - docker-symfony-network

    php-8008: # PHP service name: Same as PHP_SERVICE_NAME environment ABOVE
        image: kprimecity/docker-symfony-php:latest
        container_name: docker-symfony-php-8008 # Your Container name
        restart: unless-stopped
        environment:
            - PGID=1000
            - PUID=1000
        volumes:
            - ./path/to/web/html:/var/www/html # Mount html content to manage your project locally
        networks:
            - docker-symfony-network

networks:
    docker-symfony-network:
        name: docker-symfony-network
        driver: bridge
    default:
        name: docker-symfony_default

Docker Run command:

docker network create -d bridge docker-symfony-network \
docker network create docker-symfony_default \
docker run --net docker-symfony-network \
  --name docker-symfony-nginx-8008 \
  --restart unless-stopped
  -e PGID=1000 \
  -e PUID=1000 \
  -e PHP_SERVICE_NAME=php-8008 \
  -p 8008:80 \
  -p 8043:443 \
  -v ./path/to/web/conf/8008:/etc/nginx/conf.d \
  kprimecity/docker-symfony-nginx:latest \
docker run --net docker-symfony-network \
  --name docker-symfony-php-8008 \
  --restart unless-stopped \
  -e PGID=1000 \
  -e PUID=1000 \
  -v ./path/to/web/html:/var/www/html \
  kprimecity/docker-symfony-php:latest
⁠3. Build the Docker Image & Run the Container
sudo docker compose up --wait -d

[!NOTE] This command will build all Docker images and run all containers.


⁠🌐 Usage

After running the container, access your application in your browser:

https://localhost:8043

You should see your index page rendered by the docker-symfony Nginx and PHP-FPM containers.

preview

[!NOTE] No need to start the Symfony server to access your project.


⁠📝 Notes

  • By default, Symfony SSL is used just in development; never use it in production.
  • For more security propose or in production mode:
    • Put your project (The Port you used to Bind to Port 80) under a Reverse Proxy, you can use Nginx Proxy Manager⁠,
    • Or change the SSL source in the nginx server configuration to make Nginx use your own SSL.
  • The Docker Compose Environment (PHP_SERVICE_NAME) value must be as the php container service name.
  • Your project URLs: http://xx.xx.xx.xx:8008 (No Symfony Web Debug Toolbar) or https://xx.xx.xx.xx:8043 (With Symfony Web Debug Toolbar).

⁠🤝 Contributing

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/your-feature).
  3. Make your changes.
  4. Commit your changes (git commit -m "Add your feature").
  5. Push to the branch (git push origin feature/your-feature).
  6. Open a pull request.

⁠📄 License

This project is licensed under the GPL-3.0 License⁠. See the LICENSE⁠ file for details.

License: GPL v3


⁠🔎 Acknowledgments


Take care! 💖

Tag summary

Content type

Image

Digest

sha256:4b0093877…

Size

55.3 MB

Last updated

about 1 year ago

docker pull kprimecity/docker-symfony-php