Skip to content

Repository files navigation

laravel-apache.dev

Laravel + Apache + MySQL development environment with Docker and Docker Compose. Based on a dev.to Article and Laravel + Apache + Docker by veevidify.

Status

GitHub license

Contents:

Requirements

Versions included in this template

  • PHP: 8.3-apache (via laravel-apache/dev:latest)
  • MySQL: 8.0 (via mysql:8.0)
  • phpMyAdmin: 5.2.2 (via phpmyadmin/phpmyadmin:5.2.2)
  • Composer: latest (copied into the PHP container)

Usage

Up and Running

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 app db

Copy env.example to .env and modify it to your needs:

cp env.example .env

Build the images and start the services:

docker compose build --no-cache
docker compose up -d

Setup Laravel Project

In this template, the app/ folder is ignored by Git. When creating a new project, Laravel should be installed inside this folder in your local clone.

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_CONNECTION=mysql
DB_HOST=mysql-db
DB_PORT=<MYSQL_PORT>
DB_DATABASE=laravel
DB_USERNAME=dbuser
DB_PASSWORD=secret

Fix permissions:

./fix-permissions

Initialize Laravel:

./php-artisan key:generate
./php-artisan migrate
./php-artisan config:cache

NOTE: To regenrate DB use ./php-artisan migrate:fresh --seed

The project can be accessed at http://localhost:<APP_PORT>

phpMyAdmin

You can also visit http://localhost:<PHPMYADMIN_PORT> to access phpMyAdmin after starting the containers.

The default username is root, and the password is the same as supplied in the .env file.

Helper Scripts

composer

Run any composer command inside the ${PROJECT_NAME}-app container, example:

./composer create-project laravel/laravel .
./composer dump-autoload

container

The ./container script is a helper utility to interact with the ${PROJECT_NAME}-app container.

When executed without arguments, it opens an interactive shell inside the container as user devuser (UID 1000), matching the host user to avoid permission issues.

./container

This gives you a Bash session inside the application container.

You can also pass any command as arguments to execute it directly inside the container:

./container vendor/bin/pint
./container ls -al

All commands are executed as devuser inside the ${PROJECT_NAME}-app container.

This ensures consistency with the containerized environment and avoids relying on host-installed tools.

database

Running ./database will connect to your ${PROJECT_NAME}-db container's daemon using mysql client.

database_backup

Run ./database_backup to backup your database inside the ${PROJECT_NAME}-db container's daemon using mysqldump client. The backup file will be stored inside the ./backup folder as <DB_DATABASE>_backup_YYYYMMDD_HHMMSS.sql.

./database_backup

fix-permissions

Running ./fix-permissions will fix storage and bootstrap/cache permissions in /var/www/html folder inside the container.

php-artisan

Running ./php-artisan will take you inside the ${PROJECT_NAME}-app container and run any php artisan command, example:

./php-artisan make:controller BlogPostController --resource

phpunit

Run ./vendor/bin/phpunit to execute tests inside the ${PROJECT_NAME}-app container, example:

./phpunit --group=failing

Bugs and Issues

Have a bug or an issue with this template? Open a new issue here on GitHub.

License

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.

About

Laravel + Apache + MySQL development environment with Docker and Docker Compose.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages