Dockerization PHP-APACHE MYSQL on centos7 - php

i have tried creating a docker container on centos7 but
i could access phpmyadmin page but not index.php page
could you see the docker yml and docker file and tell what happened
like im running through kali linux to a centos7 docker its been difficult i have been trying since yesterday
the give code is docker-compose.yml
version: "3"
services:
www:
build: .
ports:
- "8001:80"
volumes:
- ./www:/var/www/html/
links:
- db
networks:
- default
db:
image: mysql:8.0.16
command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci','--default-authentication-plugin=mysql_native_password']
ports:
- "8002:3306"
environment:
MYSQL_DATABASE: myDb
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
volumes:
- ./dump:/docker-entrypoint-initdb.d
- persistent:/var/lib/mysql
networks:
- default
phpmyadmin:
image: phpmyadmin/phpmyadmin:4.9
links:
- db:db
ports:
- 8000:80
environment:
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
volumes:
persistent:
and the dockerfile
FROM php:7.1.19-apache
RUN docker-php-ext-install mysqli mbstring
i dont know what is the issue like when access localhost:8000 on browser
im getting forbidden access 403 error
i just need to access index.php when i enter localhost:8000 on browser
please help me out,
thank you in advance

Related

Default installation still visible even after deleting the installation folder

please, when I want to run exist prestashop project (1.6.1.7) on docker, still showing me page of installation, but I have own DB. Where is a problem? Please, can you help me?
On stackoverflow I didn't found same question, which would help me.
This is my docker-compose.yml
version: "3.8"
services:
prestashop:
image: prestashop/prestashop
ports:
- 82:80
links:
- mysql:mysql
depends_on:
- mysql
volumes:
- ./../:/srv
- ./../modules:/srv/modules
- ./../themes:/srv/themes
- ./../override:/srv/override
environment:
- PS_DEV_MODE=1
- DB_SERVER=mysql
- DB_USER=root
- DB_PASSWD={PASSWORD}
- DB_NAME={DB}
- PS_INSTALL_AUTO=0
mysql:
image: mysql
container_name: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: {PASSWORD}
MYSQL_DATABASE: {DB}
MYSQL_USER: db_write
MYSQL_PASSWORD: 123
volumes:
- ./data/db/:/var/lib/mysql:delegated
adminer:
image: adminer
container_name: Adminer
restart: always
environment:
ADMINER_DEFAULT_SERVER: mysql
ports:
- 8080:8080
When I go to install my DB is removed which I don't want. I already tried to install the new database and then replace it with my database, but it didn't help.

Docker - laradoc couldn't get logged in phpmyadmin

I have installed laradoc as per documentation but I am unable to login phpmyadmin.
here is my docker-compose.yaml file:
phpmyadmin:
build: ./phpmyadmin
environment:
- PMA_ARBITRARY=1
- MYSQL_USER=${PMA_USER}
- MYSQL_PASSWORD=${PMA_PASSWORD}
- MYSQL_ROOT_PASSWORD=${PMA_ROOT_PASSWORD}
ports:
- "${PMA_PORT}:80"
depends_on:
- "${PMA_DB_ENGINE}"
networks:
- frontend
- backend
and here is .env file
PMA_DB_ENGINE=mysql
PMA_USER=default
PMA_PASSWORD=secret
PMA_ROOT_PASSWORD=secret
PMA_PORT=8080
Difficult to reproduce the error from the given info but this small setup works so maybe you can find what went wrong?
First bring your existing stack down and delete dangling volumes:
$ docker-compose down
$ docker volume prune
Start the following docker-compose.yaml:
version: '3.1'
services:
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
- PMA_ARBITRARY=1
- MYSQL_USER=${PMA_USER}
- MYSQL_PASSWORD=${PMA_PASSWORD}
- MYSQL_ROOT_PASSWORD=${PMA_ROOT_PASSWORD}
ports:
- "${PMA_PORT}:80"
depends_on:
- "${PMA_DB_ENGINE}"
networks:
- frontend
- backend
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: db
MYSQL_USER: default
MYSQL_PASSWORD: secret
networks:
- frontend
- backend
networks:
frontend:
backend:
info (I had to use mysql5.7 otherwise I was facing this bug:
docker-compose up -d
Creating network "test_frontend" with the default driver
Creating network "test_backend" with the default driver
Creating test_mysql_1 ... done
Creating test_phpmyadmin_1 ... done
I know I'm a bit 'messing' with the syntax + you can use the env vars too for mysql but I had to be quick.

Access denied to MySQL database in Docker

My Docker (v.2) docker-compose.yml file has 2 Ubuntu images and 2 MariaDB images:
app:
container_name: app
image:php-apache-dev:ubuntu-16.04
links:
- mysql
depends_on:
- mysql
ports:
- '8443:443'
volumes:
- .:/app
environment:
docker: 'true'
PHP_DEBUGGER: 'xdebug'
WEB_DOCUMENT_ROOT: '/app/public'
WEB_NO_CACHE_PATTERN: '\.(.*)$$'
working_dir: '/app'
CONF_FILE: 'conf/local/develop.php'
test:
container_name: test
image:php-apache-dev:ubuntu-16.04
links:
- mysql_test
depends_on:
- mysql_test
ports:
- '8444:443'
volumes:
- .:/app
environment:
docker: 'true'
WEB_DOCUMENT_ROOT: '/app/public'
WEB_NO_CACHE_PATTERN: '\.(.*)$$'
working_dir: '/app'
CONF_FILE: 'conf/local/test.php'
mysql:
image: mariadb:latest
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: 'dev'
MYSQL_DATABASE: 'dev'
MYSQL_USER: 'dev'
MYSQL_PASSWORD: 'dev'
mysql_test:
image: mariadb:latest
ports:
- '3307:3306'
environment:
MYSQL_ROOT_PASSWORD: 'dev'
MYSQL_DATABASE: 'dev_test'
MYSQL_USER: 'dev'
MYSQL_PASSWORD: 'dev'
One is for development, one is for testing. When I access the first one (on localhost:4443) it works. When I access the second one (on localhost:4444) I am able to view the website, but it denies access to the user:
Access denied for user 'dev'#'%' to database 'dev_test'
My configuration for the second site is set up to access the second MySQL port/user:
'db_port' => env('DB_PORT', '3307'),
'db_name' => env('DB_NAME', 'dev_test'),
I tried the answer to this question but without success. If I docker exec bash into the test database image, and run SHOW GRANTS FOR dev, it says:
GRANT ALL PRIVILEGES ON `dev_test`.* TO 'dev'#'%'
You probably forgot to use the correct MySQL host in your second site.

How can I connect php-apache and MySQL using Docker?

I have a Wordpress site on live server and I want to create a LAMP stack locally with Docker to test things.
I pull the images of php:7.0-apache and mysql:5.7, the same versions on live.
I create a MySQL container:
docker run -d --name achi-mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7
I create a php & apache container and link it with MySQL:
docker run -d --name achi-php-apache --link achi-mysql:mysql -p 8080:80 -v /home/achi/workspace/web/wordpress-template/:/var/www/html php:7.0-apache
I get the following error on localhost:8080:
Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /var/www/html/wp-includes/wp-db.php:1564 [...]
Do I link these two containers the wrong way?
Your problem is not the connection between your containers. The problem is your PHP / Apache container which doesn't support mysqli (or PDO MySQL). WordPress can't find another function to connect with a MySQL database or your MySQL container. Instead WordPress is using a deprecated and removed (since PHP 7.0) mysql_ function per default. You need to install at least mysqli on your PHP container (explained below).
I also recommend to use a docker-compose file to install and run all containers with one command.
To create the containers you want, you can use the following docker-compose.yml file:
version: "3"
services:
achi-php-apache:
build:
context: ./
container_name: achi-php-apache
ports:
- "8080:80"
volumes:
- /home/achi/workspace/web/wordpress-template:/var/www/html:rw
depends_on:
- achi-mysql
networks:
- wp-net
achi-mysql:
image: mysql:5.7
container_name: achi-mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: wp-dbname
volumes:
- wp-mysql-data:/var/lib/mysql
networks:
- wp-net
networks:
wp-net:
driver: bridge
volumes:
wp-mysql-data:
You need the following Dockerfile on the same directory as the docker-compose.yml file:
FROM php:7.0-apache
RUN docker-php-ext-install -j$(nproc) mysqli
This Dockerfile installs the missing mysqli extension so WordPress can use it.
You can also use PDO MySQL instead of mysqli. In this case you can use the following Dockerfile:
FROM php:7.0-apache
RUN docker-php-ext-install -j$(nproc) pdo
RUN docker-php-ext-install -j$(nproc) pdo_mysql
Now you can execute the command docker-compose up inside the folder where the docker-compose.yml file is located. After creating the container and running you should be able to access the WordPress site (<ip-or-hostname>:8080).
On the wp-config.php file you need to use the following constants:
define('DB_NAME', 'wp-dbname');
define('DB_USER', 'root');
define('DB_PASSWORD', '123456');
define('DB_HOST', 'achi-mysql');
You can also use the official WordPress image to install WordPress. In this case you can use the following docker-compose.yml file:
version: "3"
services:
achi-php-apache:
image: wordpress:4.9.4-php7.0-apache
container_name: achi-php-apache
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: achi-mysql
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: 123456
WORDPRESS_DB_NAME: wp-dbname
volumes:
- /home/achi/workspace/web/wordpress-template:/var/www/html:rw
depends_on:
- achi-mysql
networks:
- wp-net
achi-mysql:
image: mysql:5.7
container_name: achi-mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: wp-dbname
volumes:
- wp-mysql-data:/var/lib/mysql
networks:
- wp-net
networks:
wp-net:
driver: bridge
volumes:
wp-mysql-data:
The simplest way is to use docker-compose to link all your docker instances together rather than linking through the docker command. Here is a sample docker-compose.yml file that should do what you want:
version: '2'
services:
achi-php-apache:
image: php:7.0-apache
ports:
- "8080:80"
volumes:
- /home/achi/workspace/web/wordpress-template/:/var/www/html
links:
- achi-mysql
achi-mysql:
image: mysql:5.7
volumes:
- /var/lib/mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_USER: someuser
MYSQL_PASSWORD: somepassword
MYSQL_DATABASE: somedefaultdatabase

Unable to connect phpmyadmin to database using docker compose

May be this question asked few times before but I did't get a valid answer which can solve my problem.
I am trying to run phpmyadmin in docker on different container using docker-compose but It always through the following error:
#2002 - Connection refused — The server is not responding (or the local server's socket is not correctly configured).
My docker compose file contains the following code:
version: "2"
services:
web:
build: .
ports:
- "80:80"
networks:
- web
volumes:
- .:/code
restart: always
db:
image: "mysql:5"
volumes:
- ./mysql:/etc/mysql/conf.d
environment:
MYSQL_ROOT_PASSWORD: toor
MYSQL_DATABASE: phpapp
networks:
- web
restart: always
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_PORT: 3306
PMA_HOST: db
PMA_USER: root
PMA_PASSWORD: toor
ports:
- "8000:80"
restart: always
networks:
- web
networks:
web:
driver: bridge
In web container I am trying to connect with database and it works fine, but the problem occur with phpmyadmin connection
Any help would be appreciated. :)
Interestng enough, I have your compose-file running and phpmyadmin is accessible
from host.
Had to change port 8000 to 8004 though (port 8000 is occupied on my host).
In case your db-container does not start fast enough for phpmyadmin to connect, I suggest adding depends_on into phpmyadmin service. Makes sure db starts before phpmyadmin.
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_PORT: 3306
PMA_HOST: db
PMA_USER: root
PMA_PASSWORD: toor
ports:
- "8004:80"
restart: always
depends_on:
- db
networks:
- web
Please show logs from docker-compose up if problem persists.
Now you need to add command to mysql service for connecting to phpmyadmin.
command: --default-authentication-plugin=mysql_native_password
version: "2"
services:
db:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: drupal
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
volumes:
- ./dump:/docker-entrypoint-initdb.d
- /var/lib/mysql
networks:
- default
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- db:db
ports:
- 8000:80
environment:
PMA_HOST: db
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test

Categories