I'm just working on a laravel project which runs on docker using sail.For a feature i need to create functionality which can create thumbnails for pdf's.I figured out it is possible to done using php Imagick class/library.But unfortunately I'm struggling to install it on the project.Anyone knows how to install it using docker?Really appreciate.
This is the Dockerfile.
LABEL maintainer="Taylor Otwell"
ARG WWWGROUP
ARG NODE_VERSION=16
WORKDIR /var/www/html
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update \
&& apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 \
&& mkdir -p ~/.gnupg \
&& chmod 600 ~/.gnupg \
&& echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E5267A6C \
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C300EE8C \
&& echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu hirsute main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
&& apt-get update \
&& apt-get install -y php8.0-cli php8.0-dev \
php8.0-pgsql php8.0-sqlite3 php8.0-gd \
php8.0-curl php8.0-memcached \
php8.0-imap php8.0-mysql php8.0-mbstring \
php8.0-xml php8.0-zip php8.0-bcmath php8.0-soap \
php8.0-intl php8.0-readline php8.0-pcov \
php8.0-msgpack php8.0-igbinary php8.0-ldap \
php8.0-redis php8.0-swoole php8.0-xdebug \
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& curl -sL https://deb.nodesource.com/setup_$NODE_VERSION.x | bash - \
&& apt-get install -y nodejs \
&& npm install -g npm \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
&& apt-get update \
&& apt-get install -y yarn \
&& apt-get install -y mysql-client \
&& apt-get install -y postgresql-client \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN update-alternatives --set php /usr/bin/php8.0
RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.0
RUN groupadd --force -g $WWWGROUP sail
RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail
COPY start-container /usr/local/bin/start-container
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY php.ini /etc/php/8.0/cli/conf.d/99-sail.ini
RUN chmod +x /usr/local/bin/start-container
EXPOSE 8000
ENTRYPOINT ["start-container"]
The easiest way is to use mlocati/docker-php-extension-installer like this:
FROM php:8.0
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && \
install-php-extensions imagick
Related
I try to install supervisor on my local docker container where I run php8.1 and laravel 9.
But I have following error:
'PermissionError: [Errno 13] Permission denied: '/var/log/supervisor/supervisord.log'
This is my config:
supervisor.conf
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/artisan queue:work
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/html/storage/logs/worker.log
stopwaitsecs=3600
stdout_logfile_maxbytes=5MB
php dockerfile:
FROM php:8.1.13-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
nano \
libxslt1.1 \
libxslt1-dev \
unzip \
git \
gnupg \
libpq-dev \
libzip-dev \
iputils-ping \
supervisor \
&& docker-php-ext-install zip \
gd \
mysqli pdo pdo_mysql \
&& docker-php-ext-enable pdo_mysql \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-configure intl \
RUN echo "memory_limit='512M'" >> /usr/local/etc/php/conf.d/php-extra.ini;
ENV PHP_IDE_CONFIG "serverName=new_app"
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer --version=2.3.8 && chmod +x /usr/bin/composer
# Set timezone
RUN rm /etc/localtime \
&& ln -s /usr/share/zoneinfo/Europe/Warsaw /etc/localtime \
&& "date" \
&& printf '[PHP]\ndate.timezone = "Europe/Warsaw"\n' > /usr/local/etc/php/conf.d/tzone.ini \
RUN usermod -aG docker $USER
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
WORKDIR /var/www/html
How can I fix it?
Regards.
1.
i saw these in your dockerfile, your file does not match,
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
i suggest to change to below:
COPY supervisord.conf /etc/supervisor/supervisord.conf
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
2.
Add this to your dockerfile, to replace the original line, and try again. Good luck
RUN usermod -aG docker $USER &&\
mkdir -p /var/www/html/storage/logs &&\
touch /var/www/html/storage/logs/worker.log
I am facing an issue where I am trying to run a docker container to practice php on local. When I hit the index php page in the browser after spinning up the container, it does not report error for me when there is an error. It just shows a white screen.
My docker file
FROM ubuntu:18.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update \
&& apt-get install -y tcl locales \
&& locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
RUN apt-get update \
&& apt-get install -y nginx curl zip unzip git software-properties-common supervisor \
&& add-apt-repository -y ppa:ondrej/php \
&& apt-get update \
&& apt-get install -y php7.4-fpm php7.4-cli php7.4-gd php7.4-mysql \
php7.4-imap php7.4-imagick php7.4-opcache php7.4-mbstring php7.4-xml php7.4-zip php7.4-intl php7.4-xmlrpc php7.4-curl \
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& mkdir /run/php \
&& apt-get remove -y --purge software-properties-common \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& echo "daemon off;" >> /etc/nginx/nginx.conf
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log
COPY default /etc/nginx/sites-available/default
COPY php-fpm.conf /etc/php/7.4/fpm/php-fpm.conf
EXPOSE 88
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD ["/usr/bin/supervisord"]
Now to report the error please assist in what could be done to fix it?
When running docker-compose up I am getting the following error:
Service 'web-app' failed to build: The command '/bin/sh -c set -xe && buildDeps=" $PHP_EXTRA_BUILD_DEPS libcurl4-openssl-dev libedit-dev libsqlite3-dev libssl-dev libxml2-dev xz-utils " && apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* && curl -fSL "http://php.net/get/$PHP_FILENAME/from/this/mirror" -o "$PHP_FILENAME" && echo "$PHP_SHA256 *$PHP_FILENAME" | sha256sum -c - && curl -fSL "http://php.net/get/$PHP_FILENAME.asc/from/this/mirror" -o "$PHP_FILENAME.asc" && export GNUPGHOME="$(mktemp -d)" && for key in $GPG_KEYS; do gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; done && gpg --batch --verify "$PHP_FILENAME.asc" "$PHP_FILENAME" && rm -r "$GNUPGHOME" "$PHP_FILENAME.asc" && mkdir -p /usr/src/php && tar -xf "$PHP_FILENAME" -C /usr/src/php --strip-components=1 && rm "$PHP_FILENAME" && cd /usr/src/php && ./configure --with-config-file-path="$PHP_INI_DIR" --with-config-file-scan-dir="$PHP_INI_DIR/conf.d" $PHP_EXTRA_CONFIGURE_ARGS --disable-cgi --enable-mysqlnd --enable-mbstring --with-curl --with-libedit --with-openssl --with-zlib && make -j"$(nproc)" && make install && { find /usr/local/bin /usr/local/sbin -type f -executable -exec strip --strip-all '{}' + || true; } && make clean && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false -o APT::AutoRemove::SuggestsImportant=false $buildDeps' returned a non-zero code: 2
Any idea why and how to fix it please?
I'm trying to test some PHP code on PHP 5.3 with the GMP extension installed. Here's my Dockerfile:
FROM php:5.3
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7638D0442B90D010 AA8E81B4331F7F50 9D6D8F6BC857C906 \
&& apt-get update \
&& apt-get -y install libgmp-dev \
&& docker-php-ext-install gmp
When I try to build that I get an error about how docker-php-ext-install doesn't exist.
Here's my second attempt:
FROM php:5.3
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7638D0442B90D010 AA8E81B4331F7F50 9D6D8F6BC857C906 \
&& apt-get update \
&& apt-get -y install php5-gmp
That builds without issue but apparently that doesn't actually result in PHP having the GMP extension. I thought maybe I'd need to add extension=gmp.so to the php.ini file but it's not immediately clear to me where that file lives. php -i | grep ini returns, among other things, this:
Configuration File (php.ini) Path => /usr/local/lib
But there's no php.ini file in that directory. I tried to create one but still no luck.
Per chance there's a PHP 5.3 image floating around that already has the GMP extension installed?
I was able to do it thusly:
FROM php:5.3
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7638D0442B90D010 AA8E81B4331F7F50 9D6D8F6BC857C906 \
&& apt-get update \
&& apt-get install -y libgmp-dev wget \
&& ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h \
&& cd /tmp \
&& wget --no-check-certificate https://museum.php.net/php5/php-5.3.29.tar.xz \
&& tar xvf php-5.3.29.tar.xz \
&& cd php-5.3.29/ext/gmp \
&& phpize \
&& ./configure \
&& make \
&& make install \
&& echo extension=gmp.so > /usr/local/lib/php.ini
Installing PHP extensions works about like this:
FROM php:5.3
RUN apt-key adv --keyserver keyserver.ubuntu.com \
--recv-keys 7638D0442B90D010 AA8E81B4331F7F50 9D6D8F6BC857C906 \
&& apt-get update && apt-get -y install php5-gmp libgmp \
&& echo "extension=gmp.so" > /etc/php5/apache2/conf.d/gmp.ini \
&& /etc/init.d/apache2 reload
But the PHP manual reads:
In order to have these functions available, PHP must be compiled with GMP support by using the --with-gmp option.
So the PHP in the Dockerfile needs to be compiled with the --with-gmp option and libgmp-dev.
I use php:8.0-fpm on docker and this worked for me. I hope this work for you too.
RUN apt-get update && apt-get install -y gnupg gnupg2 gnupg1 \
&& apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7638D0442B90D010 AA8E81B4331F7F50 9D6D8F6BC857C906 \
&& apt-get install -y libgmp-dev --fix-missing \
&& docker-php-ext-install gmp
and if you faced some issue about libreadline8 you can do like bellow.
RUN apt-get install -y libreadline8 --fix-missing
RUN apt-get update && apt-get install -y gnupg gnupg2 gnupg1 --fix-missing
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7638D0442B90D010 AA8E81B4331F7F50 9D6D8F6BC857C906
RUN apt-get install -y libgmp-dev --fix-missing
RUN docker-php-ext-install gmp
I am trying to use wkhtmltopdf in a container with Docker and Symfony.
The installation is done well, but the result is very different from the reality, so I think some libraries must be missing in the system, but I don't know which one.
I've been checking other questions here and in google, but they don't help.
FROM phpdockerio/php71-fpm:latest
# Fix debconf warnings upon build
ARG DEBIAN_FRONTEND=noninteractive
# Install selected extensions and other stuff
RUN apt-get update \
&& apt-get -y --no-install-recommends install cron \
php7.1-mysql \
php-redis \
php7.1-bcmath \
php7.1-gd \
php-imagick \
php7.1-intl \
cron \
python \
xz-utils \
libxrender1 \
libfontconfig1 \
zlib1g \
fontconfig \
libfreetype6 \
libx11-6 \
libxext6 \
wkhtmltopdf
RUN curl --insecure https://getcomposer.org/composer.phar -o /usr/bin/composer && chmod +x /usr/bin/composer
RUN cd /tmp \
&& curl "https://downloads.wkhtmltopdf.org/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz" -L -o "wkhtmltopdf.tar.xz" \
&& tar Jxvf wkhtmltopdf.tar.xz \
&& rm wkhtmltopdf.tar.xz \
&& mv wkhtmltox/include/* /usr/local/include/ \
&& mv wkhtmltox/lib/* /usr/local/lib/ \
&& mv wkhtmltox/bin/* /usr/local/bin/ \
&& mv wkhtmltox/share/* /usr/local/share/
RUN apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
CMD php-fpm -F
This is the result in the container(docker)
And this is the result on my machine (without docker), as it should be.
Any idea what might be happening?