diff --git a/.env.example b/.env.example
index e69de29bb..ad84b5077 100644
--- a/.env.example
+++ b/.env.example
@@ -0,0 +1,4 @@
+DB_USER=docker
+DB_PASSWORD=secret
+DB_ROOT_PASSWORD=secret
+DB_DATABASE=test
diff --git a/.gitignore b/.gitignore
index c8e27bba7..13c31e50d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
.idea
.env
/vendor
+/homestead
/data/mysql/
.vagrant/
-aliases
\ No newline at end of file
+aliases
diff --git a/Homestead.yaml b/Homestead.yaml
index 7c3f52ce1..8519de5e9 100644
--- a/Homestead.yaml
+++ b/Homestead.yaml
@@ -1,32 +1,41 @@
+---
# Развернуть Homestead VM при помощи Vagrant и VirtualBox
-ip: 192.168.56.56
+ip: "192.168.56.56"
memory: 2048
cpus: 2
provider: virtualbox
+
authorize: ~/.ssh/id_rsa.pub
+
keys:
- ~/.ssh/id_rsa
+
folders: # Должна быть поддержка проброса директорий
-
- map: ./code/homestead
+ map: ./../code/homestead
to: /home/vagrant/code
sites:
-
map: application.local # Сайт должен отвечать на доменное имя application.local
to: /home/vagrant/code
+
databases:
- homestead
-ports:
- - send: 80
- to: 8000
+
features:
- mysql: false
- mariadb: true
- postgresql: false
- ohmyzsh: false
- webdriver: false
+ - influxdb: false
+
services:
- -
- enabled: [mariadb]
-name: dz
-hostname: dz
+ - enabled:
+ - "mariadb"
+
+ports:
+ - send: 33060 # MySQL/MariaDB
+ to: 3306
+ - send: 80
+ to: 8000
diff --git a/README.md b/README.md
index e16b2a49b..846ef7420 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,41 @@
# PHP_2023
https://otus.ru/lessons/razrabotchik-php/?utm_source=github&utm_medium=free&utm_campaign=otus
+
+## Комментарий к домашнему заданию
+
+В домашнем задании использутеся подключение к дувум базам данных MySQL (MariaDB):
+- Docker-контейнер
+- VM Homestead
+
+
+### 1. Запуск docker-контейнеров
+```bash
+$ cp .env.example .env
+$ docker compose up -d
+```
+### 2. Установка виртуальной машины Homestead
+
+```bash
+$ git clone https://github.com/laravel/homestead.git ./homestead
+$ cd ./homestead/
+$ git checkout release
+$ bash init.sh
+$ cp ../Homestead.yaml ./
+$ vagrant up
+```
+### 3. Проверка работоспособности
+**Проверка VM Homestead**
+
+В браузере по адресу: http://application.local:8000/
+Вывод функции phpinfo()
+
+**Проверка Docker**
+
+В браузере по адресу: http://application.local:8080/
+Вывод:
+- Версия Redis
+- Версия Memcache
+- MySQL соединение с Docker-контейнером (весия MariaDB)
+- MySQL соединение с VM Homestead (весия MariaDB)
+- Вывод функции phpinfo()
diff --git a/code/app/index.php b/code/app/index.php
index 7a6e1333f..e1bd33cd1 100644
--- a/code/app/index.php
+++ b/code/app/index.php
@@ -16,16 +16,17 @@
if ($mysqli_connection->connect_error) {
echo "MySQL Not connected, error: " . $mysqli_connection->connect_error;
} else {
- echo "MySQL Connected to Docker container.
";
+ echo "MySQL Connected to Docker container: " . $mysqli_connection->get_server_info();
+ echo "
";
}
// Test MySQL (Homestead)
-$mysqli_homestead_connection = new MySQLi('192.168.56.56', 'homestead', 'secret', 'homestead', 3306);
+$mysqli_homestead_connection = new MySQLi('host.docker.internal', 'homestead', 'secret', 'homestead', 33060);
if ($mysqli_homestead_connection->connect_error) {
- echo "MySQL Connected to Homestead";
-} else {
echo "MySQL Not connected to Homestead, error: " . $mysqli_homestead_connection->connect_error;
+} else {
+ echo "MySQL Connected to Homestead: " . $mysqli_homestead_connection->get_server_info();
}
phpinfo();
diff --git a/docker-compose.yml b/docker-compose.yml
index 1b587604a..0a3fe43ed 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -22,6 +22,8 @@ services:
context: docker/fpm
dockerfile: Dockerfile
image: webserver/app
+ extra_hosts:
+ - "host.docker.internal:host-gateway" # Доступ к хостовой машине по имени host.docker.internal
volumes:
- ./code/app:/data/application.local
- phpsocket:/var/run
diff --git a/docker/composer/Dockerfile b/docker/composer/Dockerfile
new file mode 100644
index 000000000..fc0ea45d5
--- /dev/null
+++ b/docker/composer/Dockerfile
@@ -0,0 +1,13 @@
+FROM php:8.2-cli
+
+WORKDIR /app
+
+RUN apt-get update && apt-get install -y \
+ libzip-dev \
+ zip \
+ && docker-php-ext-install zip \
+ && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
+ && apt-get clean \
+ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* # Освобождаем место от мусора
+
+CMD ["php"]
diff --git a/docker/fpm/Dockerfile b/docker/fpm/Dockerfile
index c99c36759..218b2d071 100644
--- a/docker/fpm/Dockerfile
+++ b/docker/fpm/Dockerfile
@@ -8,7 +8,7 @@ RUN apt-get update && apt-get install -y \
&& docker-php-ext-install -j$(nproc) gd pdo_mysql mysqli \
&& pecl install redis memcache \
&& docker-php-ext-enable redis memcache \
- && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \ # Не забудьте про Composer
+ && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* # Освобождаем место от мусора
@@ -19,4 +19,4 @@ WORKDIR /data
VOLUME /data
-CMD ["php-fpm"]
\ No newline at end of file
+CMD ["php-fpm"]