Skip to content

Instantly share code, notes, and snippets.

@kovagoz
Created September 2, 2016 05:03
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kovagoz/0d6a24405d974c06f77cd2533b63b3f8 to your computer and use it in GitHub Desktop.
Save kovagoz/0d6a24405d974c06f77cd2533b63b3f8 to your computer and use it in GitHub Desktop.
Alpine Linux with PHP 5.6 FPM and Mongo module
FROM php:5.6-fpm-alpine
RUN apk update && apk add autoconf openssl-dev g++ make && \
pecl install mongo && \
docker-php-ext-enable mongo && \
apk del --purge autoconf openssl-dev g++ make
@lucasvanlierop
Copy link

Thanks so much!, after trying 10+ other combinations this was the the first one that actually compiled properly on Alpine.

@mtrojanowski
Copy link

Thanks! That was exactly what I needed. I just changed the extension name to mongodb as I'm using it with php 7, and it works just fine.

@Fiser12
Copy link

Fiser12 commented Oct 1, 2018

Thanks! That was exactly what I needed. I just changed the extension name to mongodb as I'm using it with php 7, and it works just fine.

In php 7.2 with fpm and alpine I need add libssl1.0 for found. I have this code example with my correction

https://github.com/Fiser12/Symfony-Microservice-Dockerfile-Base/blob/3dd40aa012ef6b7952369c13081e385c29a11200/Dockerfile

@czarpino
Copy link

@Fiser12 Your link doesn't seem to be right. 😅

@omar331
Copy link

omar331 commented Aug 26, 2020

thank you @kovagoz

@babininja
Copy link

babininja commented Nov 13, 2022

I run the same code but got this error.

pecl/mongodb requires PHP (version >= 7.2.0, version <= 8.99.99), installed version is 5.6.40

can you help me solve this?

@mtrojanowski
Copy link

mtrojanowski commented Nov 14, 2022

@babininja If you use php 5.6. you should install the mongo extension. Exactly as in this example. The mongodb extension should be used only if you're on PHP >= 7.2. To switch to higher version of PHP change the first line of this Dockerfile to something like FROM php:8.1-fpm-alpine (use your desired version of PHP)

@babininja
Copy link

@mtrojanowski I am using php5.6-mongodb without docker and it works. but when i try to add it to docker file i can't. if i use php-mongo it gives me this error 'Class 'MongoDB\Driver\Manager' not found'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment