This project sets up a Dockerized PHP development environment with multiple PHP versions, Redis, and MySQL, all managed through docker-compose and environment variables. It's designed to streamline Laravel development by providing a flexible, scalable, and easy-to-use setup.
- Multiple PHP Versions: Easily switch between PHP versions for different projects.
- MySQL and Redis: Pre-configured services to support database and caching requirements.
- Supervisor Support: Automatically manage long-running processes like Laravel WebSockets.
- SSH Access: Secure access to containers for development and debugging.
- Nginx Support: Configured for serving Laravel applications.
- PHP: Multiple PHP versions (7.4, 8.0, 8.1) with Composer and Xdebug.
- Nginx: Web server for serving Laravel applications.
- MySQL: Database service for storing application data.
- Redis: In-memory data structure store for caching.
- workspace: Container for running Composer and Artisan commands.
- Docker
- Docker Compose
- Make
yq
(for parsing YAML files)
-
Clone the repository:
git clone https://github.com/alizaynoune/Laravel-Docker-DevEnv.git cd Laravel-Docker-DevEnv
-
Create and configure the
.env
file:Copy the
.env.example
to.env
and adjust the variables as needed.cp env.example .env
-
Add your sites to the
sitesMap.yaml
file:Copy the
sitesMap.example.yaml
tositesMap.yaml
and adjust the entries as needed.cp sitesMap.example.yaml sitesMap.yaml
Example entry in
sitesMap.yaml
:- map: example.local to: example-app/public php: "8.0"
-
Build and start the containers:
make up
The .env
file contains the following variables:
-
User Configuration:
USER_NAME
(the user name for the container)USER_PASSWORD
(the user password for the container)USER_UID
(the user ID for the container)USER_GID
(the user group ID for the container)ROOT_PASSWORD
-
MySQL Configuration:
MYSQL_ROOT_PASSWORD
(the root password for MySQL)MYSQL_DATABASE
(the default database name)MYSQL_USERNAME
(the default username)MYSQL_PASSWORD
(the default password)
-
Redis Configuration:
REDIS_ARGS
(additional arguments for the Redis service)
-
Directories:
APP_DIR
(the application directory)DESTINATION_DIR
(the destination directory in the container)REDIS_DATA_DIR
(the Redis data directory)MYSQL_DATA_DIR
(the MySQL data directory)
-
Default PHP Version:
DEFAULT_PHP
(the default PHP version for the workspace container)
docker-compose.yml
: Main Docker Compose configuration.docker-compose.override.yml
: This is where the PHP services are defined. (auto-generated), do not edit this file.
The PHP services are configured based on the sitesMap.yaml
file. Each site can specify a different PHP version.
Example entry in sitesMap.yaml
:
- map: example.local
to: example-app/public
php: "8.0"
-
Make Commands:
make up
: Build and start the containers.make down
: Stop and remove the containers.make restart
: Restart the containers.make logs
: Show the container logs.make exec
: Execute a command in the workspace container.
-
Workspace Container:
The workspace container is used for running Composer and Artisan commands.
make exec workspace
-
Run Commands:
composer install php artisan migrate php artisan db:seed
-
Change PHP Version:
php 80 # Switch to PHP 8.0
-