Laravel 应用程序在 Ubuntu 中运行不佳,但在 Windows 中运行良好

问题描述 投票:0回答:1

我是一名 DevOps 工程师,正在部署第一次 Laravel 应用程序。我制作了 dockerfile 和 docker-compose.yaml 文件。它在 windows 机器上运行良好。当我尝试在 ubuntu 中运行此 docker-compose.yaml 文件时,docker 容器工作正常,但 api 无法工作。报405错误。我尝试解决它但无法解决。由于我之前没有使用 Laravel 的经验,所以我被困在这里。 php版本是8.3,dockerfile是

# 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

当我点击登录 api 时,此日志为 **-1 [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 配置 — 恢复正常操作 [Thu Jan 16 12:18:06.359506 2025] [core:notice] [pid 1:tid 1] AH00094: 命令行: 'apache2 -D FOREGROUND' 172.22.0.1 - - [16/Jan/2025:12:19:15 +0000]“POST /[电子邮件受保护]&密码=123 HTTP/1.1”405 248983“-”“PostmanRuntime/7.37.3” ** 请指导我如何解决这个问题。

我尝试在其他 Windows 机器上运行此代码,效果很好。但当我在 ubuntu 机器上运行这个 dockerfile 时,它拒绝加载该端点。

laravel docker ubuntu docker-compose devops
1个回答
0
投票

我是高级软件工程师 Salman DevOps 为您编写此 docker 文件,请检查并确认如果不共享日志它是否可以工作,以便我可以编写一个可以工作的新文件

# 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
© www.soinside.com 2019 - 2024. All rights reserved.