Laravel + Apache + MySQL development environment with Docker and Docker Compose. Based on a dev.to Article and Laravel + Apache + Docker by veevidify.
- Latest versions of Docker and Docker Compose installed.
- On Linux you need to add your user to the docker group.
Clone the repo and create the folder structure for the laravel source code:
git clone https://github.com/rolodoom/laravel-apache.dev.git
cd laravel-apache.dev
mkdir -p src run/var
Copy .env.example
to .env
cp .env.example .env
Build the images and start the services:
docker-compose build --no-cache
docker-compose up -d
Create Laravel Project:
./composer create-project laravel/laravel .
Modify Laravel src/.env
file to match your container credentials:
APP_URL=http://localhost:<APP_PORT>
DB_HOST=mysql-db
DB_PORT=<MYSQL_PORT>
DB_DATABASE=laravel
DB_USERNAME=dbuser
DB_PASSWORD=secret
Initialize Laravel:
./composer install
./php-artisan key:generate
./php-artisan migrate
./php-artisan config:cache
NOTE: To regenrate DB use ./php-artisan migrate:fresh --seed
You can also visit http://localhost:8088 to access phpMyAdmin after starting the containers.
The default username is root
, and the password is the same as supplied in the .env
file.
#!/bin/bash
docker exec -it laravel-app bash -c "sudo -u devuser /bin/bash"
Running ./container
takes you inside the laravel-app
container under user uid(1000)
(same with host user)
#!/bin/bash
docker exec -it mysql-db bash -c "mysql -u dbuser -psecret laravel"
Running ./db
will connect to your database container's daemon using mysql client.
#!/bin/bash
args="$@"
command="composer $args"
echo "$command"
docker exec -it laravel-app bash -c "sudo -u devuser /bin/bash -c \"$command\""
Run any composer
command, example:
$ ./composer dump-autoload
#!/bin/bash
args="$@"
command="php artisan $args"
echo "$command"
docker exec -it laravel-app bash -c "sudo -u devuser /bin/bash -c \"$command\""
Run any php artisan
command, example:
$ ./php-artisan make:controller BlogPostController --resource
#!/bin/bash
args="$@"
command="vendor/bin/phpunit $args"
echo "$command"
docker exec -it laravel-app bash -c "sudo -u devuser /bin/bash -c \"$command\""
Run ./vendor/bin/phpunit
to execute tests, example:
$ ./phpunit --group=failing
Have a bug or an issue with this template? Open a new issue here on GitHub.
This code in this repository is released under the MIT license, which means you can use it for any purpose, even for commercial projects. In other words, do what you want with it. The only requirement with the MIT License is that the license and copyright notice must be provided with the software.