What is this?

When more than one developer or machine are needed for development, repository like Git makes the task easier. This article explains how to add new machine or a new developer to your development team while using Laravel Sail/Docker.

1. Clone the repository to your local machine

You can clone the repository with the command below. URL can be obtained from the repository.

git clone URL

2. Create .env file

Copy .env file from .env.example or get it from your original project.

cp .env.example .env 

3. Install Composer packages.

Permission & Ownership

Permission of 777 is not recommended. However, it is easier to change to 777 and change back to 775 if error occurs for storage or bootscrap/cache directories.

sudo chown -R $(id -u):$(id -g) storage bootstrap/cache && \
sudo chmod -R 777 storage  bootstrap/cache

sudo chown -R $(id -u):$(id -g) storage  bootstrap/cache && \
sudo chmod -R 775 storage  bootstrap/cache

Install Composer packages by running Docker command below to keep the version correct. Or you can run composer install from your local machine if it does not work it is recommended to install with local composer first

composer install

OR “composer update” might be needed. You may install the application’s dependencies by navigating to the application’s directory and executing the following command. This command uses a small Docker container containing PHP and Composer to install the application’s dependencies:

mkdir -p vendor && docker run --rm \
    -u "$(id -u):$(id -g)" \
    -v "$(pwd):/var/www/html" \
    -w /var/www/html \
    laravelsail/php83-composer:latest \
    composer install --ignore-platform-reqs

https://laravel.com/docs/11.x/sail#installing-composer-dependencies-for-existing-projects

In Linux, xml writer might be needed. It can be installed as

sudo apt-get install php-xml

4 Install npm packages and run dev.

npm packages should be installed and npm run dev is necessary to compile assets.

$npm install
$npm run dev

OR

$sail npm install
$sail npm run dev

5. Sail build with

Sail build is not required, however, it can be excuted when errors occur.

sail down
sail build --no-cache
sail up -d

6 Generate Application key

Laravel application key is needed.

sail artisan key:generate

7 Migarate Database

Database can be created with migration

sail artisan migrate

Debugging & Useful commands

In case you encounter some errors. Some commands below might help to debug.

sail artisan config:clear
sail artisan cache:clear

Set permissions

find . -type d -exec chmod 775 {} \;
find . -type f -exec chmod 664 {} \;

Access docker shell

sail exec laravel.test bash

Deploying on local machine Without Sail

php artisan serve
php artisan serve --host=0.0.0.0 --port=8080