Skip to content

Commit

Permalink
Доработка ДЗ
Browse files Browse the repository at this point in the history
  • Loading branch information
levitanoff committed Feb 25, 2024
1 parent ee5b6dc commit be48145
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DB_USER=docker
DB_PASSWORD=secret
DB_ROOT_PASSWORD=secret
DB_DATABASE=test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea
.env
/vendor
/homestead
/data/mysql/
.vagrant/
aliases
aliases
27 changes: 18 additions & 9 deletions Homestead.yaml
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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()
9 changes: 5 additions & 4 deletions code/app/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br><br>";
echo "MySQL Connected to Docker container: " . $mysqli_connection->get_server_info();
echo "<br><br>";
}

// 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();
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions docker/composer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
4 changes: 2 additions & 2 deletions docker/fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/* # Освобождаем место от мусора

Expand All @@ -19,4 +19,4 @@ WORKDIR /data

VOLUME /data

CMD ["php-fpm"]
CMD ["php-fpm"]

0 comments on commit be48145

Please sign in to comment.