I'm just trying to get a simple docker dev environment setup, but docker is not installing php's mysql extension. I get a fatal error - Call to undefined function mysql_connect(). I've tried different php versions (5.4, 5.5, 5.6, 7.0) all with the same result. Any help would be appreciated.
docker-compose.yml
version: '2'
volumes:
database_data:
driver: local
services:
nginx:
image: nginx:latest
ports:
- 8080:80
volumes:
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
volumes_from:
- php
php:
build: ./docker/php/
expose:
- 9000
volumes:
- .:/var/www/html
testing:
build: ./docker/php/
volumes_from:
- php
mysql:
image: mysql:latest
expose:
- 3306
volumes:
- database_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: project
MYSQL_USER: project
MYSQL_PASSWORD: project
Dockerfile
FROM php:7.0-fpm
# Install pdo_mysql
RUN apt-get update \
&& echo 'deb http://packages.dotdeb.org jessie all' >> /etc/apt/sources.list \
&& echo 'deb-src http://packages.dotdeb.org jessie all' >> /etc/apt/sources.list \
&& apt-get install -y wget \
&& wget https://www.dotdeb.org/dotdeb.gpg \
&& apt-key add dotdeb.gpg \
&& apt-get update \
&& apt-get install -y php7.0-mysql \
&& docker-php-ext-install pdo_mysql mysqli mysql
If you install this php extension works (inside dockerfile)
docker-php-ext-install mysqli
inside container:
docker-php-ext-install mysqli
apache2ctl restart
I looked at the WP Docker repo and used their php Dockerfile and it worked.
# install the PHP extensions we need
RUN apt-get update && apt-get install -y libpng12-dev libjpeg-dev && rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \
&& docker-php-ext-install gd
RUN docker-php-ext-install mysqli
Related
I have a PHP-based Docker container with Composer and Symfony installed inside of it. But each time I start that container, a message from Symfony appears, proposing to download & install the last version (and to activate TLS), which I do (for both). So I think the upgrade doesn't persist, how can I solve this ? (thank you in advance)
Thank you for your answers, everyone. The docker-composer.yaml and php/Dockerfile are made from a French tutorial video, slightly modified due to improvements noted in the Youtube comment section: The video is called "Un environnement de développement Symfony 5 avec Docker et Docker-compose" from Yoandev Co. Here is the docker-compose.yaml :
version: "3.8"
services:
db:
image: mariadb
container_name: db_SF_tuto_2
restart: always
volumes:
- db-data2:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: admin
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
networks:
- dev2
phpmyadmin:
image: phpmyadmin
container_name: phpmyadmin_SF_tuto_2
restart: always
depends_on:
- db
ports:
- 8090:80
environment:
PMA_HOST: db
networks:
- dev2
maildev:
image: maildev/maildev
container_name: maildev_SF_tuto_2
command: bin/maildev --web 80 --smtp 25 --hide-extensions STARTTLS
ports:
- "8091:80"
restart: always
networks:
- dev2
www:
build: php
container_name: www_SF_tuto_2
ports:
- "8742:8000"
volumes:
- ./php/vhosts:/etc/apache2/sites-enabled
- ./:/var/www
restart: always
networks:
- dev2
networks:
dev2:
volumes:
db-data2:
… and php/Dockerfile :
FROM php:7.4-apache
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf \
\
&& apt-get update \
&& apt-get install -y --no-install-recommends \
locales apt-utils git libicu-dev g++ libpng-dev libxml2-dev libzip-dev libonig-dev libxslt-dev unzip \
\
&& echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
&& echo "fr_FR.UTF-8 UTF-8" >> /etc/locale.gen \
&& locale-gen \
\
&& curl -sS https://getcomposer.org/installer | php -- \
&& mv composer.phar /usr/local/bin/composer \
\
&& curl -sS https://get.symfony.com/cli/installer | bash \
&& mv /root/.symfony/bin/symfony /usr/local/bin \
\
&& docker-php-ext-configure \
intl \
&& docker-php-ext-install \
pdo_mysql gd opcache intl zip calendar xsl \
\
&& pecl install apcu && docker-php-ext-enable apcu
WORKDIR /var/www/
As you have discovered, container storage is temporary and any changes done in it will be discarded when the container is removed. Note that you can stop a running container and the changes will still be there the next time you launch it, but docker-compose down does remove it, so every time you boot up your symfony binary is being reloaded from the image.
If you want for the updates to persist you'll have to create a volume.
However, since your current installation directory already contains binaries from your base image I'd suggest installing to a different directory and mount that.
In your Dockerfile, change the installation target. Since its a new directory you need to add it to the current $PATH so the tools can be executed.
FROM php:7.4-apache
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf \
\
&& apt-get update \
&& apt-get install -y --no-install-recommends \
locales apt-utils git libicu-dev g++ libpng-dev libxml2-dev libzip-dev libonig-dev libxslt-dev unzip \
&& echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
&& echo "fr_FR.UTF-8 UTF-8" >> /etc/locale.gen \
&& locale-gen \
\
&& mkdir /opt/bin -p \
&& curl -sS https://getcomposer.org/installer | php -- --install-dir /opt/bin --filename composer \
&& curl -sS https://get.symfony.com/cli/installer | bash -s - --install-dir /opt/bin \
\
&& docker-php-ext-configure \
intl \
&& docker-php-ext-install \
pdo_mysql gd opcache intl zip calendar xsl \
\
&& pecl install apcu && docker-php-ext-enable apcu
ENV PATH /opt/bin:$PATH
WORKDIR /var/www/
Now specify where to map the volume in the docker-compose.yml file:
www:
# ...
volumes:
# Specify the mount point.
# If you use short syntax here, a volume will be created every restart.
- phptools:/opt/bin
volumes:
# Declare a named volume so it can be remounted
phptools:
Run docker-compose build and docker-compose up.
I'm trying to install php-ast extension to my project. This is my Dockerfile:
FROM php:7.3.5-apache
RUN apt-get -yqq update \
&& apt-get -yqq install --no-install-recommends libzip-dev git
COPY ./php/php.ini /usr/local/etc/php/
COPY ./php/php_errors.log /var/log/php_errors.log
COPY ./apache/error.log /var/log/apache2/error.log
COPY ./apache/access.log /var/log/apache2/access.log
COPY . /var/www/html
COPY ./apache/vhost.conf /etc/apache2/sites-available/000-default.conf
COPY ./mysql/my.cnf /etc/mysql/conf.d/my.cnf
COPY --from=composer:1.6.5 /usr/bin/composer /usr/bin/composer
RUN apt-get update && apt-get install -y libmcrypt-dev libtool zip unzip \
&& docker-php-ext-install mysqli pdo_mysql \
&& pecl install mcrypt-1.0.2 ast-1.0.1 \
&& docker-php-ext-enable mcrypt ast \
&& a2enmod rewrite
RUN chown -R www-data:www-data /var/www/html
After I run this build and try to use ast, I get message that ast is not enabled. Would someone explain in plain English how should I install this extension on Docker php 7.3.5 or higher?
Update
This is my docker-compose.yml:
version: "3"
services:
appnew:
build: .
depends_on:
- mysqlnew
ports:
- 8080:80
networks:
- app-net
volumes:
- ..:/var/www/html
container_name: appnew
mysqlnew:
image: mysql:5.6
ports:
- 13317:3306
environment:
- MYSQL_DATABASE=XXXX_db
- MYSQL_ROOT_PASSWORD=XXXXXX
volumes:
- mysql57data:/var/lib/mysql
- ./mysql/my.cnf:/etc/mysql/conf.d/my.cnf
# - ./mysql/logs:/var/log/mysql/
networks:
- app-net
container_name: mysqlnew
networks:
app-net:
driver: "bridge"
volumes:
mysql57data:
driver: "local"
And this is my php.ini:
date.timezone = Europe/London
memory_limit = 128M
post_max_size = 500M
upload_max_filesize = 200M
error_log = /var/log/php_errors.log
error_reporting = -1
log_errors = 1
I used this Dockerfile
FROM php:7.3.5-apache
RUN apt-get -yqq update \
&& apt-get -yqq install --no-install-recommends libzip-dev git
RUN apt-get update && apt-get install -y libmcrypt-dev libtool zip unzip \
&& docker-php-ext-install mysqli pdo_mysql \
&& pecl install mcrypt-1.0.2 ast-1.0.1 \
&& docker-php-ext-enable mcrypt ast \
&& a2enmod rewrite
ran the build and wrote php -m and this is the output
[PHP Modules]
ast
Core
ctype
curl
date
dom
fileinfo
and you so many lines after that.
I am get a driver exception whilst trying to use pdo from inside my docker container. My image installs php7.1 along with enabling the pdo_mysql extension. The db credentials also correct, but I'm not sure why I am still this driver exception: PHP Fatal error: Uncaught PDOException: could not find driver in /var/www/app/test.php:9
Do I need to enable any other extensions?
Dockerfile
FROM ubuntu:xenial
# install dependencies
RUN apt-get update
RUN apt-get install -y software-properties-common python-software-properties
RUN apt-get install -y language-pack-en-base
RUN LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php
# setup php
RUN apt-get update && \
apt-get install -y nginx \
php7.1 \
php7.1-fpm \
php7.1-cli \
php7.1-common \
php7.1-json \
php7.1-opcache \
php7.1-mysql \
php7.1-mbstring \
php7.1-gd \
php7.1-imap \
php7.1-ldap \
php7.1-dev \
php7.1-intl \
php7.1-gd \
php7.1-curl \
php7.1-zip \
php7.1-xml \
curl
RUN phpenmod pdo_mysql
EXPOSE 8000
ENTRYPOINT ["/bin/sh", "./entrypoint.sh"]
docker-compose.yml
version: "3"
services:
app:
image: app:latest
command: start
ports:
- 8000:8000
links:
- db
environment:
DB_DATABASE: mydb
DB_HOST: db
DB_USER: app_user
DB_PASSWORD: abc123
db:
image: mysql:5.7
environment:
MYSQL_DATABASE: mydb
MYSQL_USER: app_user
MYSQL_PASSWORD: abc123
MYSQL_ROOT_PASSWORD: abc123
ports:
- 3306:3306
test.php
<?php
require_once('vendor/autoload.php');
use PDO;
$dns = ":host=".getenv('DB_HOST')."; dbname=".getenv('DB_DATABASE');
echo new PDO($dns, getenv('DB_USER'), getenv('DB_PASSWORD'));
I think your problem is on the $dns variable, you have to define the DB driver (mysql in your case).
$dns = "mysql:host=".getenv('DB_HOST')."; dbname=".getenv('DB_DATABASE');
I am trying to setup PHP 5.6.30 fp, but i got error.
Error the same as here (Docker) Getting error: docker-php-source: no such file or directory when building docker file
But i can`t understand how to resolve this.
my folder looks like
app
--docker
--workspace
inside workspace Dockerfile i paste all from https://github.com/docker-library/php/blob/eadc27f12cfec58e270f8e37cd1b4ae9abcbb4eb/5.6/fpm/Dockerfile
Step 15/22 : COPY docker-php-source /usr/local/bin/
ERROR: Service 'workspace' failed to build: lstat docker-php-source: no such file or directory
So what i must to do?
i did this command docker pull php before and it is not helped.
So i have this .yml file
version: '2'
services:
app:
build: ./docker/app
volumes:
- .:/var/www/html
command: "true"
workspace:
build: ./docker/workspace
volumes_from:
- app
links:
- php
- nginx
tty: true
depends_on:
- app
nginx:
build: ./docker/nginx
ports:
- 8080:80
links:
- php
volumes_from:
- app
php:
build: ./docker/php
expose:
- "9000"
volumes_from:
- app
mysql:
image: mysql:5.7
volumes_from:
- app
expose:
- "3306"
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: app
MYSQL_USER: root
MYSQL_PASSWORD: root
memcached:
image: memcached
ports:
- "11211:11211"
inside workspace/Dockerfile i have all strings from github image 6.6.30fpm
Then inside this folder i do
docker-compose build workspace
Before this in workspace i had another settings
FROM ubuntu:14.04
ENV DEBIAN_FRONTEND noninteractive
RUN \
sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.list && \
apt-get update && \
apt-get -y upgrade && \
apt-get install -y build-essential && \
apt-get install -y software-properties-common && \
apt-get install -y byobu curl git htop man unzip vim wget nano locate
RUN apt-get update --fix-missing --allow-unauthenticated
RUN apt-get install -y --allow-unauthenticated libmcrypt-dev libxml2-dev mysql-client
RUN apt-get update -y --allow-unauthenticated && apt-get upgrade -y --allow-unauthenticated && apt-get install -q -y php5 php5-dev php5-fpm php5-mysqlnd php5-mcrypt
RUN echo "extension=/usr/lib/php5/20121212/mcrypt.so" > /etc/php5/mods-available/mcrypt.ini \
&& ln -s /etc/php5/mods-available/mcrypt.ini /etc/php5/cli/conf.d/20-mcrypt.ini
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
WORKDIR /var/www/html
# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
and this works but i want to 5.6.30 instead of 5.5.9
Perhaps it is due to the fact that there is no permission to execute.
Try
chmod +x docker-php-*
UPD:
Just put all these files inside directory with your php 5.6 Dockerfile
If you want to use php 7.2 version, this link is for you
Anyway for other googlers. Just explore this repository and you will find that you want. :)
I am new to docker and I'm trying to set it up in order to run with Laravel 5.1. I am currently getting the following error
Call to undefined function Illuminate\Foundation\Bootstrap\mb_internal_encoding() in /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php:43
I believe this is because the mbstring php extention is not installed. I have tried to add php-mbstring to the Docker file but it doesn't seem to be working.
Here is my full Docker file
FROM php:5.6.30-fpm
RUN apt-get update && apt-get install -y libmcrypt-dev \
mysql-client libmagickwand-dev --no-install-recommends \
&& pecl install imagick \
&& docker-php-ext-install mcrypt pdo_mysql \
&& docker-php-ext-install php-mbstring
I am then running sudo docker compose up from the application folder. This does not seem to be resolving the error though. How do I know if the extensions are being installed properly?
EDIT: I have included the docker-compose.yml file below
version: '2'
services:
# The Application
app:
build:
context: ./
dockerfile: app.dockerfile
working_dir: /var/www
volumes:
- ./:/var/www
environment:
- "DB_PORT=3306"
- "DB_HOST=database"
# The Web Server
web:
build:
context: ./
dockerfile: web.dockerfile
working_dir: /var/www
volumes_from:
- app
ports:
- 8080:80
# The Database
database:
image: mysql:5.6
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_DATABASE=homestead"
- "MYSQL_USER=homestead"
- "MYSQL_PASSWORD=secret"
- "MYSQL_ROOT_PASSWORD=secret"
ports:
- "33061:3306"
volumes:
dbdata:
Remove the php- prefix and it should work fine. You can also run it on the previous docker-php-ext-install command:
docker-php-ext-install mcrypt pdo_mysql mbstring
on ubuntu php-mbstring has dependency with php-common and version specific mbstring like php7.1-mbstring that may cause the problem. You can check dependencies with this command below;
apt-cache depends php-mbstring