An unique development experience using Laravel based on docker-compose workflow with the minimal settings to your local environment.
You can customize everything here. Feel free to modify as you need.
- A supported OS:
- macOS
- Linux
- GIT
- Docker
- macOS: docker-ce-desktop-mac
- Linux: get.docker.com
- Docker Compose
- macOS install guide (Already installed with Docker for Mac)
- Linux: install guide
- nginx (:80)
- backend (:9000)
- mysql (:3306)
- phpmyadmin (:8080)
- redis (:6379)
optional. - redis-commander (:8081)
optional. - mailhog (:1025, :8025)
optional. - minio (:9001, :9080)
optional. - frontend (:3000)
optional. - storybook (:6006)
optional.
Type the follow command in your terminal:
wget https://github.com/1codehappy/laravel-workspace/archive/refs/heads/master.zip
unzip master
rm master.zip
cd laravel-workspace-masterOr
git clone git@github.com:1codehappy/laravel-workspace.gitamqp apcu bcmath calendar decimal exif gd gettext gmp imagick imap intl ldap mailparse memcached mongo mysqli newrelic opcache pcov pdo_mysql pdo_pgsql pcntl rdkafka redis smb soap swoole trader xdebug xlswriter xmlrpc xsl yaml zip
To generate the .env and the docker-compose.yml file for the Laravel Workspace type:
./lws.sh bootstrapThe code above represents the simple structure of .env file.
# User
LWUSER=lws
LWGID=1000 # id -g
LWUID=1000 # id -u
# Laravel configs
BACKEND_VOL=./backend
BACKEND_CMD="composer create-project --prefer-dist laravel/laravel"
BACKEND_PATH=/var/www/html
# Javascript configs
FRONTEND_VOL=./frontend
FRONTEND_CMD="git clone git@<<GIT_REPOSITORY_PATH>>/<<vendor>>/<<project>>"
FRONTEND_PATH=/var/www/html
# PHP configs
FPM_MEMORY_LIMIT=512M
CLI_MEMORY_LIMIT=1G
MAX_UPLOAD_FILE=20M
PHP_LIBS="pdo_mysql redis xdebug"
NEW_RELIC_KEY=
NEW_RELIC_APP_NAME=
NEW_RELIC_AGENT_VERSION=
# Database configs
MYSQL_DATABASE=lws
MYSQL_USERNAME=lws
MYSQL_PASSWORD=secret
MYSQL_ROOT_PASSWORD=secretLWUSER: represents the user's name.LWGID: represents the user's group ID.LWUID: represents the user's ID.
You can change the LWUSER variable as you need. But the other 2 of them need to be configured carefully.
Open a ssh terminal and type:
id -g $(whoami) # LWGID
id -u $(whoami) # LWUID- By default, LWGID/LWUID came with values of Ubuntu fresh install.
- If you have more then one user or use another OS you will need do set correctly to avoid permission issues.
BACKEND_VOL: path to share with the container.BACKEND_CMD: command to install repository (if needed).BACKEND_PATH: repository path inside container.
You need to declare these variables to configure the laravel project path.
FRONTEND_VOL: path to share with the container.FRONTEND_CMD: command to install repository (if needed).FRONTEND_PATH: repository path inside container.
FPM_MEMORY_LIMIT:php_memory_limitconfiguration to web.CLI_MEMORY_LIMIT:php_memory_limitconfiguration to console.MAX_UPLOAD_FILE:max_upload_fileandpost_max_sizeconfiguration to web.PHP_LIBS: PHP/PECL extensions to configure, enable and install them.NEW_RELIC_KEY: New Relic key to authorize the agent.NEW_RELIC_APP_NAME: New Relic application name.NEW_RELIC_AGENT_VERSION: New Relic agent version to download.
Edit your .env file and add the available php extensions that you need. You don't need to know what package is required.
PHP_LIBS="amqp apcu bcmath calendar decimal exif gd gettext gmp imagick imap intl ldap mailparse memcached mongo mysqli newrelic opcache pcov pdo_mysql pdo_pgsql pcntl rdkafka redis smb soap swoole trader xdebug xlswriter xmlrpc xsl yaml zip"MYSQL_DATABASE: database name.MYSQL_USERNAME: database user's name.MYSQL_PASSWORD: database user's passwordMYSQL_ROOT_PASSWORD: database root password.
- The
docker-compose.ymlis generated as a copy ofdocker-compose.yml.example. - The initial is setted up to run a basic laravel application.
Original file:
services:
nginx: # request and deliver content for the backend application.
# ...
backend: # laravel applicaiton.
# ...
composer: # to composer functions.
# ...
artisan: # artisan commands.
# ...
mysql: database container.
# ...
phpmyadmin: visual web IDE for MySQL database.
# ...- The others services are commented by default.
- You can uncomment, modify or add new services to run in development environment.
services:
pestphp: # if you install pestphp you can uncomment it to use the container.
# ...
frontend: # you can use a docker container for the javascript application.
# ... you can modify it and put how it works for you.
storybook: # you can use a docker container for storybook.
# ... you can modify it and put how it works for you.
redis: database container.
# ... You must uncomment the related docker volume at the end of file.
rc: visual web IDE for Redis.
# ...
mailhog: An email service.
# ... Some instructions about how it needs to configure in Laravel are commented.
minio: Simulates a AWS S3 to use with Laravel.
# ... Some instructions about how it needs to configure in Laravel are commented.
# ... You must uncomment the related docker volume at the end of file.- You will see the laravel application created according to the
backendvariables started withBACKEND_prefix at.envfile.
The command below will configure the laravel application:
./lws.sh setup-be- You will see the frontend application created according to the
frontendvariables started withFRONTEND_prefix at.envfile.
The command below will configure the javascript application:
./lws.sh setup-feTo build the docker images, you need to execute the command below:
./lws.sh buildIt takes some time to build. I think you can have a coffee now.
Navigate in your terminal to the directory you cloned this to start all docker containers:
docker-compose up
docker-compose up -d
docker-compose up --buildOr:
./lws.sh start
./lws.sh start -d
./lws.sh start -d --buildTo stop all docker containers, you must execute the command below:
docker-compose downOr:
./lws.sh stopYou can use docker-compose exec backend <<command>>, but there is the Laravel Workspace option to go to shell prompt.
./lws.sh backend # docker-compose exec backend /bin/ash -ilYou can use the artisan commands using docker-compose run --rm composer <<command>> or typing the commands using lws.sh.
./lws.sh composer install
./lws.sh composer update
./lws.sh composer require <<package>>You can use the artisan commands using docker-compose run --rm artisan <<command>> or typing the commands using lws.sh.
./lws.sh artisan
./lws.sh artisan key:generate
./lws.sh artisan migrate
./lws.sh artisan tinkerAs the artisan way, you can use docker-compose exec frontend <<command>>, but there is the Laravel Workspace option to go to shell prompt.
./lws.sh frontend # docker-compose exec frontend /bin/ash -il- Backend application: http://localhost
- Frontend application: http://localhost:3000
optional - Storybook: http://localhost:6006
optional - PHPMyAdmin: http://localhost:8080
- Redis Commander: http://localhost:8081
optional - Mailhog: http://localhost:8025
optional - Minio: http://localhost:9001
optional- user: MEJHLMRWKAZTYMEFSRJL
- password: LBybk6EmwNDGLQztdKkU3DMTVruAWdAEeyDYXwQs
PS: As default you are a regular user in docker container. If you want to install or remove any package, you should use sudo inside backend/frontend containers.
And you can check the container logs, if needed:
./lws.sh logs nginx
./lws.sh logs -f nginx
./lws.sh logs laravel
./lws.sh logs -f laravelType the command below to see all commands:
./lws.shby CodeHappy ;)