Skip to content

Instantly share code, notes, and snippets.

@phuongdev89
Last active October 27, 2023 16:40
Show Gist options
  • Save phuongdev89/d13a19010f535cf08fe59fc51cc3d7fa to your computer and use it in GitHub Desktop.
Save phuongdev89/d13a19010f535cf08fe59fc51cc3d7fa to your computer and use it in GitHub Desktop.
Yii2 Advanced + docker

Usage

Start

docker compose up -d

Stop

docker compose down

Nginx

login to phpmyadmin and create db nginx_proxy_manager
create folder storage at root app

Access terminal

Frontend

docker exec -it frontend bash

Backend

docker exec -it backend bash

Console

use backend or frontend as you want

Web interface

FE: http://localhost:20080

BE: http://localhost:21080

phpmyadmin: http://localhost:28080

phpredisadmin: http://localhost:28081

nginxproxy: http://localhost:60080

Email: [email protected]
Password: changeme

# Change PHP version as you want
FROM yiisoftware/yii2-php:7.4-apache
RUN install-php-extensions redis gmp
RUN sed -i -e 's|/app/web|/app/backend/web|g' /etc/apache2/sites-available/000-default.conf
<?php
use yii\db\Connection as MysqlConnection;
use yii\redis\Connection as RedisConnection;
return [
'components' => [
'db' => [
'class' => MysqlConnection::class,
'dsn' => 'mysql:host=mysql;dbname=yii2_advanced',
'username' => 'root',
'password' => 'mysql', //todo change mysql password
'charset' => 'utf8',
],
'redis' => [
'class' => RedisConnection::class,
'hostname' => 'redis',
'port' => 6379,
'password' => 'redis' //todo change redis password
],
],
];
version: '3.2'
services:
mysql:
container_name: mysql
image: mariadb:10.6
restart: always
command: --transaction-isolation=READ-COMMITTED --log-bin=binlog --binlog-format=ROW
environment:
- MYSQL_ROOT_PASSWORD=mysql # todo change mysql password
ports:
- "23306:3306"
volumes:
- ./storage/mysql:/var/lib/mysql
redis:
container_name: redis
image: bitnami/redis
restart: always
environment:
- REDIS_PASSWORD=redis # todo change redis password
ports:
- "26379:6379"
frontend:
depends_on:
- mysql
- redis # todo remove if not needed
links:
- mysql
- redis # todo remove if not needed
container_name: frontend
restart: always
build: frontend
ports:
- "20080:80"
volumes:
- ~/.composer-docker/cache:/root/.composer/cache:delegated
- ./:/app
backend:
depends_on:
- mysql
- redis # todo remove if not needed
links:
- mysql
- redis # todo remove if not needed
container_name: backend
restart: always
build: backend
ports:
- "21080:80"
volumes:
- ~/.composer-docker/cache:/root/.composer/cache:delegated
- ./:/app
phpmyadmin:
container_name: phpmyadmin
depends_on:
- mysql
links:
- mysql
image: phpmyadmin/phpmyadmin
restart: always
ports:
- "28080:80"
environment:
- PMA_ARBITRARY=1
- PMA_HOST=mysql
- PMA_PORT=3306
- PMA_USER=root
- PMA_PASSWORD=mysql # todo change mysql password
- UPLOAD_LIMIT=100M
phpredisadmin:
container_name: phpredisadmin
image: erikdubbelboer/phpredisadmin:latest
restart: always
depends_on:
- redis
ports:
- "28081:80"
environment:
REDIS_1_HOST: redis
REDIS_1_NAME: yii2_redis # name of this redis instance, any name as you want
REDIS_1_AUTH: redis # todo change redis password
ADMIN_USER: admin # todo change phpredis login username
ADMIN_PASS: 123456 # todo change phpredis login password
nginx:
container_name: nginx
image: jc21/nginx-proxy-manager:latest
links:
- mysql
restart: always
ports:
- '80:80'
- '60080:81'
- '443:443'
volumes:
- ./storage/nginx/data:/data
- ./storage/letsencrypt:/etc/letsencrypt
environment:
DB_MYSQL_HOST: mysql
DB_MYSQL_PORT: 3306
DB_MYSQL_USER: root
DB_MYSQL_PASSWORD: mysql # todo change mysql password
DB_MYSQL_NAME: nginx_proxy_manager
# Change PHP version as you want
FROM yiisoftware/yii2-php:7.4-apache
RUN install-php-extensions redis gmp
RUN sed -i -e 's|/app/web|/app/frontend/web|g' /etc/apache2/sites-available/000-default.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment