forked from docker/awesome-compose
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Laravel Implementation with Docker Compose (docker#344)
Signed-off-by: Hanie Asemi <[email protected]>
- Loading branch information
Showing
5 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Install and Set Up Laravel with Docker Compose | ||
|
||
Setting up Laravel in the local environment with Docker using the LEMP stack that includes: Nginx, MySQL, PHP, and phpMyAdmin. | ||
|
||
## Why use Docker for Development | ||
|
||
- [x] Consistent development environment for the entire team. | ||
- [x] You don't need to install a bunch of language environments on your system. | ||
- [x] You can use different versions of the same programming language. | ||
- [x] Deployment is easy | ||
|
||
## How to Install and Run the Project | ||
|
||
1. ```git clone [email protected]:hanieas/Docker-Laravel.git``` | ||
2. ```cd src``` | ||
3. ```composer install``` | ||
3. Copy ```.env.example``` to ```.env``` | ||
4. ```docker-compose build``` | ||
5. ```docker compose up -d``` | ||
6. You can see the project on ```127.0.0.1:8080``` | ||
|
||
## How to use MySQL as a database | ||
|
||
1. Uncomment the MySQL configuration inside the ```docker-compose.yml``` including: ```db``` and ```phpMyAdmin``` | ||
2. Copy ```.env.example``` to ```.env``` | ||
3. Change ```DB_CONNECTION``` to ```mysql``` | ||
4. Change ```DB_PORT``` to ```3306``` | ||
5. Open the ```phpMyAdmin``` on ```127.0.0.1:3400``` | ||
|
||
## How to use PostgreSQL as a database | ||
|
||
1. Uncomment the PostgreSQL configuration inside the ```docker-compose.yml``` including: ```db``` and ```pgamdin``` | ||
2. Copy ```.env.example``` to ```.env``` | ||
3. Change ```DB_CONNECTION``` to ```pgsql``` | ||
4. Change ```DB_PORT``` to ```5432``` | ||
5. Open the ```pgAdmin``` on ```127.0.0.1:5050``` | ||
|
||
## How to run Laravel Commands with Docker Compose | ||
|
||
1. ```cd src``` | ||
2. ```docker-compose exec app php artisan {your command}``` | ||
|
||
## Medium | ||
|
||
https://medium.com/@hanieasemi/setting-up-a-laravel-local-environment-with-docker-7541ae170daf | ||
|
||
## YouTube | ||
|
||
https://www.youtube.com/watch?v=6ANYowpB910 | ||
|
||
https://www.youtube.com/watch?v=gZfCAIGsz_o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
version: '3.8' | ||
|
||
services: | ||
|
||
# Web Server Service | ||
nginx: | ||
image: nginx:alpine | ||
container_name: nginx | ||
ports: | ||
- "8080:80" | ||
volumes: | ||
- ./src:/var/www | ||
- ./nginx/conf.d/:/etc/nginx/conf.d/ | ||
depends_on: | ||
- app | ||
- db | ||
|
||
# Database Service if you want to use mysql uncomment this service and comment the postgres | ||
# db: | ||
# image : mysql | ||
# container_name : mysql | ||
# volumes: | ||
# - ./mysql/data:/var/lib/mysql | ||
# ports: | ||
# - "3306:3306" | ||
# environment: | ||
# MYSQL_DATABASE: blog | ||
# MYSQL_ROOT_PASSWORD: password | ||
|
||
# Database Service | ||
db: | ||
image: postgres | ||
container_name: postgres | ||
volumes: | ||
- ./postgresql/data:/var/lib/postgresql/data | ||
ports: | ||
- "5432:5432" | ||
environment: | ||
POSTGRES_DB: blog | ||
POSTGRES_USER: root | ||
POSTGRES_PASSWORD: password | ||
|
||
# Application Service | ||
app: | ||
container_name: blog | ||
build: | ||
context: ./php | ||
dockerfile: Dockerfile | ||
volumes: | ||
- ./src:/var/www | ||
ports: | ||
- "9000:9000" | ||
working_dir: /var/www | ||
|
||
# phpMyAdmin Service if you want to mysql uncomment this service and comment the pgadmin | ||
# phpmyadmin: | ||
# image: phpmyadmin/phpmyadmin | ||
# container_name: phpmyadmin | ||
# ports: | ||
# - "3400:80" | ||
# depends_on: | ||
# - db | ||
|
||
# pgAdmin Service | ||
pgadmin: | ||
image: dpage/pgadmin4 | ||
container_name: pgAdmin | ||
ports: | ||
- "5050:80" | ||
depends_on: | ||
- db | ||
environment: | ||
PGADMIN_DEFAULT_EMAIL: [email protected] | ||
PGADMIN_DEFAULT_PASSWORD: password |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
server { | ||
listen 80; | ||
index index.php index.htm index.html; | ||
error_log /var/log/nginx/error.log; | ||
access_log /var/log/nginx/access.log; | ||
server_name localhost; | ||
root /var/www/public; | ||
|
||
location / { | ||
try_files $uri $uri/ /index.php?$query_string; | ||
} | ||
|
||
location /index.php { | ||
try_files $uri = 404; | ||
fastcgi_split_path_info ^(.+\.php)(/.+)$; | ||
fastcgi_pass app:9000; | ||
fastcgi_index index.php; | ||
include fastcgi_params; | ||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | ||
fastcgi_param PATH_INFO $fastcgi_path_info; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
FROM php:8.0.3-fpm | ||
|
||
RUN docker-php-ext-install pdo pdo_mysql | ||
|
||
|
||
RUN apt-get update | ||
|
||
# Install useful tools | ||
RUN apt-get -y install apt-utils nano wget dialog vim | ||
|
||
# Install important libraries | ||
RUN echo "\e[1;33mInstall important libraries\e[0m" | ||
RUN apt-get -y install --fix-missing \ | ||
apt-utils \ | ||
build-essential \ | ||
git \ | ||
curl \ | ||
libcurl4 \ | ||
libcurl4-openssl-dev \ | ||
zlib1g-dev \ | ||
libzip-dev \ | ||
zip \ | ||
libbz2-dev \ | ||
locales \ | ||
libmcrypt-dev \ | ||
libicu-dev \ | ||
libonig-dev \ | ||
libxml2-dev | ||
|
||
RUN echo "\e[1;33mInstall important docker dependencies\e[0m" | ||
RUN docker-php-ext-install \ | ||
exif \ | ||
pcntl \ | ||
bcmath \ | ||
ctype \ | ||
curl \ | ||
iconv \ | ||
xml \ | ||
soap \ | ||
pcntl \ | ||
mbstring \ | ||
tokenizer \ | ||
bz2 \ | ||
zip \ | ||
intl | ||
|
||
# Install Postgre PDO | ||
RUN apt-get install -y libpq-dev \ | ||
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \ | ||
&& docker-php-ext-install pdo pdo_pgsql pgsql |
Empty file.