Z
Z
ZaurK2018-07-01 13:35:10
Yii
ZaurK, 2018-07-01 13:35:10

How to raise yii2 on docker?

Good day! I just can’t master this bunch of yii2 + docker. I switched to ubuntu and everything seems to be fine. I can create images and run containers, but I can’t figure out how to tie it all together and bring it to mind. I rummaged through many articles and books, something is described everywhere, but I stumble upon some mistakes and get stuck on it. Who lifted yii2 basic or advanced on the docker, please direct me to the right path, where it is described clearly and accessible? Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SteepZero, 2018-10-30
@SteepZero

Read about docker-compose
In the project, you create a docker-compose.yml file, describe your containers there, a
separate container for nginx, a separate container for php-fpm, a separate container for the database. You configure
volumes for them, etc.
Here is an example of how I do it for Laravel
For Yii, everything is about the same
docker-compose.yml:

version: '3'

services:
  nginx:
    image: nginx:latest
    ports:
      - 80:80
    volumes:
      - ./:/var/www/html
      - ./docker/nginx/conf.d:/etc/nginx/conf.d
      - ./docker/nginx/logs:/var/log/nginx/
  php:
    image: php:7.2-fpm
    volumes:
      - ./:/var/www/html
  db:
    image: mysql:latest
    environment:
      MYSQL_DATABASE: labbit
      MYSQL_ROOT_PASSWORD: rootlabbit
      MYSQL_USER: labbit
      MYSQL_PASSWORD: labbit
    ports:
      - 3306:3306
    volumes:
      - db_data:/var/lib/mysql

  redis:
    image: redis:latest
volumes:
  db_data:

docker/nginx/conf.d/site.conf:
server {
    listen 80;
    listen [::]:80;

    server_name labbit.local www.labbit.local;

    root /var/www/html/public/;
    index index.php;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    location / {
        root /var/www/html/public/;
        try_files $uri $uri/ /index.php$is_args$args;
        autoindex off;
        index index.php;
    }

    location ~ \.php$ {
        set $path_info $fastcgi_path_info;
        root /var/www/html/public/;
        fastcgi_index index.php;
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        try_files $uri $uri/;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass php:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question