Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mstdmstd's avatar

How to set url of laravel app under docker without “public”?

Hello, Installing laravel 5.7 app under docker(based on php:7.2-apache ) I need to use "/public" in my url to run my app, so root url of my app is

http://127.0.0.1:8081/public

I modified .env of my laravel app as

APP_URL=http://127.0.0.1:8081/public/

But it did not help, as I browser I got image url :

http://127.0.0.1:8081/storage/mysites/-mysite-16/Babe_ver1.jpg?dt=1546059015

which way is invalid, as valid way must be :

http://127.0.0.1:8081/public/storage/mysites/-mysite-16/Babe_ver1.jpg?dt=1546059015

The similar way with ajax requests, as I got invalid ways :

http://127.0.0.1:8081/admin/get_activity_log_rows/1

But valid must be

http://127.0.0.1:8081/public/admin/get_activity_log_rows/1

In my docker-compose.yml :

version: '3.1'

services:

    web:

        build:
            context: ./web
            dockerfile: Dockerfile.yml

        environment:
            - APACHE_RUN_USER=www-data
        volumes:
            - ${APP_PATH_HOST}:${APP_PTH_CONTAINER}
        ports:
            - 8081:80
        working_dir: ${APP_PTH_CONTAINER}


    composer:
        image: composer:1.8
        volumes:
            - ${APP_PATH_HOST}:${APP_PTH_CONTAINER}
        working_dir: ${APP_PTH_CONTAINER}
        command: composer install

and in .env of docker project :

# PATHS
DB_PATH_HOST=./databases
APP_PATH_HOST=./Mysites
APP_PTH_CONTAINER=/var/www/html/

How to set root url of my site with “/public” ?

Thanks!

0 likes
3 replies
mstdmstd's avatar

I have found valid decision for me at https://github.com/petecoop/docker-laravel I looked that at end of web/Dockerfile.yml there was a line :

COPY virtualhost.conf /etc/apache2/sites-enabled/000-default.conf

and in this 000-default.conf “/public” path and other parameters were written.

Snapey's avatar

Yep, that does not look right.

You should not be copying anything into sites-enabled folder. I suggest you seek a better tutorial.

As mentioned, just set Document Root correctly for the Laravel project public folder and not the Laravel project itself.

Please or to participate in this conversation.