can not connect to mysql with php code | used docker
i use WordPress want to use docker and deploy on a server problem is i can use WordPress but when want to use duplicator to transfer my site errored that can not connect to MySQL problem is wordpress itself can connect to db but other php codes can not docker-compose.yml file with following code
also i write a PHP code to test can connect to db but also also in path of localhost:8000/test.php got error 500 status code if i delete codes that connect to db 500 error code will removed and work normal
@dev.khosromanesh Your PHP container in your setup uses the php:7.4 image, which might not come with the MySQL extensions installed by default. You can customize your PHP Dockerfile to install these extensions.
FROM php:7.4
# Install necessary extensions
RUN docker-php-ext-install mysqli pdo pdo_mysql
# Copy your application code
COPY . /var/www/html
WORKDIR /var/www/html
Update your docker-compose.yml php service to use the custom Dockerfile for the php service
@dev.khosromanesh Modify your test.php script to use the correct hostname and credentials. Note that when connecting from one Docker container to another, you should use the service name (in this case, db) as the hostname instead of localhost.