I have a container with a symfony project which routes doesn’t work, but http://localhost
I think its some problem with the Apache configuration
this is my Dockerfile
# Imagen base de PHP 8.1 con Apache y Xdebug 3
FROM php:8.2-apache
# Instalar dependencias de Xdebug
RUN pecl install xdebug-3.4.0 && docker-php-ext-enable xdebug
# Instalar dependencias de PHP y extensiones necesarias
RUN apt-get update && apt-get install -y
libfreetype6-dev
libjpeg62-turbo-dev
libpng-dev
libzip-dev
zip
&& docker-php-ext-configure gd --with-freetype --with-jpeg
&& docker-php-ext-install -j$(nproc) gd pdo pdo_mysql zip
# Configuración de Xdebug
RUN echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
# Habilitar módulo de Apache para el archivo .htaccess
RUN a2enmod rewrite
# Exponer el puerto 9003 para Xdebug
EXPOSE 9003
# Directorio de trabajo en el contenedor
WORKDIR /var/www/html
# Copiar archivo de configuración de Apache
COPY apache-config.conf /etc/apache2/sites-available/000-default.conf
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
RUN curl -sS https://get.symfony.com/cli/installer | bash
&& mv /root/.symfony*/bin/symfony /usr/local/bin/symfony
CMD ["apache2-foreground"]
this is docker-compose
services:
php:
container_name: todo-2-php
build:
context: .
dockerfile: Dockerfile
volumes:
- .:/var/www/html
- ./xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
ports:
- "80:80"
depends_on:
- mysql
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
XDEBUG_MODE: "develop,debug"
XDEBUG_CONFIG: "client_host=host.docker.internal start_with_request=yes"
mysql:
container_name: todo-2-mysql
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: user_database
MYSQL_USER: my_user
MYSQL_PASSWORD: my_password
MYSQL_CHARSET: utf8mb4
MYSQL_COLLATION: utf8mb4_unicode_ci
ports:
- "3307:3306"
volumes:
- database_data:/var/lib/mysql
volumes:
database_data:
and the apache.config.conf
file
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/public
<Directory /var/www/html/public>
AllowOverride All
Require all granted
</Directory>
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirige todo excepto los archivos existentes al index.php de Symfony
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
</IfModule>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I copied the doc controller to test
<?php
// src/Controller/LuckyController.php
namespace AppController;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentRoutingAttributeRoute;
class LuckyController
{
#[Route('/lucky/number', methods: ['GET'])]
public function number(): Response
{
$number = random_int(0, 100);
return new Response(
'<html><body>Lucky number: '.$number.'</body></html>'
);
}
}
and when I try to make a request to http://localhost/lucky/controller
I get this error No route found for "GET http://localhost/lucky/controller"
I think its should be a problem with the apache configuration but the changes that I tried didn’t work