0

I am trying to setup the PHP, MYSQL, NGINX using Docker . I followed the udemy tutorial by Maximillian and my kept all my docker files in a dockerfiles folder.

The php.dockerfile is as follows:

FROM php:8.0-fpm-alpine

WORKDIR /var/www/html

COPY src .

RUN docker-php-ext-install pdo pdo_mysql

My nginx.dockerfile is :

FROM nginx:stable-alpine

WORKDIR /etc/nginx/conf.d

COPY nginx/nginx.conf .

RUN mv nginx.conf default.conf

WORKDIR /var/www/html

COPY src .

And composer file is:

FROM composer:latest
 
WORKDIR /var/www/html
 
ENTRYPOINT [ "composer" ]

The docker-compose.yaml file is :

version: '2.2'

services:
  server:
    # image: 'nginx:stable-alpine'
    build:
      context: .
      dockerfile: dockerfiles/nginx.dockerfile
    ports:
      - '8000:80'
    volumes:
      - ./src:/var/www/html
      - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
    # depends_on:
    #   - php
    #   - mysql
  php:
    build:
      context: .
      dockerfile: dockerfiles/php.dockerfile
    volumes:
      - ./src:/var/www/html:delegated
  mysql:
    image: mysql:5.7
    env_file:
      - ./env/mysql.env
  composer:
    build:
      context: ./dockerfiles
      dockerfile: composer.dockerfile
    volumes:
      - ./src:/var/www/html
  artisan:
    build:
      context: .
      dockerfile: dockerfiles/php.dockerfile
    volumes:
      - ./src:/var/www/html
    entrypoint: ['php', '/var/www/html/artisan']
  npm:
    image: node:14
    working_dir: /var/www/html
    entrypoint: ['npm']
    volumes:
      - ./src:/var/www/html


nginx.conf file is :

server {
    listen 80;
    index index.php index.html;
    server_name localhost;
    root /var/www/html/public;
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

But When I run the following command :

docker-compose up --build server php mysql

After the command :


docker-compose run --rm composer create-project --prefer-dist laravel/laravel .

I get this Facade error . I went through all the Questions in stack over flow that has this error but I couldn't find the resolution even after hours of searching as I am new to both docker and PHP. Please help me setting up this application. Error screenshot is as follows :

A facade root has not been set

  • Intially I got some permission denied error for a folder called storage and when I gave chmod 777 permission that error has gone and then I got this Facade error. – React Learner Sep 09 '22 at 18:58
  • A bunch of suggestions here, https://stackoverflow.com/questions/35418810/eloquent-error-a-facade-root-has-not-been-set – waterloomatt Sep 09 '22 at 19:01
  • @waterloomatt none of those answers helped. The questions and answeres in the link you suggested are for already running applications, but mine is a fresh application on which I haven't written any custom code. – React Learner Sep 09 '22 at 19:43
  • Any errors in `storage/logs/laravel.log`? – waterloomatt Sep 09 '22 at 23:52
  • @waterloomatt laravel.ERROR: syntax error, unexpected token ")" {"exception":"[object] (ParseError(code: 0): syntax error, unexpected token \")\" at /var/www/html/vendor/symfony/finder/Finder.php:588) [stacktrace] #0 /var/www/html/vendor/composer/ClassLoader.php(428): Composer\\Autoload\\includeFile('/var/www/html/v...') #1 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php(86): Composer\\Autoload\\ClassLoader->loadClass('Symfony\\\\Compone...') #2 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/LoadConfiguration – React Learner Sep 20 '22 at 04:47

1 Answers1

0

At last I found that we need run the laravel with version 8 and for me the command is : docker-compose run --rm composer create-project --prefer-dist laravel/laravel=8 . --> to build the docker image

and finally docker-compose up server.

You need to have the permission of the entire working folder to make the modifications.