0

I have written below dockerFile

FROM php:8.0-apache
WORKDIR /var/www/html
# Mod Rewrite
RUN a2enmod rewrite
# Linux Library
RUN apt-get update -y && apt-get install -y \
    libicu-dev \
    libmariadb-dev \
    unzip zip \
    zlib1g-dev \
    libpng-dev \
    libjpeg-dev \
    libfreetype6-dev \
    libjpeg62-turbo-dev \
    libpng-dev 
# Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# PHP Extension
RUN docker-php-ext-install gettext intl pdo_mysql gd
RUN docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg \
    && docker-php-ext-install -j$(nproc) gd

and in docker-compose file I have 3 services , laravel app, mysql and pgadmin

services:
  
  inventory:
    container_name: laravel-app
    build: .
    volumes:
      - ./laravel-app:/var/www/html
    ports:
      - 9000:80
 
  mysql_db:
    image: mysql:latest
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: invoice
    volumes:
      - ./DB/invoice.sql:/docker-entrypoint-initdb.d/invoice.sql
    ports:
    - 3306:3306

  phpmyadmin:
    image: phpmyadmin:latest
    restart: always
    ports:
      - 9001:80
    environment:
      - PMA_ARBITRARY=1

After build in localhost:9000 I'm getting 403 Forbidden. But localhost:9000/public I'm getting laravel home page. How can I run this app in localhost:9000 rather then localhost:9000/public ?

http://localhost:9000/public/ enter image description here

http://localhost:9000/

enter image description here

Niloy Rony
  • 602
  • 1
  • 8
  • 23
  • You have to modify the `apache` site to use `/var/www/html/public` as `DocumentRoot`, but I have never used `php:8.0-apache`, just `php:8.0-fpm` so I have no idea how you do that (if you can using the environment config or you need to manually do that change) – matiaslauriti Oct 19 '22 at 18:49
  • As a suggestion, [Laradock](https://github.com/Laradock/laradock) provides a full PHP development environment for Docker and does exactly what you want. It is much more painless compared to writing a Dockerfile. Best! – Ebi Oct 19 '22 at 20:46

1 Answers1

0

You need to create .htaccess file in the /var/www/html directory with the following content

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]

More here for Reference: Laravel 5 – Remove Public from URL

Edit:

If you don't want to introduce/update the .htaccess file, you may choose to put a reverse proxy, such as nginx in front of your laravel as explained here:

https://blog.quickadminpanel.com/laravel-public-folder-how-to-configure-domains-for-in-apachenginx/

Rakesh Gupta
  • 3,507
  • 3
  • 18
  • 24
  • Thank you for your answer, Can we make this change in docker end rather then change in htaccess ? – Niloy Rony Oct 20 '22 at 05:26
  • If you don't want to use htaccess, you will have to put a reverse proxy (nginx or similar) in front of your laravel that will add /public to every request doing into your laravel. – Rakesh Gupta Oct 21 '22 at 20:22