webdevops / php-docker-boilerplate

:stew: PHP Docker Boilerplate for Symfony, Wordpress, Joomla or any other PHP Project (NGINX, Apache HTTPd, PHP-FPM, MySQL, Solr, Elasticsearch, Redis, FTP)
https://webdevops.io/projects/php-docker-boilerplate/
MIT License
562 stars 186 forks source link

How to use PostgreSQL instead of mysql ? #60

Closed nicolas-piquerez closed 7 years ago

nicolas-piquerez commented 7 years ago

Hello, Have you managed to use postgreSQL ?

I'm trying to replace mysql with postgresql, but I can't get symfony / laravel to connect.

I have the following error when trying to connect to a remote (aws) postgreSQL database : ErrorException in Connection.php line 770: could not find driver

In docker-compose i linked postgre links:

- mail

  #- mysql
  - pgsql

Removed comments from PostgreSQL config #######################################

PostgreSQL server

####################################### pgsql: build: context: docker/postgres/

dockerfile: Postgres-9.4.Dockerfile

  dockerfile: Postgres-9.5.Dockerfile

volumes_from:

- storage

ports:
  - 15432:5432
env_file:
  - etc/environment.yml
  - etc/environment.development.yml

It seems the php7 extension for postgreSQL is missing I tried to install it with "RUN /usr/local/bin/apt-install php7.0-pgsql" but can't find any php packages installed :/

kyrilg commented 7 years ago

Hello, I recently faced the same problem; Here is my Dockerfile.development

FROM webdevops/php-apache-dev:7.1

ENV PROVISION_CONTEXT "development"

COPY etc/ /opt/docker/etc/

RUN ln -sf /opt/docker/etc/cron/crontab /etc/cron.d/docker-boilerplate \

RUN chmod 0644 /opt/docker/etc/cron/crontab \ && echo >> /opt/docker/etc/cron/crontab \ && ln -sf /opt/docker/etc/php/development.ini /opt/docker/etc/php/php.ini

RUN apt-get update

RUN apt-get install -y libpq-dev \ && docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \ && docker-php-ext-install pdo_pgsql pgsql

RUN apt-get install -y zlib1g-dev libicu-dev g++ \ && docker-php-ext-configure intl \ && docker-php-ext-install intl

Configure volume/workdir

WORKDIR /app/

mblaschke commented 7 years ago

Don't run RUN apt-get update on a single run command, you will create an additional layer which you don't need :)

You can use RUN apt-install libpq-dev ... on our images, this will handle all stuff automatically :)

We've already discussed adding pgsql on our images and will add this too.

nicolas-piquerez commented 7 years ago

Thank you kyrilg. It works like a charm !!

As mblaschke suggested, i tried without the update, but libpq-dev could not be found. So I kept the update for now :)

Can I ask you how is your docker-compose ? I would like to simplify mine by removing the storage container and the docker volume, I don't need the separate app from storage, or at least I can't see the advantages in my case.

version: '2' services: app: build: context: . dockerfile: Dockerfile links:

kyrilg commented 7 years ago

@clenoma just replace apt-get install by apt-install and then you can remove apt-get update :) @mblaschke would answer better than me but he already told me that the storage was no longer necessary and should be removed

You can go at https://webdevops.io/slack/ to discuss about that