PHP 8.0 - Apache - phpMyAdmin - Docker Image - php

I am creating an image for a php8 project run on apache, and work with phpMyAdmin, I have my Dockerfile as follow :
FROM php:8.0-apache
RUN apt-get update -y && apt-get install -y libmariadb-dev && docker-php-ext-install mysqli && docker-php-ext-install pdo_mysql
WORKDIR /var/www/html
And my docker-compose.yml as follow :
services:
php-apache-environment:
container_name: php-apache
image: php:8.0-apache
volumes:
- ./php/src:/var/www/html/
ports:
- 8000:80
db:
container_name: db
image: mysql:latest
restart: always
environment:
MYSQL_ROOT_PASSWORD: MYSQL_ROOT_PASSWORD
MYSQL_DATABASE: MY_DATABASE
MYSQL_USER: MYSQL_USER
MYSQL_PASSWORD: MYSQL_PASSWORD
ports:
- "9906:3306"
phpmyadmin:
image: phpmyadmin:latest
ports:
- '8080:80'
restart: always
environment:
PMA_HOST: db
depends_on:
- db
For me, all is good, but when I run "docker compose up --build", container is launched, but he has not install "mysqli" and "pdo_mysql" like I request in the Dockerfile.
But, if I log in by CLI to the PHP container, and that I run docker-php-ext-install mysqli and docker-php-ext-install pdo_mysql, it works, and I just have to restart the PHP container.
But, I dont know why, I can't install it from the start ?
Thank you for your help.

Thans to Lety comment, we juste need to change the line 4 of docker-compose.yml
by :
build: ./php
(to indicate the directory where the Dockerfile is) and it works.
Resume :
Dont change the Dockerfile
. Change the docker-compose.yml by :
version: '3.8'
services:
php-apache-environment:
container_name: php-apache
build: ./php
volumes:
- ./php/src:/var/www/html/
ports:
- 8000:80
db:
container_name: db
image: mysql:latest
restart: always
environment:
MYSQL_ROOT_PASSWORD: MYSQL_ROOT_PASSWORD
MYSQL_DATABASE: MY_DATABASE
MYSQL_USER: MYSQL_USER
MYSQL_PASSWORD: MYSQL_PASSWORD
ports:
- "9906:3306"
phpmyadmin:
image: phpmyadmin:latest
ports:
- '8080:80'
restart: always
environment:
PMA_HOST: db
depends_on:
- db

Related

I run CakePHP application in Docker and I got this message in the browser "This page isn’t working"

I have an existing CakePHP project and I want to run it with Docker,
I used the command docker compose up -d and I got those containers:
Containers List in Docker
Now Obviously, it should be work on localhost:9000 and the phpmyadmin on localhost:8083.
But only the PMA (phpmyadmin) worked, and that what I got in my browser for localhost:9000
Browser Response
So this what I am facing.
DockerFile
FROM phpdockerio/php74-fpm:latest
# Install selected extensions and other stuff
RUN apt-get update \
&& apt-get -y --no-install-recommends install php7.4-mysql php7.4-intl php7.4-mbstring php7.4-sqlite3\
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
WORKDIR "/var/www/html"
docker-compose.yml
version: "3.8"
services:
nginx-proxy:
image: nginx
volumes:
- ./website:/var/www/html
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./docker/log:/var/log/nginx
- ./docker/certs:/etc/nginx/certs
- ./docker/nginx:/etc/nginx/conf.d
ports:
- 80:80
- 443:443
depends_on:
- php
- db
php:
build: ./docker/php/
image: php:fpm
ports:
- 9000:9000
container_name: talkto_php
environment:
- VIRTUAL_HOST=talkto_php.local
depends_on:
- db
volumes:
- ./website:/var/www/html
- ./docker/apache/apache2.conf:/etc/apache2/apache2.conf
db:
image: mysql:5.6.51
container_name: talkto_db
environment:
MYSQL_ROOT_PASSWORD: calltode
MYSQL_USER: talkto
MYSQL_PASSWORD: talkto
MYSQL_DATABASE: talkto
ports:
- "3306:3306"
volumes:
- talkto-data:/var/lib/mysql
- ./database/calltode_dev2.sql:/home/db.sql
pma:
image: phpmyadmin/phpmyadmin
container_name: pma
environment:
PMA_HOST: db
PMA_PORT: 3306
PMA_ARBITRARY: 1
restart: always
ports:
- 8083:80
links:
- db
volumes:
talkto-data:
It suppose to show me the contain of my CakePHP application on localhost:9000

PHP GD library missing - Docker installation

I am using the following docker-compose.yaml file:
version: "3.9"
services:
web:
image: nginx:latest
ports:
- "8080:80"
volumes:
- ./src:/var/www/html
- ./default.conf:/etc/nginx/conf.d/default.conf
links:
- php-fpm
php-fpm:
image: php:8-fpm
volumes:
- ./src:/var/www/html
db:
image: 'jc21/mariadb-aria:latest'
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: 'secretpassword.'
MYSQL_DATABASE: 'secretdb'
MYSQL_USER: 'secretuser'
MYSQL_PASSWORD: 'secretpassword.'
volumes:
- ./data/mysql:/var/lib/mysql
phpmyadmin:
image: lscr.io/linuxserver/phpmyadmin:latest
container_name: pma
links:
- db
environment:
PMA_ARBITRARY: 0
PMA_HOST: db
PMA_PORT: 3306
restart: always
ports:
- 8085:80
It works fine. I wanna test a cms. I need the GD library. But it seems that it is not installed yet.
How can I install the GD library?
I went into the php-fpm container. I installed the gd library successfully! Thanks for the tip!

"No releases available" error when installing pecl in Docker

I am trying to install Xdebug or Redis package in a Docker container from pecl. Installation failed and returns an error:
There are no releases available for package "pecl.php.net/xdebug".
Example for Xdebug: https://pecl.php.net/package/xdebug/3.1.0
My docker-compose.yaml
version: '3'
networks:
app-network:
services:
site:
build:
context: .
dockerfile: nginx.dockerfile
container_name: my_nginx
ports:
- "8082:80"
- "443:443"
volumes:
- ./src:/var/www/html
depends_on:
- php
- db
- redis
networks:
- app-network
db:
image: percona
container_name: my_db
restart: on-failure
tty: true
ports:
- "3314:3306"
volumes:
- ./percona:/var/lib/percona
environment:
MYSQL_DATABASE: mydb
MYSQL_USER: me
MYSQL_PASSWORD: 123
MYSQL_ROOT_PASSWORD: 456
SERVICE_TAGS: dev
SERVICE_NAME: db
networks:
- app-network
php:
build:
context: .
dockerfile: php.dockerfile
container_name: my_php
volumes:
- ./src:/var/www/html
ports:
- "9000:9000"
networks:
- app-network
composer:
image: frojd/composer-php-7.4
container_name: my_composer
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
depends_on:
- php
networks:
- app-network
redis:
image: redis:alpine
container_name: my_redis
volumes:
- ./redis:/data
restart: on-failure
command: redis-server --appendonly yes --requirepass "${REDIS_PASSWORD}"
ports:
- 6380:6379
networks:
- app-network
npm:
image: node:14.18.0
container_name: my_npm
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
entrypoint: ['npm']
artisan:
build:
context: .
dockerfile: php.dockerfile
container_name: my_artisan
volumes:
- ./src:/var/www/html
depends_on:
- db
working_dir: /var/www/html
entrypoint: ['php', '/var/www/html/artisan']
networks:
- app-network
cron:
build:
context: .
dockerfile: cron.dockerfile
container_name: my_cron
volumes:
- ./src:/var/www/html
networks:
- app-network
My php.dockerfile
FROM php:7.4-fpm
WORKDIR /var/www/html
RUN apt-get update && \
apt-get install ca-certificates && \
apt-get clean
RUN docker-php-ext-install pdo pdo_mysql
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_host = host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
What is the cause of the error and how can I fix it?
You may be behind a proxy... I resolved this same problem by setting the proxy for PECL specifically (the environment variable alone $HTTP_PROXY won't work).
RUN pear config-set http_proxy ${http_proxy} &&\
pear config-set php_ini $PHP_INI_DIR/php.ini
RUN pecl install xdebug-3.1.1 && docker-php-ext-enable xdebug
This answer helped me: https://stackoverflow.com/a/11195778/256762. Hope mine's help as well 😉.

Docker: PhpMyAdmin has an upload limit of 2048KiB

i have a docker-compose.yml that looks like this:
webserver:
build: ./_docker/php
ports:
- 80:80
links:
- mysql
volumes_from:
- app
mysql:
image: mysql:5.7
environment:
MYSQL_DATABASE: "${DB_NAME}"
MYSQL_USER: "${DB_USER}"
MYSQL_ROOT_PASSWORD: "${DB_ROOT_PW}"
MYSQL_PASSWORD: "${DB_PW}"
volumes:
- ./_docker/data/db:/docker-entrypoint-initdb.d
volumes_from:
- data
data:
image: mysql:5.7
volumes:
- /var/lib/mysql
command: "true"
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- 8080:80
links:
- mysql
environment:
PMA_HOST: mysql
app:
image: tianon/true
volumes:
- .:/var/www/public_html
Dockerfile looks like this:
FROM php:7.0-apache
#php:7.2.2-apache
#php:5.6.33-apache
COPY php.ini /usr/local/etc/php/
COPY 000-default.conf /etc/apache2/sites-available/
RUN a2enmod rewrite
RUN a2enmod expires
RUN a2enmod headers
RUN apt-get update
RUN apt-get install -y zlib1g-dev libxml2-dev libfreetype6-dev libjpeg62-turbo-dev libmcrypt-dev libpng12.0 imagemagick
RUN docker-php-ext-install mysqli zip soap
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install gd
# Install opcache
RUN docker-php-ext-install opcache
and the php ini like this:
max_input_vars = 1500
max_execution_time = 300
post_max_size=50M
upload_max_filesize=50M
when i start the container i have my webserver located on http://localhost.
i put an index.php with a phpinfo(); inside it and it shows, that the php.ini works.
When i open http://localhost:8080 and login to PMA it shows me that my upload limit i set to 2048KiB.
Where can i change this?
Thanks in advance!
Use like this UPLOAD_LIMIT env in docker. This is from my docker-compose.yml. Default value for UPLOAD_LIMIT is 2048K which is 2048KiB. Setting value to 300M increases it to 300MiB.
Reference: https://github.com/phpmyadmin/docker#environment-variables-summary
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: 'php7.3-phpmyadmin'
restart: 'always'
links:
- mysql
environment:
PMA_HOST: mysql
PMA_PORT: 3306
UPLOAD_LIMIT: 300M
ports:
- '8082:80'
volumes:
- /sessions
I implemented UPLOAD_LIMIT ENV variable in
https://github.com/phpmyadmin/docker/pull/261/files#diff-80edf79b0f382a3c6e871ac209ffd6abR57
you need to use UPLOAD_LIMIT inside enviroment, and you need to specify values with = sign, like example: UPLOAD_LIMIT=300M
version: '3.1'
services:
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: somerandompasswordgenerated
ports:
- 3306:3306
phpmyadmin:
image: phpmyadmin
restart: always
ports:
- 8080:80
environment:
- PMA_ARBITRARY=1
- UPLOAD_LIMIT=300M
UPLOAD_LIMIT: 500M
mariadb:
image: mariadb:latest
container_name: w-mariadb
restart: always
ports:
- "3307:3306"
environment:
MYSQL_DATABASE: db_name
MYSQL_USER: root
MYSQL_PASSWORD: db_password
MYSQL_ROOT_PASSWORD: db_password
volumes:
- 'w-mariadb:/var/lib/mysql'
networks:
- w-network
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: w-phpmyadmin
links:
- mariadb
environment:
MYSQL_ROOT_PASSWORD: db_password
PMA_HOST: mariadb
UPLOAD_LIMIT: 500M
restart: always
ports:
- '8383:80'
networks:
- w-network
In my case I couldn't fix it with UPLOAD_LIMIT, so without further debugging I needed a quick solution even if it's temporary:
open phpmyadmin container terminal: docker exec -it container_name bash
If you don't have vim or nano editor install one: apt-get update, apt-get install vim
create config file: vi /usr/local/php/conf.d/myconf.ini
with this content: post_max_size=50M upload_max_filesize=50M
restart container
Remember these changes will be gone when container is recreated, it's just a temporary solution. Try working with UPLOAD_LIMIT as suggested in previous answer.
UPDATE
Tried again with setting upload_limit environment, but still without luck, so found another solution:
created a file say uploads.ini with this content:
post_max_size=50M
upload_max_filesize=50M
and link it to container volume :
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- mysql:db
ports:
- 8084:80
volumes:
- ./uploads.ini:/usr/local/etc/php/conf.d/php-phpmyadmin.ini
environment:
MYSQL_ROOT_PASSWORD: something
#UPLOAD_LIMIT: 3000000000 <-- didn't work
the following worked very well.
My docker-compose.yml contains this:
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: some-name
env_file:
- phpmyadmin.env
depends_on:
- mariadb
volumes:
The following entry was added to the phpmyadmin.env: UPLOAD_LIMIT=256MB
The larger number (Maximal: 256MiB) showed up right after the container was brought down and was back up again.
If you want to install from phpmyadmin docker image and with docker run, you can exec this.
docker run --name your-image-name -d --link mysql-docker:db --env "UPLOAD_LIMIT=256M" phpmyadmin
This works for me and enable upload to 256MB SQL file.
I edit this file :
/usr/local/etc/php/conf.d/phpmyadmin-misc.ini
and set new values :
post_max_size=64M
upload_max_filesize=64M
It works fine.

docker compose - add python to LAMP

In linux I build a blog application that is based on mysql, apache2 and php. But I use some python for it. The python is for adapting python Pygments that is described there https://davidwalsh.name/pygments-php-wordpress .
I prepared docker compose stage that works fine but python does not work in it. How to add python to docker compose?
Here are my files:
root#debian:/usr/local/share/a22php7m55# cat docker-compose.yml
version: "2.1"
services:
apachephp:
build: ./a22php7/
ports:
- 8888:80
volumes:
- "/etc/passwd:/etc/passwd:ro"
- "/etc/group:/etc/group:ro"
- "${PROJECT_ROOT}:/var/www/html"
networks:
- database
- server
depends_on:
- mysql
container_name: ap47
mysql:
image: mariadb:5.5
volumes:
- ${MYSQL_DATA}:/var/lib/mysql
networks:
- database
environment:
MYSQL_ROOT_PASSWORD: "${MYSQL_ROOT_PASSWORD}"
MYSQL_DATABASE: "${MYSQL_NAME}"
MYSQL_USER: "${MYSQL_USERNAME}"
MYSQL_PASSWORD: "${MYSQL_PASSWORD}"
container_name: maria47
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- 8080:80
networks:
- database
depends_on:
- mysql
environment:
PMA_HOST: mysql
container_name: pma47
volumes:
mariadb:
networks:
database:
server:
root#debian:/usr/local/share/a22php7m55# cat a22php7/
root#debian:/usr/local/share/a22php7m55# cat a22php7/Dockerfile
FROM php:7.1.3-apache
RUN docker-php-ext-install pdo pdo_mysql
root#debian:/usr/local/share/a22php7m55#
Looking at the base image for php:7.1.3-apache we see it's built on debian:jessie so we can install python, pip and pygments by adding these lines to your Dockerfile:
RUN apt-get update && apt-get install -y python python-pip
RUN pip install pygments

Categories