i have the following simple dockerfile to add php from alpine,
FROM php:7.2-fpm-alpine
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Install extensions
RUN docker-php-ext-install mbstring tokenizer mysqli pdo_mysql
COPY ./app /app
WORKDIR /app
RUN composer install
and while running composer install it complains with this message - The requested PHP extension ext-http * is missing from your system. Install or enable PHP's http extension.
i tried to see if i can install it using 'docker-php-ext-install' but according to here the extension is not included.
also tried to add RUN apk add php-http, i also got the following error message
PS: it works locally on my local linux machine after installing the extension using sudo apt install php-http
First, you could add a apk update before adding packages. However the php_http package does not exist in alpine so you need to compile the pecl module.
Using the following question as an inspiration, I found adding this to your Dockerfile works well:
RUN apk add --update --virtual .build-deps autoconf g++ make zlib-dev curl-dev libidn2-dev libevent-dev icu-dev libidn-dev
RUN docker-php-ext-install mbstring tokenizer mysqli pdo_mysql json hash iconv
RUN pecl install raphf propro
RUN docker-php-ext-enable raphf propro
RUN pecl install pecl_http
RUN echo -e "extension=raphf.so\nextension=propro.so\nextension=iconv.so\nextension=http.so" > /usr/local/etc/php/conf.d/docker-php-ext-http.ini
RUN rm -rf /usr/local/etc/php/conf.d/docker-php-ext-raphf.ini
RUN rm -rf /usr/local/etc/php/conf.d/docker-php-ext-propro.ini
RUN rm -rf /tmp/*
Related
This never gets installed on my Github Actions even though I added intl in the end.
FROM composer:1.9.0
LABEL repository="https://github.com/ubient/laravel-vapor-action"
LABEL homepage="https://github.com/ubient/laravel-vapor-action"
LABEL maintainer="Claudio Dekker <claudio#ubient.net>"
# Install required extenstions for laravel
# https://laravel.com/docs/6.x#server-requirements
RUN apk add libxml2-dev libpng-dev && \
docker-php-ext-install bcmath xml tokenizer mbstring gd intl
# Install Vapor + Prestissimo (parallel/quicker composer install)
RUN set -xe && \
composer global require hirak/prestissimo && \
composer global require laravel/vapor-cli && \
composer clear-cache
# Install Node.js (needed for Vapor's NPM Build)
RUN apk add --update nodejs npm
# Prepare out Entrypoint (used to run Vapor commands)
COPY vapor-entrypoint /usr/local/bin/vapor-entrypoint
ENTRYPOINT ["/usr/local/bin/vapor-entrypoint"]
This fixed it
# Install INTL
RUN apk add icu-dev
RUN docker-php-ext-configure intl && docker-php-ext-install intl
https://github.com/aligajani/laravel-vapor-action/
Running Laravel on an appache server.
Upon building the image with docker-compose up --build with the following Dockerfile
FROM php:7.3-apache-stretch
RUN apt-get update -y && apt-get install -y libpng-dev
RUN docker-php-ext-install pdo pdo_mysql gd
FROM composer:1.9.0 as build
WORKDIR /app
COPY . /app
RUN composer global require hirak/prestissimo && composer install
I am getting the error message:
phpoffice/phpspreadsheet 1.13.0 requires ext-gd * -> the requested PHP extension gd is missing from your system.
This happens when the composer install command runs.
As you can see up, I am actually installing gd from php, so it should not give me this error message.
Do you have any idea how I can solve it?
Thanks!
It's happen, because you are using multistage building and your composer second stage have nothing to do with previous build using PHP container. Primary use case with multistaging is to produce some useful artefacts which can be used later.
So what I suggest is to copy composer file from composer image, then place it somewhere in your php container.
I will give you my solution which is working perfectly for me with laravel/symfony etc.
FROM php:7.4.4-fpm
# We copy composer from it's original image to our php container to use it later.
COPY --from=composer:1.9 /usr/bin/composer /usr/bin/composer
WORKDIR /var/www
ARG USER_ID
RUN useradd -s /bin/bash -d /home/user/ -m -G sudo,www-data user -u $USER_ID
RUN apt update && apt install -y zip unzip wget zlib1g-dev libicu-dev
RUN docker-php-ext-install pdo_mysql intl opcache gd
USER user
RUN wget https://get.symfony.com/cli/installer -O - | bash
ENV PATH="/home/user/.symfony/bin:${PATH}"
COPY php.ini /usr/local/etc/php
# You can also run here composer install, depends on your use case
You can change your docker image. For example try this:
FROM richarvey/nginx-php-fpm
WORKDIR /app
RUN php ./artisan config:cache && composer install
Can anyone help me with this problem.
When i try to create a docker image from a dockerfile for laravel application i get this error:
checking for oniguruma... no
configure: error: Package requirements (oniguruma) were not met:
No package 'oniguruma' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables ONIG_CFLAGS
and ONIG_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
The command '/bin/sh -c docker-php-ext-install pdo mbstring' returned a non-zero code: 1
Here is my Dockerfile:
FROM php:7
RUN apt-get update -y && apt-get install -y openssl zip unzip git
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN docker-php-ext-install pdo mbstring
WORKDIR /app
COPY app /app # this copies all the app files to a folder called `app`
RUN composer install
CMD php artisan serve --host=0.0.0.0 --port=8000
EXPOSE 8000
and the docker command to build the Dockerfile
sudo docker build -t test .
What #kalatabe said is correct. But in case you absolutely wanted to make sure mbstring gets installed, you can also add libonig-dev to your apt-get install
Just remove mbstring from the docker-php-ext-install instruction.
The error is caused by a dependency problem - the mbstring extension requires the oniguruma library to make multibyte regular expression functions work. From the installation guide:
Oniguruma is necessary for the regular expression functions with multibyte character support. Oniguruma is bundled with mbstring. As of PHP 5.4.0, if Oniguruma is already installed on the system, --with-onig[=DIR] can be specified to use the installed library.
However, in the image that you're using, the extension is already installed and configured, so you don't need to do anything else:
$> docker run --rm -it php:7 php -r "var_dump(mb_ereg_match('^99.*', '123456'));"
bool(false)
$> docker run --rm -it php:7 php -r "var_dump(mb_ereg_match('^12.*', '123456'));"
bool(true)
If your are using a distro with yum package manager. Execute this command:
sudo yum install -y oniguruma-devel
for phpbrew user
You can solve this error by removing the mbstring variant from the installation command using -mbstring parameter.
Example:
phpbrew install php-7.4 +default -mbstring
For ALPINE-based images e.g. FROM php:8.0.24-fpm-alpine3.16
you have to add the package oniguruma-dev like:
FROM php:8.0.24-fpm-alpine3.16
...
RUN apk update && apk add oniguruma-dev
...
RUN docker-php-ext-install -j$(nproc) mbstring
...
As #katalabe & #kgx already mentioned:
mbstring requires any kind of oniguruma installed.
For Debian-based images please see #kgx answer above: https://stackoverflow.com/a/59373581/6852290
I have a simple docker file, as follows:
FROM php:7.2-apache
COPY src/ /var/www/html/
Normally to install drivers for Mongo or MySQL connectivity I would do so by adding something like the below to the dockerfile:
docker-php-ext-install mongo
On this occasion I want to connect my php application to a SQL Server database, and I understand the best way to do this for php 7.x is by using the PDO driver, however I am unfamiliar with how to do configure this in the dockerfile.
I've tried doing a pecl install, like adding:
RUN pecl install sqlsrv pdo_sqlsrv
However this fails with a combination of errors that do not seem to point me in the right direction.
I'm just looking for a simple way to get this done in a dockerfile or by using docker run.
For added info, here's the error I'm getting:
/tmp/pear/temp/sqlsrv/shared/xplat.h:30:17: fatal error: sql.h: No such file or directory
#include <sql.h>
^
compilation terminated.
Makefile:194: recipe for target 'conn.lo' failed
make: *** [conn.lo] Error 1
ERROR: `make' failed
The command '/bin/sh -c pecl install sqlsrv pdo_sqlsrv && docker-php-ext-enable pdo_sqlsrv' returned a non-zero code: 1
Thanks all
I have created a docker file for this exact purpose:
FROM php:7.3-apache
ENV ACCEPT_EULA=Y
RUN apt-get update && apt-get install -y gnupg2
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get -y --no-install-recommends install msodbcsql17 unixodbc-dev
RUN pecl install sqlsrv
RUN pecl install pdo_sqlsrv
RUN docker-php-ext-enable sqlsrv pdo_sqlsrv
COPY . /var/www/html/
Enjoy!
Did you get an answer to this? I got it working with the following steps. (The unixodbc-dev package should get you past the pecl install.)
in the Docker file:
RUN apt-get -y install unixodbc-dev
RUN pecl install sqlsrv pdo_sqlsrv
And then you have to add some changes to php.ini to enable sqlserver.
get a local copy of php.ini and add these lines:
extension=pdo_sqlsrv.so
extension=sqlsrv.so
Then copy your local php.ini into the docker image (my file is in a local "config" folder).
in the Docker file:
COPY config/php.ini /usr/local/etc/php/
My docker config:
###############
# MSSQL support
###############
RUN apt-get update \
&& apt-get install -y gpg unixodbc unixodbc-dev \
&& docker-php-ext-install pdo pdo_mysql \
&& pecl install sqlsrv pdo_sqlsrv
# ------------ Install MS SQL client deps ------------ #
# adding custom MS repository
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list
# install SQL Server drivers and tools
RUN apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql17
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
RUN /bin/bash -c "source ~/.bashrc"
# Debian 9 msodbcsql : https://packages.microsoft.com/debian/9/prod/pool/main/m/msodbcsql17/
RUN wget https://packages.microsoft.com/debian/9/prod/pool/main/m/msodbcsql17/msodbcsql17_17.4.2.1-1_amd64.deb
RUN ACCEPT_EULA=Y dpkg -i msodbcsql17_17.4.2.1-1_amd64.deb
RUN apt-get -y install locales
RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
RUN locale-gen
RUN echo "extension=sqlsrv.so" >> /usr/local/etc/php/conf.d/docker-php-ext-sqlsrv.ini
RUN echo "extension=pdo_sqlsrv.so" >> /usr/local/etc/php/conf.d/docker-php-ext-pdo-sqlsrv.ini
# -------------- END MSSQL -------------------------------- #
FROM php:7.4.0-apache
ENV ACCEPT_EULA=Y
RUN apt-get update && apt-get install -y gnupg2
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-relea`enter code here`se.list
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get -y --no-install-recommends install msodbcsql17 unixodbc-dev
RUN pecl install sqlsrv
RUN pecl install pdo_sqlsrv
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-enable sqlsrv pdo_sqlsrv pdo pdo_mysql
COPY index.php /var/www/html/
I want to add Zend Guard Loader support on my php instance.
http://www.zend.com/en/products/loader/downloads#Linux
Normally, I will download the package, and then add the following settings into php.ini
[Zend Guard Loader]
zend_extension="/usr/local/webserver/php/ext/ZendGuardLoader.so"
zend_loader.enable=1
zend_loader.disable_licensing=0
zend_loader.obfuscation_level_support=3
zend_loader.license_path="/var/developer.zl"
But, now I'm running the instance within docker.
docker run --name php_instance php:5-fpm
And I tried to get into the shell:
docker exec -it php_instance bash
But I cannot find the php.ini, how can I make it work?
Did you add a command in your Dockerfile to copy the php.ini file from local to docker container?
Similar to
FROM php:7.1-fpm
# Install system packages
RUN apt-get update && apt-get install -y \
openssl \
libssh2-1 \
libssh2-1-dev \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
RUN pecl install xdebug
# Enable php extensions
RUN docker-php-ext-install mysqli pdo_pgsql
RUN pecl install ssh2-1.1.2
# Copy custom php.ini file
ADD ./deployment/my.php.ini /usr/local/etc/php/