Skip to content

Symfony starter kit setup with docker, docker-compose, php8.2 nginx, adminer, postgresql, mailhog, SymfonyPHP 7.1, pre-commit setup with psr-12 and phpstan

License

Notifications You must be signed in to change notification settings

starter-nanorocks/symfony-php-starter-kit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Symfony PHP Starter Kit

This is a starter kit for Symfony 7.1 with the following technologies:

  • Docker
  • Docker Compose
  • PHP 8.2
  • Nginx
  • Adminer
  • PostgreSQL
  • MailHog
  • Xdebug

Requirements

  • Docker
  • Docker Compose

Getting Started

  1. Clone the repository:

    git clone https://github.com/yourusername/symfony-starter-kit.git
    cd symfony-starter-kit
  2. Create environment variables:

    cp .env.dist .env
  3. Build and start the containers:

    docker-compose up --build -d
  4. Install Symfony dependencies:

    docker-compose exec php composer install

Services

  • PHP 8.2: The PHP version used for the application.
  • Nginx: Serves the Symfony application.
  • PostgreSQL: The database server.
  • Adminer: Database management tool accessible at http://localhost:8080.
  • MailHog: Email testing tool accessible at http://localhost:8025.

Docker Compose Configuration

Here is the docker-compose.yml configuration:

version: '4.2'

services:
  php-fpm:
    container_name: php
    build:
      context: .
      dockerfile: docker/php/Dockerfile
    volumes:
      - ./symfony:/var/www/html/symfony
      - ./docker/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
      - ./docker/php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
    networks:
      - starter-kit

  nginx:
    container_name: nginx
    image: nginx:stable
    ports:
      - '80:80'
    volumes:
      - ./symfony:/var/www/html/symfony
      - ./docker/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf
    networks:
      - starter-kit

  db:
    container_name: postgres
    image: postgres
    restart: always
    shm_size: 128mb
    environment:
      POSTGRES_PASSWORD: secret
    ports:
      - '5432:5432'
    volumes:
      - ./docker/db/init.sql:/docker-entrypoint-initdb.d/init.sql
    networks:
      - starter-kit
    command: postgres -c 'max_connections=200'

  adminer:
    container_name: adminer
    image: adminer
    restart: always
    environment:
      ADMINER_DEFAULT_DB_HOST: database
      ADMINER_DESIGN: haeckel
      ADMINER_PLUGINS: tables-filter tinymce
    ports:
      - '54320:8080'
    networks:
      - starter-kit

  mailhog:
    container_name: mailhog
    image: mailhog/mailhog:latest
    restart: always
    ports:
      - 1025:1025
      - 8025:8025
    networks:
      - starter-kit

networks:
  starter-kit:
    driver: bridge

Pre-commit Setup with GrumPHP

Install GrumPHP

Add GrumPHP to your Symfony project using Composer:

docker-compose exec php composer require --dev phpro/grumphp

Configure GrumPHP

Create a grumphp.yml file in the root of your project:

grumphp:
    tasks:
        phpcs:
            standard:
                - 'PSR12'
        phpstan:
            autoload_file: ~
            configuration: ~
            level: null
            force_patterns: []
            ignore_patterns: []
            triggered_by: ['php']
            memory_limit: "-1"
            use_grumphp_paths: true

Update composer.json

Add the GrumPHP configuration to your composer.json scripts section to automatically run GrumPHP on git commit:

"scripts": {
    "post-install-cmd": [
        "vendor/bin/grumphp git:init"
    ],
    "post-update-cmd": [
        "vendor/bin/grumphp git:init"
    ]
}

Initialize GrumPHP

Run the following command to initialize GrumPHP:

php vendor/bin/grumphp git:init

Database Configuration

Update the .env file with your database credentials:

DATABASE_URL=postgresql://symfony:symfony@postgres:5432/symfony

Accessing Services

License

This project is licensed under the MIT License.

About

Symfony starter kit setup with docker, docker-compose, php8.2 nginx, adminer, postgresql, mailhog, SymfonyPHP 7.1, pre-commit setup with psr-12 and phpstan

Topics

Resources

License

Stars

Watchers

Forks