A modern Docker setup for Laravel 12 with PHP 8.3, Apache, and MySQL 8.0.
This project provides a complete Docker environment for developing Laravel 12 applications with:
- PHP 8.3 - PHP version with full support for modern PHP features
- Laravel 12 - Latest Laravel framework with modern structure
- Apache 2.4 - Web server with mod_rewrite enabled
- MySQL 8.0.23 - Database server
- Docker Compose - Container orchestration
- Docker Desktop or Docker Engine
- Docker Compose
- Composer (for local development)
# Clone the repository
git clone <repository-url>
cd docker-laravelNote: You do NOT need to run
composer installlocally. The Docker container is self-sufficient and will install all PHP dependencies during the build process with PHP 8.3.
# Copy example environment file
cp .env.example .envThe docker-run.sh script provides an interactive way to manage containers:
bash docker-run.shThen select:
- Environment: Choose between
dev(development) orprod(production) - Action: Choose between
build,start, orshutdown
This script handles all docker compose commands with proper environment variable configuration.
If you prefer manual commands, you need to source the .env file first:
# Source environment variables and use the compose file in docker/ directory
set -a
. .env
set +a
export ENVIRONMENT=dev # or 'prod'
# Build images (first time, use --no-cache for clean build)
docker compose -f docker/docker-compose.override.yml build --no-cache
# Start containers
docker compose -f docker/docker-compose.override.yml up -d
# View logs
docker compose -f docker/docker-compose.override.yml logs -f
# Stop containers
docker compose -f docker/docker-compose.override.yml downTip: The
docker-run.shscript handles all of this automatically, so Option A is recommended.
Open your browser and visit: http://localhost:8080
This project uses Laravel 12's modern structure:
├── bootstrap/
│ └── app.php # Application bootstrapping (fluent configuration)
├── app/
│ ├── Http/
│ │ ├── Middleware/ # HTTP middleware (TrustHosts, etc.)
│ │ ├── Controllers/ # Application controllers
│ ├── Models/ # Eloquent models
│ └── Providers/ # Service providers
├── routes/
│ ├── web.php # Web routes
│ ├── api.php # API routes
├── resources/
│ ├── views/ # Blade templates
│ ├── css/ # CSS files
│ └── js/ # JavaScript files
├── storage/
│ ├── app/ # Application storage
│ ├── logs/ # Application logs
│ └── framework/ # Framework cache
├── tests/ # Test files
├── docker-compose.yml # Container configuration
└── composer.json # PHP dependencies
- No Kernel.php: Middleware configuration moved to
bootstrap/app.php - Fluent Configuration: Application bootstrapping uses fluent API
- Modern PHP: Requires PHP 8.1+ with support for recent language features
- Updated Packages: All dependencies updated to Laravel 12 compatible versions
# Start containers in background
docker compose up -d
# View running containers
docker compose ps
# View logs
docker compose logs web # Web container logs
docker compose logs db # Database container logs
docker compose logs -f # Follow logs
# Execute commands in containers
docker exec docker-laravel-web php artisan migrate
docker exec docker-laravel-web php artisan tinker
# Access container shell
docker exec -it docker-laravel-web bash
docker exec -it docker-laravel-mysql bash# Run migrations
docker exec docker-laravel-web php artisan migrate
# Seed database
docker exec docker-laravel-web php artisan db:seed
# Access MySQL console
docker exec -it docker-laravel-mysql mysql -uroot -p# Restart containers
docker compose restart
# Remove and rebuild containers
docker compose down
docker compose up -d --build
# Clear Laravel cache
docker exec docker-laravel-web php artisan cache:clear
docker exec docker-laravel-web php artisan config:clear
docker exec docker-laravel-web php artisan view:clearKey Docker-related variables:
| Variable | Default | Description |
|---|---|---|
DOCKER_WEB_PORT_NUMBER |
8080 | Port to access the website |
DOCKER_WEB_CONTAINER_NAME |
docker-laravel-web | Web container name |
DOCKER_DB_CONTAINER_NAME |
docker-laravel-mysql | Database container name |
DOCKER_BUILD_OS |
ubuntu | Operating system for web container |
DOCKER_BUILD_OS_VERSION |
24.04 | Ubuntu version (24.04 includes PHP 8.3) |
DOCKER_BUILD_MYSQL_VERSION |
8.4 | MySQL version |
DB_CONNECTION=mysql
DB_HOST=db # Service name from docker-compose.yml
DB_PORT=3306
DB_DATABASE=fff
DB_USERNAME=root
DB_PASSWORD=<your-password>docker/
├── apache/
│ └── apache.conf # VirtualHost configuration
├── mysql/
│ ├── Dockerfile # MySQL image configuration
│ ├── my.cnf # MySQL configuration
│ └── docker-entrypoint-initdb.d/
│ └── *.sql # SQL scripts to run on startup
├── php/
│ └── php.ini # PHP configuration (if needed)
└── os/
└── Dockerfile # Web server base image
| Service | Port | URL |
|---|---|---|
| Web (Apache) | 8080 | http://localhost:8080 |
| MySQL | 3306 | localhost:3306 |
Web Container:
- Current directory → /var/www/html
- ./docker/apache/apache.conf → /etc/apache2/sites-available/000-default.conf
- ./storage/logs → /var/log
Database Container:
- ./database/mysql → /var/lib/mysql
- ./storage/logs/mysql → /var/log/mysql- PHP Version: Ubuntu 24.04 includes PHP 8.3 by default, which is required for Laravel 12
- Database Storage: MySQL data is persisted in
./database/mysql/ - Logs: Application and server logs are available in
./storage/logs/ - Git Ignored: Docker MySQL data is in
.gitignoreto avoid committing database files
- Laravel 12 Documentation
- Docker Documentation
- Docker Compose Documentation
- MySQL Docker Hub
- PHP Docker Hub
The Laravel framework is open-sourced software licensed under the MIT license.