はじめに
dockerでphp + apache + mariadb の環境を構築して、 phpmyadmin、xdebugおよびcomposerを使ってphpunitをインストールします
[下記のgithubリポジトリ](https://github.com/jyef/project) ## ディレクトリ構成 ``` ├── composer.json ├── docker-compose.yml ├── db └── my.cnf ├── html │ ├── index.php │ ├── sample.php │ ├──tests │ └── sampleTest.php ├── php ├── Dockerfile └── php.ini ``` ## docker-compose.yml ``` version: "3"services:
php:
build: ./php/
tty: true
stdin_open: true
volumes:
- ./php/php.ini:/usr/local/etc/php/php.ini
- ./:/var/www/
ports:
- 80:80
db:
image: mariadb:latest
environment:
MYSQL_ROOT_PASSWORD: root
TZ: 'Asia/Tokyo'
volumes:
- ./db/data:/var/lib/mysql
- ./db/my.cnf:/etc/mysql/conf.d/my.cnf
ports:
- 3306:3306
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
- PMA_ARBITRARY=1
- PMA_HOST=db
- PMA_USER=root
- PMA_PASSWORD=root
depends_on:
- db
ports:
- 8080:80
volumes:
- "./phpmyadmin/sessions:/sessions"
## composer.json
{
"require-dev": {
"phpunit/phpunit": "^9.0"
},
"scripts": {
"test": [
"phpunit"
]
},
"autoload": {
"psr-4": {
"App\": "html/"
}
}
}
## phpフォルダ
### Dockerfile
FROM php:7.4.3-apache
RUN apt-get update && apt-get install -y
mariadb-client vim zip
&& pecl install xdebug
&& docker-php-ext-enable xdebug
&& docker-php-ext-install pdo_mysql
&& apt-get clean
install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
WORKDIR /var/www
### php.ini
[Date]
date.timezone = "Asia/Tokyo"
[mbstring]
mbstring.internal_encoding = "UTF-8"
mbstring.language = "Japanese"
[xdebug]
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_host = "host.docker.internal"
xdebug.remote_port=9000
xdebug.remote_log = /var/log/xdebug.log
## dbフォルダ
### my.cnf
[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
default_authentication_plugin=mysql_native_password
[client]
default-character-set=utf8mb4
## htmlフォルダ
<p>以下は接続テスト用、phpunitの動作チェック用のファイルです</p>
### index.php