Setting up the Docker environment for the yii-framework of the

3r3r1616. In order to quickly raise the working environment there are many ways. One of them is to pick up all the necessary services in the Docker containers. To speed up the creation of new projects on the Yii-framework, I wrote such a small instruction that is used by the developers in our team. 3r3167.
3r3168.  
3r3r1616. At the start you should have docker, docker-compose, php and php-composer. 3r3168.  
Create a folder with a project and a folder in it
docker
. 3r3167. 3r3168.  
mkdir project-dir
cd project-dir && mkdir docker
3r3163. 3r3168.  
3r3r1616. In the folder 3r32323. docker Create a configuration file for our container Dockerfile . 3r3167. 3r3168.  
    # Base image with nginx and php
FROM richarvey /nginx-php-fpm
# We add our web application
ADD app /var /www /app
# Delete the configs of sites that have
there. RUN rm -Rf /etc /nginx /sites-enabled /*
# Add our config
ADD docker /conf /nginx /site.conf /etc/nginx/sites-available/site.conf
# Turn it on
RUN ln -s /etc/nginx/sites-available/site.conf /etc/nginx/sites-enabled/site.conf
3r3163. 3r3168.  
3r3r1616. In the same folder docker we create docker-compose.yml to raise development environment. 3r3167. 3r3168.  
    # The latest version of docker-compose
version: '3'
# Create a common deafult network for all
containers. networks:
default:
driver: bridge
# Create separate containers
services:
# Container with web application
app:
# We collect from Dockerfile
build:
# Root indicate the root of the main project
context: /
dockerfile: ./docker/Dockerfile
# Show outside port 80 3r33333. ports:
- "80:80"
# We connect to a common network with other containers
networks:
- default
# Run only after db
depends_on:
- db
# Link the external source folder inside 3r33332. volumes: 3r33332. - "/app:/var/www/app"
# Also link config for nginx
- "./conf/nginx:/etc/nginx/sites-available"
# A container with a database
db:
image: mysql: latest
# We connect to a common network with other containers
networks:
- default
# Show outside port
ports:
- "3336: 3306"
# Set parameters for initializing the database
environment:
# Password to the database
MYSQL_ROOT_PASSWORD: root
# Created by default DB
MYSQL_DATABASE: yii-template-db
# We link the external folder to store the database
volumes: 3r33332. - "./database:/var/lib/mysql"
3r3163. 3r3168.  
3r3r1616. For nginx create a folder docker /conf /nginx and file 3r3116. site.conf in it. The file may change, depending on how you want to configure nginx on your project. It can be changed locally, since It connects through volume. But do not forget to reboot nginx inside the container: nginx -s reload 3r3167. 3r3168.  
  3r3124. server {3r33333. charset utf-8;
client_max_body_size 128M;
listen 80; ## listen for ipv4
root /var /www /app /frontend /web /;
index index.php;
access_log /var/www/app/log/frontend-access.log;
error_log /var/www/app/log/frontend-error.log;
location /{3r33332. try_files $ uri $ uri //index.php$is_args$args;
}
# uncomment non-existing static files by Yii
#location ~. (js | css | png | jpg | gif | swf | ico | pdf | mov | fla | zip | rar) $ {
# try_files $ uri = 404;
#}
#error_page 404 /404.html;
# deny accessing php files for the /assets directory
location ~ ^ /assets /.*. php $ {
deny all;
}
location ~ .php $ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
fastcgi_pass unix: /var/run/php-fpm.sock;
try_files $ uri = 404;
}
location ~ * /. {
deny all;
}
} 3r3163. 3r3168.  
3r3r1616. All commands are executed from the root folder. 3r3167. 3r3168.  
3r33170.  
We carry out the project creation team composer create-project --prefer-dist yiisoft /yii2-app-advanced app .  
Run the environment. docker-compose -f docker /docker-compose.yml up -d  
Initialize the project. app /init --env = Development --overwrite = All  
Open the file in the editor. app /common /config /main-local.php and fill it with data to connect to the database. In the example we have the root password - root, the database host is db, the database name is yii-template-db.  
Connect to container docker exec -it docker_app_1 bash  
We execute the database migration command php /var /www /app /yii migrate  
Create a folder for logs mkdir /var /www /app /log  
And exit exit  
Braking service docker-compose -f docker /docker-compose.yml down  
We start it again docker-compose -f docker /docker-compose.yml up -d
 
Open
localhost
in the browser and look at the new site.
 
! function (e) {function t (t, n) {if (! (n in e)) {for (var r, a = e.document, i = a.scripts, o = i.length; o-- ;) if (-1! == i[o].src.indexOf (t)) {r = i[o]; break} if (! r) {r = a.createElement ("script"), r.type = "text /jаvascript", r.async =! ? r.defer =! ? r.src = t, r.charset = "UTF-8"; var d = function () {var e = a.getElementsByTagName ("script")[0]; e.parentNode.insertBefore (r, e)}; "[object Opera]" == e.opera? a.addEventListener? a.addEventListener ("DOMContentLoaded", d,! 1): e.attachEvent ("onload", d ): d ()}}} t ("//mediator.mail.ru/script/2820404/"""_mediator") () (); 3r33232.
+ 0 -

Add comment