Im trying to run a laravel application in a container and I get driver could not be found on migrate. Laravel 8, mysql 8, php 8
docker compose
version: "3.9"
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#Nginx Service
webserver:
image: nginx:latest
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "8005:80"
- "8006:443"
volumes:
- ./:/var/www
- ./docker/nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#Mariadb Service
db:
image: mysql
container_name: db
restart: unless-stopped
tty: true
environment:
MYSQL_DATABASE: test
MYSQL_ROOT_PASSWORD: test
SERVICE_TAGS: dev
SERVICE_NAME: db
volumes:
- dbdata:/var/lib/mysql1
- ./docker/sqldb/db.cnf:/etc/sqldb/db.cnf
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
Dockerfile
FROM php:fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Copy existing application directory contents
COPY . /var/www
# Set working directory
WORKDIR /var/www
# Give permissions
RUN chown -R www-data:www-data .
RUN find . -type f -exec chmod 664 {} \;
RUN find . -type d -exec chmod 775 {} \;
RUN chgrp -R www-data storage bootstrap/cache
RUN chmod -R ug+rwx storage bootstrap/cache
RUN docker-php-ext-install mysqli pdo pdo_mysql
RUN docker-php-ext-install mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
# Expose port 9000 and start php-fpm server
EXPOSE 9000
.env
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=test
# I have also tried creating another user and granting all privileges to it, same thing
Its some missing extension I cant figure what is it, maybe im installing pdo incompatible with php 8? The user and database are correctly created.
error
Illuminate\Database\QueryException
could not find driver (SQL: select * from information_schema.tables where table_schema = test and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:678
674▕ // If an exception occurs when attempting to run a query, we'll format the error
675▕ // message to include the bindings with SQL, which will make this exception a
676▕ // lot more helpful to the developer instead of just the database's errors.
677▕ catch (Exception $e) {
➜ 678▕ throw new QueryException(
679▕ $query, $this->prepareBindings($bindings), $e
680▕ );
681▕ }
682▕
+33 vendor frames
34 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
note: I have tried many solutions on many different answers here on stackoverflow
Thank you!
Edit:: phpinfo() has PDO (sqlite enabled), and pdo_sqlite (3.27.2) and mysqlnd 8.0.6 Thats the only db drivers i can see, maybe its something to do with local.ini I add using docker-compose
here's local.ini
upload_max_filesize=40M
post_max_size=40M
# tried adding extension=php_pdo_mysql.so, no luck