Skip to content

pyd/docker-symfony-fpm-postgresql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

Docker setup for symfony development in Linux with php-fpm, nginx and postgresql.


Prerequisites

Configure and enable docker user namespace so root files in containers can be edited by current user in host and vice versa.
See https://docs.docker.com/engine/security/userns-remap/
Create the /etc/docker/daemon.json file to enable namespace remapping for the current user

{
  "userns-remap": "my-username"
}

In the /etc/subuid file create a mapping between the unprivileged user in host and root user in containers:

  my-username:my-UID:1

In the /etc/subgid file create a mapping between the unprivileged group in host and root group in containers:

  my-username:my-GID:1

Install

1. clone the repo

$ cd /path/to/project
$ git clone --depth 1 https://github.com/pyd/docker-symfony-fpm-postgresql.git .

2. Configure

  • /path/to/project/docker/.env file: set GIT_USER_NAME and GIT_USER_EMAIL
  • /path/to/project/docker/php/conf.d/xdebug.ini: customize config, like mode, log, idekey...

3. run the containers

$ cd /path/to/project/docker
$ docker-compose up -d

4. set permissions on /path/to/project/pgadmin-data directory (see pgadmin app section bellow)

$ sudo chmod -R 777 /path/to/project/pgadmin-data

5. open a terminal inside the php container (connected as root in /var/www/html)

$ docker-compose exec php sh

6. create the symfony project

# composer create-project symfony/skeleton .
# git init
# git add .
# git commit -m "create symfony project"

symfony app URL: http://localhost:8080


pgadmin app URL: http://localhost:8181


permissions on /path/to/project/pgadmin-data

According to https://www.pgadmin.org/docs/pgadmin4/latest/container_deployment.html, this directory should be owned by 5050:5050 but this does not prevent an access denied on sessions/ subdirectory when trying to log in. Chmod 777 solved this.

DSN

Use variables defined in the /path/to/project/docker/.env file.
By default "host=db dbname=postgres user=postgres password=superuser_password" as DSN.
Note host=db. Internally, docker will replace 'db' with the IP of the php container.
Same DSN can be used in the symfony app and in pgadmin.

Test db connection

Comment code in /path/to/project/app/public/index.php and paste the code bellow.

if (!$connection = pg_connect ("host=db dbname=postgres user=postgres password=superuser_password")) {
  $error = error_get_last();
  echo "DB connection failed: ". $error['message']. "\n";
} else {
  echo "DB connection succeeded.\n";
}

Force docker to rebuild containers after modifications to /path/to/project/docker/.env file

Remove pyd_symfony_* images

$ docker-compose down --rmi 'local'

or force docker to rebuild

$ docker-compose up -d --build

About

Dockerize symfony dev env

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published