I am trying to connect to a MySQL database from a Symfony project in a Docker container.
I have added an install mysqli command to my Dockerfile but when I try to connect to the database, Symfony produces an error page with Attempted to load class "mysqli" from the global namespace. Did you forget a "use" statement?
.
Looking at the list of declared classes with use_declared_classes()
, I cannot see the mysqli class.
However, if I go into the command prompt for the container and install mysqli manually, it appears in the declared classes and it can connect to the database.
What is incorrect in my Dockerfile that means that the installation of mysqli doesn't work correctly?
My Dockerfile is
FROM php:8.1-apache
# Configure Apache
RUN a2enmod rewrite
COPY docker/web/apache.conf /etc/apache2/sites-enabled/000-default.conf
COPY . /var/www
RUN service apache2 restart
# set the working directory to be /var/www
WORKDIR /var/www
# Install PHP MYSQL extension and restart server
RUN apt-get clean \
&& apt-get update \
&& docker-php-ext-install mysqli;
RUN service apache2 restart;
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer