To install the project, run the following commands:
-
Install PHP dependencies:
composer install
-
Install JavaScript dependencies:
npm install
-
Start the development environment:
./vendor/bin/sail up
-
Start Vite
npm run dev
or
npm run build
for prod enviroment
This document provides instructions for resolving common permission issues and database connection errors in Laravel running with Docker and Sail.
Sometimes, permission issues can arise when accessing the storage
and bootstrap/cache
directories in Laravel while using Docker. Follow these steps to resolve the problem:
-
Launch a bash session as the root user for the container:
./vendor/bin/sail exec -u root laravel.test bash
-
Change the ownership of the
storage
andbootstrap/cache
directories to thesail
user:chown -R sail:sail /var/www/html/storage chown -R sail:sail /var/www/html/bootstrap/cache
-
Update the directory permissions for
storage
andbootstrap/cache
to allow write access:chmod -R 775 /var/www/html/storage chmod -R 775 /var/www/html/bootstrap/cache
-
Verify the current permissions for these directories:
ls -la /var/www/html/storage ls -la /var/www/html/bootstrap/cache
If you encounter the following database connection error:
SQLSTATE[HY000] [2002] Connection refused
This error is usually caused by an incorrect DB_HOST
value in the .env
file. Follow these steps to fix it:
-
Inspect the Docker network to find the IP address used for the network bridge:
docker network inspect bridge
-
Find the line with the
Gateway
parameter, which will look something like this:"Gateway": "172.17.0.1"
-
Copy the Gateway value and replace the
DB_HOST
value in your.env
file with it, so the database connection will look like this:DB_HOST=172.17.0.1
-
After completing these steps, restart your containers and check if the database connection issue has been resolved.