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

kmnurunnabi's avatar

Sail Cannot be run on localhost

Hey there I was building laravel using sail. I set docker and everything I need to run on project. When I start sail using sail up -d command it's show started fine but I cannot see laravel application on localhost instead into docker log i see error:

024-03-23 15:47:11 2024-03-23 09:47:11,879 INFO Set uid to user 0 succeeded
2024-03-23 15:47:11 2024-03-23 09:47:11,914 INFO supervisord started with pid 1
2024-03-23 15:47:12 2024-03-23 09:47:12,930 INFO spawned: 'php' with pid 9
2024-03-23 15:47:13 2024-03-23 09:47:13,937 INFO success: php entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2024-03-23 15:47:18 2024-03-23 09:47:18,145 INFO exited: php (exit status 1; not expected)
2024-03-23 15:47:19 2024-03-23 09:47:19,155 INFO spawned: 'php' with pid 10
2024-03-23 15:47:19 2024-03-23 09:47:19,309 INFO exited: php (exit status 1; not expected)
2024-03-23 15:47:20 2024-03-23 09:47:20,314 INFO spawned: 'php' with pid 11
2024-03-23 15:47:20 2024-03-23 09:47:20,453 INFO exited: php (exit status 1; not expected)
2024-03-23 15:47:22 2024-03-23 09:47:22,458 INFO spawned: 'php' with pid 12
2024-03-23 15:47:22 2024-03-23 09:47:22,568 INFO exited: php (exit status 1; not expected)
2024-03-23 15:47:25 2024-03-23 09:47:25,578 INFO spawned: 'php' with pid 13
2024-03-23 15:47:25 2024-03-23 09:47:25,691 INFO exited: php (exit status 1; not expected)
2024-03-23 15:47:26 2024-03-23 09:47:26,693 INFO gave up: php entered FATAL state, too many start retries too quickly
2024-03-23 15:47:25 Could not open input file: /var/www/html/artisan

my docker-compose.yml file:

services:
    laravel.test:
        build:
            context: ./vendor/laravel/sail/runtimes/8.3
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.3/app
        extra_hosts:
            - 'host.docker.internal:host-gateway'
        ports:
            - '${APP_PORT:-80}:80'
            - '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
        environment:
            WWWUSER: '${WWWUSER}'
            LARAVEL_SAIL: 1
            XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
            XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
            IGNITION_LOCAL_SITES_PATH: '${PWD}'
        volumes:
            - '.:/var/www/html'
        networks:
            - sail
        depends_on:
            - mysql
            - redis
    mysql:
        image: 'mysql/mysql-server:8.0'
        ports:
            - '${FORWARD_DB_PORT:-3306}:3306'
        environment:
            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ROOT_HOST: '%'
            MYSQL_DATABASE: '${DB_DATABASE}'
            MYSQL_USER: '${DB_USERNAME}'
            MYSQL_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ALLOW_EMPTY_PASSWORD: 1
        volumes:
            - 'sail-mysql:/var/lib/mysql'
            - './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
        networks:
            - sail
        healthcheck:
            test:
                - CMD
                - mysqladmin
                - ping
                - '-p${DB_PASSWORD}'
            retries: 3
            timeout: 5s
    redis:
        image: 'redis:alpine'
        ports:
            - '${FORWARD_REDIS_PORT:-6379}:6379'
        volumes:
            - 'sail-redis:/data'
        networks:
            - sail
        healthcheck:
            test:
                - CMD
                - redis-cli
                - ping
            retries: 3
            timeout: 5s
networks:
    sail:
        driver: bridge
volumes:
    sail-mysql:
        driver: local
    sail-redis:
        driver: local

my project location inside /var/www/php/company/[example-project].

Please help me with fix the issue

0 likes
13 replies
gych's avatar

Can you share your DockerFile

kmnurunnabi's avatar

@gych I run php artisan sail:install that generate docker-composer.yml I provided into my question. May be that is the only docker related file of my project..

MohamedTammam's avatar

Try the following:

run chmod -R 777 ./

Then run sail build or sail build --no-cache then run your application again.

ediblemanager's avatar

@MohamedTammam This isn't advisable, even on localhost as it opens up all access, to all users, to do anything they want with the files. If the docker container isn't configured to run only on the local instance, that could potentially give anyone access to everything.

ediblemanager's avatar

@MohamedTammam Yes, but if the local file permissions are wide open and there's any misconfiguration of your docker containers (example: 0.0.0.0:80), then that's open to anyone. Best to not set such wide open and dangerous permissions to reduce attack scopes.

ediblemanager's avatar

This seems telling Could not open input file: /var/www/html/artisan - are you sure you've mounted the directory correctly?

kmnurunnabi's avatar

@ediblemanager I am not sure. Actually my project directory inside /var/www/php/company/. but my volume set into /var/www/html. I am still not sure if it's cause any issue of that.

ediblemanager's avatar

@kmnurunnabi Your docker-compose config shows you mapping the current directory (the one that the docker-compose.yml file is in) into the internal folder /var/ww/html inside the container. That's ok.

Tray2's avatar

I highly recommend using Laravel Herd instead of Sail and Docker.

https://herd.laravel.com/

Couldn't be easier to handle multiple versions of php, node, and if you buy the pro version it will handle the database for you as well.

Please or to participate in this conversation.