Install docker and docker-compose
Note: we need the latest version (read this instruction!)
1.Clone project
$ git clone https://github.com/bscheshirwork/docker-yii2-advanced newproject
2.Start the php
service
$ cd newproject/docker-run
$ docker-compose run php /bin/bash
Creating network "dockerrun_default" with the default driver
Creating dockerrun_db_1
root@abfe3b3ca645:/var/www/html#
Inside the container:
root@abfe3b3ca645:/var/www/html#
2.1.Run composer update
and use github token (see https://github.com/settings/tokens
)
cache folder simply linked into containers
- ~/.composer/cache:/root/.composer/cache
composer update -vv
2.2.Run yii2 init script (0 - Development) to create local settings (see preparing-application 1-3)
./init
2.3.Synchronize db settings (docker-run/docker-compose.yml
, php-data/common/config/main-local.php
; docker-codeception-run/docker-compose.yml
, php-data/common/config/test-local.php
)
php-data/common/config/main-local.php
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=db;dbname=yii2advanced',
'username' => 'yii2advanced',
'password' => 'yii2advanced',
'charset' => 'utf8',
],
For tests we're using the same component db
with the same connection string because we're using
another folder to sync with docker contaner (mysql-data-test
)
php-data/common/config/test-local.php
'db' => [
],
2.4.Run migration
./yii migrate
Note: error?
docker-compose down
andsudo rm -rf ../mysql-data/*
Note: you can use mysqldump (in another terminal) this way:
docker exec dockerrun_db_1 sh -c 'exec mysqldump -uroot -p"$MYSQL_ROOT_PASSWORD" yii2advanced' > /some/path/on/your/host/yii2advanced.sql
2.5.Leave container (exit
, ctrl+c)
3.Run the composition
$ docker-compose up -d
Creating network "dockerrun_default" with the default driver
Creating dockerrun_db_1
Creating dockerrun_php_1
Creating dockerrun_nginx_1
4.See url 0.0.0.0:8080
- frontend, 0.0.0.0:8081
- backend
For xdebug we can use environment
XDEBUG_CONFIG: "remote_host=dev-Aspire-V3-772 remote_port=9001"
PHP_IDE_CONFIG: "serverName=docker-yii2-advanced"
remote_host
can be your IP address (outside of docker network) or your DNS if you have a dns-server (for example - local dns server or dns-server in your router; possibly you have a domain name like your machine name). Docker will connect to this DNS server from the running php container and resolve it.
In
mac OS
you can use docker special namehost.docker.internal
.
PHPStorm settings:
Create new Service named <PHP_IDE_CONFIG value>
Settings > Languages & Frameworks > PHP > Servers: [Name => yii2advanced]
value is equal to serverName
ip
, port
) doesn't matter).
Use path mapping:
Settings > Languages & Frameworks > PHP > Servers: [Use path mapping => True, /your/machine/path/to/php-data => /var/www/html]
Change debug port from 9000 to 9001
Settings > Languages & Frameworks > PHP > Debug: [Debug port => 9001]
remote_port=9001
For existing projects with MySQL 8.0.12
:
docker-compose up -d
docker-compose exec mysql mysql_upgrade -uroot -p
https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-13.html