I am trying to install extenion in the docker PHP image. I have the following Dockerfile:
FROM php:7.2-apache
RUN apt-get update
RUN apt-get install -y build-essential cmake g++ libboost-dev libboost-system-dev \
libboost-filesystem-dev libexpat1-dev zlib1g-dev libxml2-dev \
libbz2-dev libpq-dev libproj-dev \
git sudo wget postgresql-server-dev-all python-pyosmium osmium-tool
RUN docker-php-ext-install dba
RUN docker-php-ext-install pgsql
RUN printf '<Directory "/srv/nominatim/Nominatim/build/website"> \n\
Options FollowSymLinks MultiViews \n\
AddType text/html .php \n\
DirectoryIndex search.php \n\
Require all granted \n\
</Directory> \n\
\n\
Alias /nominatim /srv/nominatim/Nominatim/build/website \n' > /etc/apache2/conf-available/nominatim.conf
RUN a2enconf nominatim
RUN service apache2 stop
RUN service apache2 start
WORKDIR /srv/nominatim
RUN wget https://nominatim.org/release/Nominatim-3.2.0.tar.bz2
RUN tar xf Nominatim-3.2.0.tar.bz2
RUN mv Nominatim-3.2.0 Nominatim
WORKDIR /srv/nominatim/Nominatim
RUN mkdir build
WORKDIR /srv/nominatim/Nominatim/build
RUN cmake ..
RUN make
RUN tee settings/local.php << $"EOF \n\
<?php \n\
#define('CONST_Website_BaseURL', '/nominatim/'); \n\
EOF"
The problem is that despite extensions are installed and their ini files are listed by phpinfo, the extension doesn't work:
Warning: require_once(DB.php): failed to open stream: No such file or directory in /srv/nominatim/Nominatim/lib/db.php on line 3
Fatal error: require_once(): Failed opening required 'DB.php' (include_path='.:/usr/local/lib/php') in /srv/nominatim/Nominatim/lib/db.php on line 3
It seems like the DB.php indeed does not exist at all (or I couldn't find them), despite that the extension seems to be installed - as the .so file is in its place as well.
EDIT: I've pasted the full Dockerfile above. I am actually trying to build the Nominatim image that will be composed with another image containing the PostgreSQL with the OSM data.
Related
I am trying to install some php extensions all day but an error I do not understand occurs. Basically if I remove the install docker-php-ext-enable line everything seems to work normally (except my app that depends on them).
Dockerfile
FROM php:8.0-apache
RUN apt-get update && \
apt-get install -y unzip libcurl4-openssl-dev zlib1g-dev libpng-dev libxml2-dev libzip-dev
RUN a2enmod rewrite
RUN docker-php-ext-enable bcmath gd mysqli soap zip xml ctype curl fileinfo json
COPY idoit-1.16.2.zip /temp/idoit-1.16.2.zip
RUN unzip /temp/idoit-1.16.2.zip -d /var/www
RUN rm /temp/idoit-1.16.2.zip
COPY apache-vhost.conf /etc/apache2/sites-available/000-default.conf
# RUN chown -R www-data:www-data /var/www
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
EXPOSE 80
Here is what I get when i run sudo docker build -t test .
Sending build context to Docker daemon 153.9MB
Step 1/23 : FROM php:8.0-apache
---> 1157b188bd87
Step 2/23 : RUN apt-get update && apt-get install -y unzip libcurl4-openssl-dev zlib1g-dev libpng-dev libxml2-dev libzip-dev
---> Using cache
---> aacd74715e3f
Step 3/23 : RUN a2enmod rewrite
---> Using cache
---> 1ab1cd3d1228
Step 4/23 : RUN docker-php-ext-enable fileinfo
---> Running in 7d8a84075a50
error: 'fileinfo' does not exist
usage: /usr/local/bin/docker-php-ext-enable [options] module-name [module-name ...]
ie: /usr/local/bin/docker-php-ext-enable gd mysqli
/usr/local/bin/docker-php-ext-enable pdo pdo_mysql
/usr/local/bin/docker-php-ext-enable --ini-name 0-apc.ini apcu apc
Possible values for module-name:
opcache.so sodium.so
Some of the above modules are already compiled into PHP; please check
the output of "php -i" to see which modules are already loaded.
Any ideas?
This question already has answers here:
ADD failed : No such file/Directory while building docker image
(3 answers)
Closed 2 years ago.
I got this error when building docker php image
Step 13/25 : ADD php.ini /usr/local/etc/php/php.ini
ERROR: Service 'phpt3' failed to build: ADD failed: stat
/var/lib/docker/tmp/docker-builder310748204/php.ini: no
such file or directory
Below is the docker file:
FROM php:7.3-fpm
# install the PHP extensions we need
RUN apt-get update \
&& apt-get install -y --no-install-recommends msmtp mailutils vim curl debconf subversion git apt-transport-https apt-utils \
build-essential locales acl mailutils wget nodejs \
gnupg gnupg1 gnupg2 \
zlib1g-dev zlib1g-dev libicu-dev g++ \
sudo
# Install GD
RUN apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install -j$(nproc) gd
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install gd
# MYSQLI
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
# Install ext-zip
RUN apt-get install -y unzip libzip-dev
RUN docker-php-ext-install zip
RUN docker-php-ext-configure intl
RUN docker-php-ext-install pdo_mysql json calendar intl
ADD php.ini /usr/local/etc/php/php.ini
COPY additionnal.ini /usr/local/etc/php/conf.d/
COPY php-fpm-pool.conf /usr/local/etc/php/pool.d/www.conf
RUN rm -rf /var/lib/apt/lists/* \
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
echo "fr_FR.UTF-8 UTF-8" >> /etc/locale.gen && \
locale-gen
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version
# set up sendmail config, see http://linux.die.net/man/5/ssmtp.conf for options
RUN echo "hostname=localhost.localdomain" > /etc/msmtp/msmtp.conf
RUN echo "mailhub=maildevt3" >> /etc/msmtp/msmtp.conf
# The above 'maildevt3' is the name you used for the link command
# in your docker-compose file or docker link command.
# Docker automatically adds that name in the hosts file
# of the container you're linking MailDev to.
# Set up php sendmail config
RUN echo "sendmail_path=sendmail -i -t" >> /usr/local/etc/php/conf.d/php-sendmail.ini
# Fully qualified domain name configuration for sendmail on localhost.
# Without this sendmail will not work.
# This must match the value for 'hostname' field that you set in ssmtp.conf.
RUN echo "localhost localhost.localdomain" >> /etc/hosts
WORKDIR /var/www/
EXPOSE 9000
CMD ["php-fpm"]
Can anyone help me to overcome this bug.
I'm doing this tutorial
https://passions.miary.dev/2019/08/30/docker-maildev-fr/
It looks like the image installer does not have the rights to write to the installation directory.
-> How to fix:
ADD failed : No such file/Directory while building docker image
If that doesn't work: test if the folder, which is shown in the error exists.
Give enough permissions to the directory with chmod -> https://wiki.ubuntuusers.de/chmod/
I am using a php7 in docker container to run a service based on phpdocx library. It needs tidy and some other extensions installed and active to work. I have installed php-tidy however I am getting following warning.
PHP Warning: PHP Startup: Unable to load dynamic library 'tidy' (tried: /usr/lib/php7/modules/tidy (Error loading shared library /usr/lib/php7/modules/tidy: No such file or directory), /usr/lib/php7/modules/tidy.so (Error relocating /usr/lib/php7/modules/tidy.so: _zval_ptr_dtor: symbol not found)) in Unknown on line 0
Dockerfile
FROM php:7.3.2-cli-alpine3.9
USER root
COPY . code
WORKDIR code
RUN apk update && apk add php-tidy && apk add php-zip && apk add php-curl && apk add php-sodium
# RUN sed -i s/;extension=tidy/extension=tidy/ -f /usr/local/etc/php/php.ini-development
# RUN sed -i s/;extension=tidy/extension=tidy/ -f /usr/local/etc/php/php.ini-production
COPY php.ini /usr/local/etc/php/php.ini-development
COPY php.ini /usr/local/etc/php/php.ini-production
COPY php.ini /usr/local/etc/php/php.ini
CMD php -S 0.0.0.0:8080
Output from docker shell
on running phpinfo()
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /usr/local/etc/php
Loaded Configuration File => /usr/local/etc/php/php.ini
Scan this dir for additional .ini files => /usr/local/etc/php/conf.d
Additional .ini files parsed => /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini
# vi /usr/local/etc/php/php.ini
extension=tidy
[Tidy]
; The path to a default tidy configuration file to use when using tidy
; http://php.net/tidy.default-config
;tidy.default_config = /usr/local/lib/php/default.tcfg
; Should tidy clean and repair output automatically?
; WARNING: Do not use this option if you are generating non-html content
; such as dynamic images
; http://php.net/tidy.clean-output
tidy.clean_output = Off
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
extension_dir = "/usr/lib/php7/modules/"
; On windows:
;extension_dir = "ext"
#ls /usr/lib/php7/modules/
curl.so sodium.so tidy.so zip.so
There are docker commands to install php libraries. So instead of using linux command eg: apk add php-tidy using docker-php-ext-install tidy solved my problem. Below is the docker file that works.
FROM php:7
ENV DEBIAN_FRONTEND noninteractive
USER root
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y apt-utils
RUN apt-get install -y libzip-dev
RUN apt-get install -y libtidy-dev
RUN apt-get install -y curl
RUN apt-get install -y libcurl3
RUN apt-get install -y libcurl3-dev
RUN docker-php-ext-install zip
RUN docker-php-ext-install curl
RUN docker-php-ext-install tidy
RUN docker-php-ext-enable zip
RUN docker-php-ext-enable curl
RUN docker-php-ext-enable tidy
COPY . code
WORKDIR code
EXPOSE 8080
CMD php -S 0.0.0.0:8080
On Debian Bullseye based Dockerfile:
RUN apt-get update && \
apt-get install -y libtidy-dev && \
rm -rf /var/lib/apt/lists/* && \
docker-php-ext-install tidy && \
docker-php-ext-enable tidy
I trying to get a php:apache server in a docker container with docker-compose to work. But after compose up I get following error message:
[client 172.21.0.1:49230] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.php,index.html) found, and server-generated directory index forbidden by Options directive
my dockerfile:
FROM php:7.1-apache
RUN apt-get update -y
RUN apt-get upgrade -y
RUN apt-get install -y \
adduser \
ca-certificates \
unzip \
curl \
git \
wget \
openssl
RUN docker-php-ext-install pdo_mysql
# Installiere benötigte PHP Erweiterungen
RUN apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
&& docker-php-ext-install -j$(nproc) iconv mcrypt \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
# Install bcmath
RUN docker-php-ext-install bcmath pcntl
# Install Phalcon-PHP
WORKDIR /phalcon/cphalcon
# https://github.com/phalcon/cphalcon/releases
ENV PHALCON_VERSION "v3.2.1"
RUN curl -L -o "phalcon-${PHALCON_VERSION}.tar.gz" "https://api.github.com/repos/phalcon/cphalcon/tarball/${PHALCON_VERSION}" \
&& tar -xvf "phalcon-${PHALCON_VERSION}.tar.gz" --strip 1 \
&& rm "phalcon-${PHALCON_VERSION}.tar.gz" \
&& cd /phalcon/cphalcon/build \
&& ./install
# Install Phalcon Devtools
WORKDIR /usr/local/lib/phalcon-devtools
# https://github.com/phalcon/phalcon-devtools/releases
ENV PHALCON_DEVTOOLS_VERSION "v3.2.0"
RUN curl -L -o "phalcon-devtools-${PHALCON_DEVTOOLS_VERSION}.tar.gz" "https://api.github.com/repos/phalcon/phalcon-devtools/tarball/${PHALCON_DEVTOOLS_VERSION}" \
&& tar -xvf "phalcon-devtools-${PHALCON_DEVTOOLS_VERSION}.tar.gz" --strip 1 \
&& rm "phalcon-devtools-${PHALCON_DEVTOOLS_VERSION}.tar.gz" \
&& ln -s /usr/local/lib/phalcon-devtools/phalcon.php /usr/bin/phalcon \
&& chmod +x /usr/bin/phalcon
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN chmod +x /usr/local/bin/composer
# Install Dockerize
ENV DOCKERIZE_VERSION v0.5.0
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
WORKDIR /usr/src/fileserver
COPY config/apache/apache2.conf /etc/apache2/apache2.conf
COPY config/apache/envvars /etc/apache2/envvars
COPY config/apache/site-default.conf /etc/apache2/sites-available/000-default.conf
COPY config/apache/project.conf /etc/apache2/project.conf
COPY config/php.ini /usr/local/etc/php/
COPY run.sh /run.sh
COPY start_safe_perms.sh /start_safe_perms.sh
RUN chmod 755 /*.sh
RUN a2enmod rewrite
RUN a2enmod headers
VOLUME ["/usr/src/fileserver"]
CMD ["/run.sh"]
docker-compose:
version: '3.1'
services:
fileserver:
build: fileServer/docker
container_name: fileServer
volumes:
- ./FileServer/:/usr/src/fileserver #/usr/src/app
ports:
- "5001:80"
I think the error comes from my site-default.config, which should normally overwrites the 000-default.conf
But I don´t know why the default directory is var/www/html. It should be /usr/src/fileserver/public/ (if i do docker exec at this container, it shows the fileserver folder with index.php)
site-default.conf
<VirtualHost *:5001>
DocumentRoot /usr/src/fileserver/public
<Directory /usr/src/fileserver/public/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /usr/src/fileserver/docker/logs/error.log
CustomLog /usr/src/fileserver/docker/logs/access.log combined
</VirtualHost>
Can someone help me? (please ask for more informations, if they needed)
Looks like you are exposing port 5001 from local machine to port 80 on the docker instance, but then you are defining your virtual host on port 5001. So your site-default.conf it probably should read:
<VirtualHost *:80>
Notice that the error is about /var/www/html/ (some Apache default directory) and not your own /usr/src/fileserver/public
I am trying to setup a Symfony project using docker but it always return errors related to permissions in "cache" directory.
I have tried everything and I can't seem to find a solution.
The problem is somehow the cache folder is always created with "root" owner even with my server and php-fpm user set as www-data. Maybe because of the php-cli user?
I have tried:
- setfacl : Don't work with docker
- chown / chmod to www-data: also didn't work. it might changes the owner correctly in the begining but them gives an error in other place.
docker-compose.yml
app:
build: .
command: "tail -f /dev/null" # keep the application container running
links:
- mysql
volumes:
- .:/var/www
nginx:
build: docker/nginx/
ports:
- 8090:80
links:
- php-fpm
volumes_from:
- app
php-fpm:
build: docker/fpm
ports:
- 9000:9000
volumes_from:
- app
mysql:
image: mysql:5.7
volumes:
- ./docker/data/mysql:/var/lib/mysql
My app Dockerfile:
FROM php:5.6-cli
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y \
git \
vim \
curl \
php5-json \
php5-intl \
php5-mcrypt \
php5-mysql \
php5-apcu \
php5-gd
ADD /docker/fpm/php.ini /usr/local/etc/php/
# install composer.
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
RUN usermod -u 1000 www-data
ADD . /var/www
WORKDIR /var/www
PHP-fpm Dockerfile
FROM php:5.6-fpm
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y \
php5-json \
php5-intl \
php5-mcrypt \
php5-mysql \
php5-apcu \
php5-gd
RUN apt-get install -y php5-xdebug
ADD xdebug.ini /usr/local/etc/php/conf.d/
ADD php.ini /usr/local/etc/php/
EXPOSE 9000
WORKDIR /var/www
CMD ["php-fpm"]
Nginx Dockerfile
FROM nginx:latest
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y git vim
ADD nginx.conf /etc/nginx/
ADD symfony.conf /etc/nginx/sites-available/
RUN mkdir -p /etc/nginx/sites-enabled
RUN ln -s /etc/nginx/sites-available/symfony.conf /etc/nginx/sites-enabled/
RUN usermod -u 1000 www-data
EXPOSE 80
EXPOSE 443
ENTRYPOINT ["nginx"]
I am out of ideas. Any suggestions?
Thank you.
I have an apache 2.2 setup with docker and at the end of the Dockerfile I have the following command:
ENTRYPOINT service apache2 start && sh /opt/fix_symfony_cache_and_logs_permissions.sh
and this in the fix_symfony_cache_and_logs_permissions script:
rm -rf /{route_to_app}/app/cache/* /{route_to_app}/app/logs/*
tailf /dev/null
It seems that your problem could be related to the fact that your php-fpm process is the one who should run with the right permissions.
EDIT: I just found out about this https://github.com/drgomesp/symfony-docker which I think would help you set it up correctly
I also had this problem. Nothing worked, chown, chmod, setfacl. Then ended up with the following solution. Warning, my solution has some security issues regarding the reading/writing. Use it on your own risk!
FROM php:5.6.29-apache
RUN apt-get update \
&& apt-get install -y git libssl-dev zlib1g-dev libicu-dev g++ \
&& docker-php-ext-install intl mbstring zip \
&& a2enmod rewrite
RUN pecl install mongo \
&& echo extension=mongo.so > /usr/local/etc/php/conf.d/mongo.ini \
&& docker-php-ext-enable mongo \
&& pecl install mongodb && \
docker-php-ext-enable mongodb
COPY apache2.conf /etc/apache2/apache2.conf
COPY . /var/www/html
WORKDIR /var/www/html
RUN rm -rf /var/www/html/var/cache/prod \
&& rm -rf /var/www/html/var/cache/dev
RUN chown -R www-data /var/www
RUN chmod -R 777 /var/www
USER www-data
RUN curl -sS https://getcomposer.org/installer | php
RUN php composer.phar install --no-interaction --optimize-autoloader
USER root
And apache2.conf file content is as follows.
User www-data
Group www-data
ErrorLog /proc/self/fd/2
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Listen 80
DocumentRoot /var/www/html/web
<Directory /var/www/html/web>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
DirectoryIndex disabled
DirectoryIndex app.php