Giter Site home page Giter Site logo

staffnowa / docker-symfony Goto Github PK

View Code? Open in Web Editor NEW
41.0 6.0 12.0 403 KB

Docker Symfony (PHP-FPM - NGINX - MySQL - MailHog - Redis - RabbitMQ)

License: MIT License

Shell 43.99% Go 56.01%
docker-symfony linux php-fpm nginx mysql docker symfony-application mailhog redis rabbitmq supervisor mariadb elasticsearch blackfire ngrok wkhtmltopdf yarn npm

docker-symfony's Introduction

Docker for Symfony (PHP-FPM - NGINX - MySQL)

Docker symfony gives you everything you need for developing Symfony application. This complete stack run with docker and docker-compose.

Installation

Install the latest Docker CE version

If you are running on Linux:

curl -fsSL https://get.docker.com -o get-docker.sh &&
sh get-docker.sh

If you would like to use Docker as a non-root user, you should now consider adding your user to the "docker" group with something like:

sudo usermod -aG docker ${USER}

Install the latest Docker Compose

If you are running on Linux:

sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose

Configuration

  1. Create a .env from the .env.dist file. Adapt it according to your symfony application

    cp .env.dist .env
  2. Build / run containers

    ./d4d start
    
  3. Update your system host file (add symfony.local)

    # UNIX only: get containers IP address and update host (replace IP according to your configuration)
    $ sudo echo $(docker network inspect bridge | grep Gateway | grep -o -E '[0-9\.]+') "symfony.local" >> /etc/hosts

    Note: For OS X, please take a look here.

  4. Prepare Symfony app

    1. Get your logins to access MySQL server ./d4d passwd show

    2. Update

      a) SF2, SF3: app/config/parameters.yml

      # ./project/app/config/parameters.yml
      parameters:
          database_host:     mysql
          database_port:     ~
          database_name:     db_name
          database_user:     db_user
          database_password: db_password (random password)
      

      b) SF4, SF5, SF6: .env

      DATABASE_URL=mysql://db_user:db_password@mysql:3306/db_name
      MAILER_URL=smtp://mailhog:1025
      
    3. Composer install & create database

      $ docker-compose exec php bash
      $ composer create-project symfony/website-skeleton my-project
          
      # Symfony 2
      $ sf doctrine:database:create
      $ sf doctrine:schema:update --force
      # Only if you have `doctrine/doctrine-fixtures-bundle` installed
      $ sf doctrine:fixtures:load --no-interaction
          
      # Symfony 3
      $ sf3 doctrine:database:create
      $ sf3 doctrine:schema:update --force
      # Only if you have `doctrine/doctrine-fixtures-bundle` installed
      $ sf3 doctrine:fixtures:load --no-interaction
      
      # Symfony 4
      $ sf4 doctrine:database:create
      $ sf4 doctrine:schema:update --force
      # Only if you have `doctrine/doctrine-fixtures-bundle` installed
      $ sf4 doctrine:fixtures:load --no-interaction
      
      # Symfony 5
      $ sf5 doctrine:database:create
      $ sf5 doctrine:schema:update --force
      # Only if you have `doctrine/doctrine-fixtures-bundle` installed
      $ sf5 doctrine:fixtures:load --no-interaction
      
      # Symfony 6
      $ sf6 doctrine:database:create
      $ sf6 doctrine:schema:update --force
      # Only if you have `doctrine/doctrine-fixtures-bundle` installed
      $ sf6 doctrine:fixtures:load --no-interaction
  5. Enjoy :-)

    Usage

    Just run ./d4d start, then:

    How it works?

    Have a look at the docker-compose.yml file, here are the docker-compose built images:

    • nginx: Nginx is one of the most popular web servers in the world and responsible for hosting some of the largest and highest-traffic sites on the internet. It is more resource-friendly than Apache in most cases and can be used as a web server or reverse proxy.
    • php: PHP is a popular general-purpose scripting language that is especially suited to web development.
    • mysql: MySQL is the most popular relational database management system.
    • phpmyadmin: phpMyAdmin was created so that users can interact with MySQL / MariaDB through a web interface.
    • mailhog: MailHog is an email testing tool for developers.
    • redis: Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.

    This results in the following running containers:

    $ docker-compose ps
               Name                          Command               State                       Ports                     
    ---------------------------------------------------------------------------------------------------------------------
    docker-symfony_mailhog_1      MailHog                          Up      0.0.0.0:1025->1025/tcp, 0.0.0.0:8025->8025/tcp
    docker-symfony_mysql_1        docker-entrypoint.sh --cha ...   Up      0.0.0.0:3306->3306/tcp                        
    docker-symfony_nginx_1        nginx -g daemon off;             Up      0.0.0.0:80->80/tcp                            
    docker-symfony_php_1          docker-php-entrypoint php-fpm    Up      9000/tcp                                      
    docker-symfony_phpmyadmin_1   /docker-entrypoint.sh apac ...   Up      0.0.0.0:8080->80/tcp                          
    docker-symfony_redis_1        docker-entrypoint.sh redis ...   Up      6379/tcp          

PHP extensions

Extension PHP 7.1 PHP 7.2 PHP 7.3 PHP 7.4 PHP 8.0 PHP 8.1 PHP 8.2 PHP 8.3
amqp 1.11.0 1.11.0 1.11.0 2.1.1 2.1.1 2.1.1 2.1.1 2.1.1
mongodb 1.11.1 1.16.2 1.16.2 1.17.1 1.17.1 1.17.1 1.17.1 1.17.1
redis 5.3.7 6.0.2 6.0.2 6.0.2 6.0.2 6.0.2 6.0.2 6.0.2
xdebug 2.9.8 3.1.6 3.1.6 3.1.6 3.1.6 3.1.6 3.1.6 3.1.6

DirectAdmin support us!

JetBrains support us!

Blackfire.io support us!

Get $200 to try DigitalOcean!

DigitalOcean Referral Badge

docker-symfony's People

Contributors

dependabot[bot] avatar staffnowa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

docker-symfony's Issues

PHP - Don't Check PHP Files Timestamps

In production servers, PHP files should never change, unless a new application version is deployed. However, by default OPcache checks if cached files have changed their contents since they were cached. This check introduces some overhead that can be avoided as follows:

; php.ini
opcache.validate_timestamps=0

After each deploy, you must empty and regenerate the cache of OPcache. Otherwise you won't see the updates made in the application. Given that in PHP, the CLI and the web processes don't share the same OPcache, you cannot clear the web server OPcache by executing some command in your terminal. These are some of the possible solutions:

  1. Restart the web server;
  2. Call the apc_clear_cache() or opcache_reset() functions via the web server (i.e. by having these in a script that you execute over the web);
  3. Use the cachetool utility to control APC and OPcache from the CLI.

[PHP] - missing imap

apt-get install libc-client-dev libkrb5-dev

docker-php-ext-configure imap --with-kerberos --with-imap-ssl && docker-php-ext-install imap

Missing exif

Added new lines
docker-php-ext-install exif
docker-php-ext-enable exif

Install package
apt-get install exiftool

Composer create-project - permission denied

Hi, first of all, thank you for your work, your config looks mature. I have an issue at the stage "Composer install & create database" I have the following error:

➜  staffnowa-symfony git:(master) ✗ docker-compose exec php bash   
www-data@ebd147552d65:~/project$ composer create-project symfony/website-skeleton my-project
Cannot create cache directory /var/www/.composer/cache/repo/https---repo.packagist.org/, or directory is not writable. Proceeding without cache
Installing symfony/website-skeleton (v4.2.1.4)
Cannot create cache directory /var/www/.composer/cache/files/, or directory is not writable. Proceeding without cache

                              
  [ErrorException]            
  mkdir(): Permission denied  

It seems like user www-data cannot write into /var/www/.composer and /var/www/project dirs.

My .env:

PROJECT_PATH=./project

# Project's domain
PROJECT_DOMAIN=staffnowa.local

SYMFONY_LOG_PATH=./var/logs/symfony
NGINX_LOG_PATH=./var/logs/nginx/
MYSQL_DATA_PATH=./var/lib/mysql

# Linux users: Set this to user id from the host system to avoid permission problems.
# Get the user id with: "id -u"
USER_ID=1000
GROUP_ID=1000

# Security
SSH_KEY_PATH=~/.ssh

# Debian OS available versions: wheezy, jessie, stretch
DEBIAN_VERSION=stretch

# PHP available versions: 5.6, 7.0, 7.1, 7.2, 7.3
PHP_VERSION=7.2

NGINX_VERSION=1.15.7-1~stretch

# Composer
COMPOSER_PATH=~/.composer

# MySQL
MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE=db_name
MYSQL_USER=db_user
MYSQL_PASSWORD=db_password

# MySQL available versions: 5.5, 5.6, 5.7, 8.0
MYSQL_VERSION=5.7

# PHP settings
PHP_TIMEZONE=Europe/Vilnius
PHP_MEMORY_LIMIT=2048M

# Open ports
PORT_MYSQL=3380
PORT_NGINX=80
PORT_PHPMYADMIN=8080

# Xdebug
XDEBUG_CONFIG=1
XDEBUG_REMOTE_ENABLE=1
XDEBUG_REMOTE_AUTOSTART=1
XDEBUG_REMOTE_PORT=9000

Also I have these permissions in /var/www :

total 32
drwxr-xr-x 1 root root 4096 Dec 27 13:36 .
drwxr-xr-x 1 root root 4096 Dec 10 16:34 ..
drwxr-xr-x 1 root root 4096 Dec 27 13:36 .composer
drwxr-xr-x 2 root root 4096 Dec 27 13:36 .ssh
drwxr-xr-x 1 root root 4096 Dec 27 13:34 html
drwxr-xr-x 3 root root 4096 Dec 27 13:36 project
www-data@ebd147552d65:~$```

PHP - Configure OPcache for Maximum Performance

The default OPcache configuration is not suited for Symfony applications, so it's recommended to change these settings as follows:

; php.ini
; maximum memory that OPcache can use to store compiled PHP files
opcache.memory_consumption=256

; maximum number of files that can be stored in the cache
opcache.max_accelerated_files=20000

wkhtmltopdf throws "QSslSocket: cannot resolve CRYPTO_num_locks"

We need to fix it. Quick fix install this one libssl1.0-dev

file config/php/Dockerfile
content
RUN apt-get update && \ apt-get install --no-install-recommends --no-install-suggests -y gnupg1 \ openssl \ git \ unzip \ libzip-dev \ nano \ libpng-dev \ libmagickwand-dev \ curl \ xauth \ xvfb \ openssh-client \ less \ inkscape \ cron \ libmcrypt-dev \ libssl1.0-dev

Prepare blackfire integration

docker-compose.yml

version: '3'

services:
  blackfire:
    image: blackfire/blackfire
    ports: ["8707"]
    environment:
      # Exposes BLACKFIRE_SERVER_* environment variables from the host
      - BLACKFIRE_CLIENT_ID
      - BLACKFIRE_CLIENT_TOKEN
      - BLACKFIRE_SERVER_ID
      - BLACKFIRE_SERVER_TOKEN

PHP installation

RUN curl -sS https://packages.blackfire.io/gpg.key | apt-key add - && \
    echo "deb http://packages.blackfire.io/debian any main" | tee /etc/apt/sources.list.d/blackfire.list && \
    apt-get update && apt-get install -y blackfire-agent blackfire-php

.env configuration

# Blackfire
BLACKFIRE_SERVER_ID=
BLACKFIRE_SERVER_TOKEN=
BLACKFIRE_CLIENT_ID=
BLACKFIRE_CLIENT_TOKEN=

PHP - Configure the PHP realpath Cache

When a relative path is transformed into its real and absolute path, PHP caches the result to improve performance. Applications that open many PHP files, such as Symfony projects, should use at least these values:

; php.ini
; maximum memory allocated to store the results
realpath_cache_size=4096K

; save the results for 10 minutes (600 seconds)
realpath_cache_ttl=600

PHP disables the realpath cache when the open_basedir config option is enabled.

MySQL 5.6 wait_timeout issue

Unknown suffix 'c' used for variable 'wait_timeout' (value '28800cle')

2021-04-26 15:32:36+03:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.6.51-1debian9 started.
2021-04-26 15:32:36+03:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config
command was: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci --default-authentication-plugin=mysql_native_password --verbose --help --log-bin-index=/tmp/tmp.yY5u6TV6E9
Unknown suffix 'c' used for variable 'wait_timeout' (value '28800cle')
2021-04-26 15:32:36 0 [Warning] option 'wait_timeout': unsigned value 0 adjusted to 1
2021-04-26 15:32:36 0 [ERROR] mysqld: Error while setting value '28800cle' to 'wait_timeout'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.