What could be wrong with my apache configuration?

Viewed 18

I'm having trouble running my code inside a php container. The code is written with the codeigniter 4 framework. This is my Dockerfile:

FROM composer:2.4.1 as build
WORKDIR /tmp/
COPY composer.json .
RUN composer install --no-interaction --prefer-dist

FROM php:7.4-apache
WORKDIR /var/www/html
COPY --from=build /tmp/vendor ./vendor/
COPY . .
RUN chown -R www-data:www-data /var/www
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
RUN echo "ServerName 0.0.0.0:8080" >> /etc/apache2/apache2.conf && echo "Define SRVROOT "/etc/apache2"" >> /etc/apache2/apache2.conf && echo "ServerRoot "/etc/apache2"" >> /etc/apache2/apache2.conf
RUN sed -i "s/Listen 80/Listen 8080/" /etc/apache2/ports.conf 
RUN sed -i "s/VirtualHost *:80/VirtualHost *:8080/" /etc/apache2/sites-available/000-default.conf
RUN a2enmod rewrite
RUN rm composer.json
EXPOSE 8080
CMD apachectl -D FOREGROUND

So far I tried to modify the ServerName value with localhost, 127.0.0.1, with the ip of the docker host but still I get the 404 not found error when I type the url in the host.

Mi apache2.conf looks like this with the modifications that I do in the Dockerfile:

DefaultRuntimeDir ${APACHE_RUN_DIR}

PidFile ${APACHE_PID_FILE}

Timeout 300

KeepAlive On

MaxKeepAliveRequests 100

KeepAliveTimeout 5

User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log

LogLevel debug

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

AccessFileName .htaccess


<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf

IncludeOptional sites-enabled/*.conf

Define SRVROOT /etc/apache2
ServerRoot /etc/apache2

This is the virtual host file:

<VirtualHost *:8080>

    ServerName 10.10.0.232:8080

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    <Directory /var/www/html>
        Require all granted
        AllowOverride All
        DirectoryIndex index.php
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

The only thing I get in the browser is the 404 not found error. I try to modify those files with different values but I always get the same error. Could you guide me if this problem may be due to the Apache configuration or is it something related to the code.

This is a debug that i get in the container logs
[Thu Sep 22 15:41:49.524080 2022] [authz_core:debug] [pid 17] mod_authz_core.c(815): [client x.x.x.x:54970] AH01626: authorization result of Require all granted: granted
[Thu Sep 22 15:41:49.524143 2022] [authz_core:debug] [pid 17] mod_authz_core.c(815): [client x.x.x.x:54970] AH01626: authorization result of <RequireAny>: granted
[Thu Sep 22 15:41:49.524256 2022] [authz_core:debug] [pid 17] mod_authz_core.c(815): [client x.x.x.x:54970] AH01626: authorization result of Require all granted: granted
[Thu Sep 22 15:41:49.524263 2022] [authz_core:debug] [pid 17] mod_authz_core.c(815): [client x.x.x.x:54970] AH01626: authorization result of <RequireAny>: granted
x.x.x.x - - [22/Sep/2022:15:41:49 +0000] "GET / HTTP/1.1" 404 1313 "-" "insomnia/2022.3.0"
0 Answers
Related