I can't display my index.php from my container due to this error:
Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /var/www/db/dbh.inc.php:8 Stack trace: #0 /var/www/includes/header.php(6): require() #1 /var/www/index.php(2): require_once('/var/www/includ...') #2 {main} thrown in /var/www/db/dbh.inc.php on line 8
The line 8 is: $conn = mysqli_connect($servername, $db_username, $db_password, $db_name);
I know that mysql_connect is deprecated in PHP 7.0, and I use here mysqli_connect
My Dockerfile from php-fpm run mysqli so I don't know what's wrong here
If my index.php show only a Hello World
ererything is working well with Docker. Just to let you know my website is working well from my localhost without Docker.
If I want to connect to my db it's not working well with Docker.
In order to start the containers, I do docker-compose up -d
I have two questions:
1. How can I fix this issue ?
2. How can I start the db container always first before all others containers with docker-compose ?
Here my tree files:
.
├── access
│ --- commented ---
├── assets
| --- commented ---
├── changepass.php
├── contact.php
├── db
│ ├── dbh.inc.php
│ ├── Dockerfile
│ └── mysqldump.all.tables.sql
├── docker
│ ├── docker-compose.yml
│ ├── nginx
│ │ ├── conf.d
│ │ │ └── default.conf
│ │ ├── Dockerfile
│ │ ├── nginx.conf
│ │ └── sites
│ │ └── default.conf
│ └── php-fpm
│ └── Dockerfile
├── editerrors.php
├── includes
│ ├── auth_check.php
│ ├── footer.php
│ ├── functions.inc.php
│ └── header.php
├── index.php
├── login.php
├── log.php
├── profile.php
├── signup.php
├── stb.php
└── userslist.php
/docker/nginx/Dockerfile
# nginx
FROM nginx:alpine
CMD ["nginx"]
EXPOSE 80 443
/docker/php-fpm/Dockerfile
# php-fpm
FROM php:fpm-alpine
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
CMD ["php-fpm"]
EXPOSE 9000
WORKDIR /var/www/
/db/Dockerfile
# Database MariaDB
FROM mariadb:latest
CMD ["mysqld"]
EXPOSE 3306
/docker/docker-compose.yml
version: '3'
services:
php-fpm:
container_name: php
build:
context: ./php-fpm
volumes:
- ../:/var/www
nginx:
container_name: nginx
build:
context: ./nginx
volumes:
- ../:/var/www
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/sites/:/etc/nginx/sites-available
- ./nginx/conf.d/:/etc/nginx/conf.d
depends_on:
- php-fpm
ports:
- "9001:80"
- "443:443"
database:
container_name: db
build:
context: .
dockerfile: ../db/Dockerfile
environment:
- MYSQL_DATABASE=mydb
- MYSQL_USER=myuser
- MYSQL_PASSWORD=mypassword
- MYSQL_ROOT_PASSWORD=docker
volumes:
- ../db/mysqldump.all.tables.sql:/docker-entrypoint-initdb.d/mysqldump.all.tables.sql