A pretty simplified Docker Compose workflow that sets up a LAMP (Linux, Apache ,MySQL, PHP) network of containers for local Laravel development or php projects with Apache.
Ports used in the project:
Software | Port |
---|---|
php-apache | 80 |
mysql | 3306 |
xdebug | 9000 |
To get started, make sure you have Docker installed on your system and Docker Compose, and then clone this repository.
-
Clone this project:
git clone https://github.com/rafaeljurkfitz/docker-php-apache-mysql.git
-
Inside the folder
docker-php-apache-mysql
and Generate your own.env
to docker compose with the next command:cp .env.example .env
-
You need Create or Put your laravel project in the folder
src
; to create follow the next instructions Here. -
Build the project whit the next commands:
docker-compose up --build -d
The configuration of the database must be the same on both sides .
# .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=db_user
DB_PASSWORD=db_password
DB_ROOT_PASSWORD=secret
# src/.env
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=db_user
DB_PASSWORD=db_password
The only change is the DB_HOST
in the src/.env
where is called to the container of mysql
:
# source/.env
DB_HOST=mysql