skip to Main Content

I’m a DevOps engineer and deploying a first-time Laravel application. I made it’s Dockerfile and docker-compose.yaml file. It’s working fine on Windows machines. When I try to run this docker-compose.yaml file in Ubuntu, the docker container works fine but the api’s are not working. Giving 405 errors. I have tried to resolve it but could not. As I have no experience of working with Laravel before, I’m stuck here. The PHP version is 8.3 and Dockerfile is

# Use PHP with Apache as the base image
FROM php:8.3-apache as web

# Install Additional System Dependencies
RUN apt-get update && apt-get install -y 
    libzip-dev 
    zip 
    git 
    && apt-get clean && rm -rf /var/lib/apt/lists/*

# Enable Apache mod_rewrite for URL rewriting
RUN a2enmod rewrite

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql zip

# Configure Apache DocumentRoot to point to Laravel's public directory
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

# Copy the application code
COPY . /var/www/html

# Set the working directory
WORKDIR /var/www/html

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Install project dependencies
RUN composer install --no-dev --optimize-autoloader

# Set permissions
RUN chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache

This log when I hit the login API is –

**
[Thu Jan 16 12:18:06.359392 2025] [mpm_prefork:notice] [pid 1:tid 1] AH00163: Apache/2.4.62 (Debian) PHP/8.2.27 configured -- resuming normal operations
[Thu Jan 16 12:18:06.359506 2025] [core:notice] [pid 1:tid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
172.22.0.1 - - [16/Jan/2025:12:19:15 +0000] "POST /[email protected]&password=123 HTTP/1.1" 405 248983 "-" "PostmanRuntime/7.37.3"

Please guide me on how can i resolve this issue.

I tried working this code on another Windows machine and it works fine. but as I run this dockerfile on the Ubuntu machine it refuses to load that endpoint.

2

Answers


  1. Chosen as BEST ANSWER

    Thanks for guiding me. Actually I was not aware of case-sensitivity in Linux and this issue was due to it. Windows is not case-sensitive but Linux is. When I changed my folder name is app/Httpd/Controller/API and also in php.ini, I issue got resolved in my Ubuntu machine. But When I deployed it on Portainer I got the the older image content. So I run "sudo docker system prune -a", all the caching and unused images are removed and my application started working fine. I really appreciate you guys helping me to sort this issue. Thank you very much.


  2. I’m Salman a Senior Software Engineer
    & DevOps writing this docker file for you kindly check and confirms that it works if not share logs so I can write a new that will works

    # Use PHP with Apache as the base image
    FROM php:8.3-apache as web
    
    # Install Additional System Dependencies and PHP extensions
    RUN apt-get update && apt-get install -y 
        libzip-dev 
        zip 
        git 
        && docker-php-ext-install pdo_mysql zip 
        && apt-get clean && rm -rf /var/lib/apt/lists/*
    
    # Enable Apache mod_rewrite for URL rewriting
    RUN a2enmod rewrite
    
    # Configure Apache DocumentRoot to point to Laravel's public directory
    ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
    RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
    RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
    RUN sed -i 's/AllowOverride None/AllowOverride All/g' /etc/apache2/apache2.conf
    
    # Copy the application code
    COPY . /var/www/html
    
    # Set the working directory
    WORKDIR /var/www/html
    
    # Install composer
    RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
    
    # Install project dependencies
    RUN composer install --no-dev --optimize-autoloader
    
    # Set permissions for storage and cache
    RUN chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache 
        && chmod -R 775 /var/www/html/storage /var/www/html/bootstrap/cache
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search