利用docker搭建yii2 詳細步驟

2022-06-03 06:37:22 字數 3272 閱讀 9723

在hub.docker.com 搜尋yii2,並且最後定位到 

codemix/yii2-base 然後在github上開啟 clone 到本地

按照下面步驟操作

composer create-project --no-install codemix/yii2-dockerized myprojectcd myproject

cp docker-compose-example.yml docker-compose.yml

cp .env-example .env

啟動docker 建議加上 -d 引數

docker-compose up

資料庫遷移

docker-compose run --rm web ./yii migrate

把配置修改為自己沒有占用的埠

裡面有 nginx 和 apache 兩個web伺服器可以選擇

執行 docker-compose build

docker-compose up -d

直接訪問本地對應的埠

1 # for *-apache base

image

2# web:

3 # build: ./

4# ports:

5 # - "

8080:80"6

# expose:

7 # - "80"

8# volumes:

9 # - ./:/var/www/html/

10# links:

11 # -db

12# environment:

13 # enable_env_file: 1

14 # enable_localconf: 1

15 # api_token: ""16

17# uncomment to autostart at boottime

18#restart: always

1920

# uncomment to send log output to syslog

21 #log_driver: "

syslog"22

#log_opt:

23 # tag: "

docker-web"24

25 # for *-php-fpm and *-hhvm base

image

2627 build: ./

28expose:

29 - "

9000"30

volumes:

31 - ./:/var/www/html/

32links:

33 -db

34environment:

35 enable_env_file: 1

36 enable_localconf: 1

37 api_token: "

f1528c9bc2181668bc80417e33a7fb79412bf52a"38

39nginx:

40 build: ./nginx

41ports:

42 - "

8083:80"43

links:

45volumes_from:

4748

db:49 image: mysql:5.6

50ports:

51 - "

3308:3306"52

expose:

53 - "

3308"54

environment:

55 mysql_root_password: secret-root

56mysql_database: web

57mysql_user: web

58mysql_password: web

5960

# uncomment to autostart at boottime

61 #restart: always

1 #from codemix/yii2-base:2.0.7-apache

2 from codemix/yii2-base:2.0.7-php-fpm

3 #from codemix/yii2-base:2.0.7-hhvm45

6# composer packages are installed first. this will only add packages

7 # that are not already in the yii2-base

image.

8 copy composer.json /var/www/html/

9 copy composer.lock /var/www/html/

10 run composer self-update --no-progress &&\

11 composer install --no-progress

1213 # copy the working dir to the image'

s web root

14 copy . /var/www/html

1516

# the following directories are .dockerignored to not pollute the docker images

17 # with local logs and published assets from

development. so we need to create

18 # empty dirs and set

right permissions inside the container.

19 run mkdir -p runtime web/assets \

20 && chown www-data:www-data runtime web/assets

2122 # expose everything under /var/www (vendor +html)

23 # this is only required for

the nginx setup

24 volume ["

/var/www

"]

yii2 搭建Swagger 快速搭建(一)

一.安裝擴充套件元件zircote swagger php 專案根目錄底下執行 composer require zircote swagger php 在api web下新建資料夾swageer docs 這個資料夾可以自己命名,沒有強制要求,用來放json檔案的 我這個swagger.json檔...

YII2 搭建redis拓展 教程

安裝redis擴充套件 1.通過composer進行安裝,到專案根目錄cmd執行 推薦 php composer.phar require prefer dist yiisoft yii2 redis或者新增 yiisoft yii2 redis 2.0.0 到對應專案的composer.json檔...

yii2框架 yii2自身的自動載入 三

上一節說完了composer的自動載入,下面我們來說一下yii2自身的自動載入。在我們的入口檔案,例如index.php,如下 comment out the following two lines when deployed to production defined yii debug or d...