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');
Related
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 want to run my application in a docker container. I am able to run my PHP application in a docker container but I want to add mysql in my application and restore my sql dump in my database. And I want my application code to be cloned by dockerfile and httpd configuration with dockerfile itself.
here is my docker file
FROM centos:centos7
RUN yum -y update \
&& yum --setopt=tsflags=nodocs -y install \
gcc \
httpd \
mod_ssl \unzip \
&& rm -rf /var/cache/yum/* \
&& yum clean all
RUN rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
RUN rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
RUN yum remove php-cli php-common
RUN yum -y install php55w \
php55w-opcache \
php55w-xml \
php55w-mcrypt \
php55w-gd \
php55w-devel \
php55w-mysqlnd \
php55w-intl \
php55w-mbstring \
RUN yum -y install git
RUN git clone
https://USERNAME:PASSWORD#gitlab.com/xxxxxxxxxxx/Product/yyyyyyyyyyy.git
abc;
RUN rm -rf /var/cache/yum/*
RUN yum clean all
EXPOSE 80
#ADD ./abc/ /var/www/html/
COPY /abc/abclive/gitlab.abc/dev/ /var/www/html/
#WORKDIR /var/www/html/abc/abclive/gitlab.abc/dev/
ENV APACHE_DOCUMENT_ROOT /var/www/html/abc/abclive/gitlab.abc/dev/
WORKDIR /var/www/html/abc/abclive/gitlab.abc/dev/
CMD ["/usr/sbin/httpd", "-D","FOREGROUND"]
here is my docker-compose.yml
version: '3'
services:
web:
build: .
ports:
- "8090:80"
centos:
image: "centos:centos7"
# links:
# - db
# volumes:
# - .:/newvolebs
#db:
# image: "mysql:5.6"
# volumes:
# - newvolebs:/var/lib/mysql/data
# networks:
# - overlay
# environment:
# MYSQL_ROOT_PASSWORD: PASSWORD
# MYSQL_DATABASE: DATABASENAME
i have created one ebs volume attached it with my instance and make it usable with name "newvolebs"
how to mount it in my application database.
Thanks in advance.
I am working on a php docker application.Am facing an error while trying docker-compose up command. Trying to connect a php application to mysql.
My docker compose file
web:
build: .
command: php -S 0.0.0.0:8000 -t /app
links:
- db
ports:
- "8000:8000"
volumes:
- ./app:/app
db:
image: mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_USER: dev
MYSQL_PASSWORD: 123456
MYSQL_DATABASE: myapp
Am getting this error: E: Unable to locate package libicu-dev
ERROR: Service 'web' failed to build: The command '/bin/sh -c apt-get install -y libicu-dev' returned a non-zero code: 100
This might be because these are https sources.
Can you invoke
apt-get update && apt-get install -y apt-transport-https
before the command
/bin/sh -c apt-get install -y libicu-dev
is executed?
See
apt-get update' returned a non-zero code: 100
apt update
(optional) apt purge libicu-dev
apt install libicu-dev
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'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