简体   繁体   English

未找到 Laravel、Docker、Apache2

[英]Laravel Not Found, Docker, Apache2

I am traying to connect to my container but I am getting the following error.我正在尝试连接到我的容器,但出现以下错误。 Before my container works without problems.在我的容器正常工作之前。 I made a new build but it doesn't work.我做了一个新的构建,但它不起作用。

My Docker file is the following:我的 Docker 文件如下:

FROM php:7.2-apache

LABEL maintainer="christianahvilla@gmail.com"

# Install PHP
RUN apt-get update && apt-get install -y \
    curl \
    zlib1g-dev \
    libzip-dev \
    nano

# Add and Enable PHP-PDO Extenstions
RUN docker-php-ext-install mysqli pdo pdo_mysql
RUN docker-php-ext-enable pdo_mysql
RUN docker-php-ext-install zip

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

#set our application folder as an environment variable
ENV APP_HOME /var/www/html

#change uid and gid of apache to docker user uid/gid
RUN usermod -u 1000 www-data && groupmod -g 1000 www-data

COPY --chown=www-data:www-data . $APP_HOME

#Expose Port 8000 since this is our dev environment
EXPOSE 8000

My Docker-Compose:我的 Docker-Compose:

version: "3.7"
services: 
    #Laravel App
    web:
        build:
            context: .
            dockerfile: Dockerfile
        ports:
            - 8000:80
        volumes:
            - ./:/var/www
            - ./public:/var/www/html
        networks:
            - mynet
        depends_on: 
            - db

    #MySQL Service
    db:
        image: mysql:5.7
        container_name: db
        ports:
            - 3306:3306
        environment:
            MYSQL_DATABASE:
            MYSQL_USER: 
            MYSQL_PASSWORD: 
            MYSQL_ROOT_PASSWORD: 
        volumes:
            - mysqldata:/var/lib/mysql/
        networks:
            - mynet

#Docker Networks
networks:
    mynet:
        driver: bridge
#Volumes
volumes:
    mysqldata:
        driver: local

When I try to access to http:localhost:8000/ I can do it but if I try to access to another route I get the error.当我尝试访问 http:localhost:8000/ 时,我可以做到,但是如果我尝试访问另一条路由,则会出现错误。

在此处输入图片说明

You have to configure the apache2.conf in /etc/apache2/apache2.conf from Dockerfile, and also a2endmode rewrite , finally you need to restart apache2:您必须从Dockerfile中配置/etc/apache2/apache2.conf的apache2.conf,以及a2endmode rewrite ,最后您需要重新启动apache2:

RUN sed -i '/<Directory \/var\/www\/>/,/<\/Directory>/ s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
RUN a2enmod rewrite
RUN service apache2 restart

Then run docker-compose build and docker-compose up -d然后运行docker-compose builddocker-compose up -d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM