I developed a project in Windows. I've used PHP, MySQL (using PDO) and Apache.
I created the database and tables with code. There was no problem.
I am trying to dockerize this project on my Ubuntu 18.04 machine. Believe me, I've only been trying this since morning.
The project runs smoothly with CSS, JavaScript on localhost. But it gives error when adding to database. The error code I received was: could not find driver. php.ini file is missing
I also don't have my apache2 folder that should be in etc/php/7.2.
I get the SQLSTATE[HY000] [2002] Cannot assign requested address error I made the connection this way:
$db = new PDO("mysql:host=$this->servername;charset=utf8", $this->username, $this->password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
I get the could not find driver error I made the connection this way (using pdo_mysql):
$db = new PDO("pdo_mysql:host=$this->servername;charset=utf8", $this->username, $this->password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
I have installed apache2 and php in Dockerfile.
Here is my result of tree command:
.
├── docker-compose.yml
├── Dockerfile
└── src
├── css
│ ├── css
│ │ └── dashboard.css
│ ├── fonts
│ │ └── feather
│ │ ├── feather-webfont6cfa.eot
│ │ ├── feather-webfont6cfa.svg
│ │ ├── feather-webfont6cfa.ttf
│ │ └── feather-webfont6cfa.woff
│ └── style.css
├── docker-compose.yml
├── js
│ ├── guncelle.js
│ └── resimler.js
└── php
├── about.php
├── categories.php
├── create_database.php
├── footer.php
├── header.php
├── index.php
├── info.php
├── login.php
└── logout.php
There are docker-compose.yml and Dockerfile files:
# DOCKERFILE
FROM php:7.3-apache
RUN apt-get update
RUN apt-get install -y git
RUN docker-php-ext-install pdo pdo_mysql mysqli
RUN a2enmod rewrite
#Install Composer
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php composer-setup.php --install-dir=. --filename=composer
RUN mv composer /usr/local/bin/
COPY src/ /var/www/html/
EXPOSE 80
# DOCKER-COMPOSE.YML
version: '3'
services:
mysql:
image: mysql:8.0
container_name: vt_album
command: --default-authentication-plugin=mysql_native_password
volumes:
- .:/application
restart: always
environment:
- MYSQL_ROOT_PASSWORD=2222
- MYSQL_PASSWORD=2222
ports:
- "3306:3306"
website:
container_name: php_album
build:
context: ./
volumes:
- ./src/:/var/www/html
ports:
- 8080:8080
depends_on:
- mysql