Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Добавляет файлы задания №1 #614

Open
wants to merge 2 commits into
base: ACheburaev/main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .docker/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM nginx:latest

COPY hosts/application.local.conf /etc/nginx/conf.d/application.local.conf

WORKDIR /www
VOLUME /www
EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
26 changes: 26 additions & 0 deletions .docker/nginx/hosts/application.local.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
server {
listen 80;
server_name application.local;

root /www/application.local;

index index.php index.html;

location ~* .(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires max;
}

location / {
try_files $uri $uri/ /index.php?$query_string;
}

location ~* .php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php8-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
33 changes: 33 additions & 0 deletions .docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM php:8.0-fpm

RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libonig-dev \
libzip-dev \
libmemcached-dev \
libmcrypt-dev \
libpq-dev \
&& pecl install mcrypt-1.0.4 \
&& docker-php-ext-enable mcrypt \
&& docker-php-ext-install -j$(nproc) iconv mbstring pdo pdo_pgsql pgsql zip \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd \
&& pecl install memcache \
&& docker-php-ext-enable memcache \
&& pecl install memcached \
&& docker-php-ext-enable memcached \
&& pecl install redis \
&& docker-php-ext-enable redis \
&& rm /usr/local/etc/php-fpm.d/* \
&& curl -sS https://getcomposer.org/installer > composer-setup.php \
&& php composer-setup.php && rm composer-setup.php* \
&& chmod +x composer.phar && mv composer.phar /usr/bin/composer

COPY application.local.conf /usr/local/etc/php-fpm.d/

WORKDIR /www
VOLUME /www

CMD ["php-fpm"]
19 changes: 19 additions & 0 deletions .docker/php/application.local.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[global]
daemonize = no
error_log = /proc/self/fd/2
log_limit = 8192

[www]
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
catch_workers_output = yes
decorate_workers_output = no
user = www-data
group = www-data
access.log = /proc/self/fd/2
clear_env = no
listen = /var/run/php8-fpm.sock
listen.mode = 0777
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POSTGRES_DB=postgres
POSTGRES_USER=user
POSTGRES_PASSWORD=password
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
*.idea
*.idea
logs
run
data
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
build:
docker-compose -f docker-compose.yml
rebuild:
docker-compose -f docker-compose.yml build --no-cache
start:
docker-compose -f docker-compose.yml up -d
stop:
docker-compose -f docker-compose.yml down
restart:
docker-compose -f docker-compose.yml down
docker-compose -f docker-compose.yml up -d
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# PHP_2022

Cheburaev A.D.
HW 1

Make команды для работы с docker:
- ```make build``` - сборка контейнеров;
- ```make rebuild``` - пересборка контейнеров;
- ```make start``` - запуск контейнеров;
- ```make stop``` - остановка контейнеров;
- ```make restart``` - перезапуск контейнеров.

Для того чтобы сайт открывался по адресу ```application.local``` необходимо указать этот адрес в хостах локальной машины.
Например в Ubuntu так ```127.0.0.1 localhost application.local```
58 changes: 58 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: '3'

services:
nginx:
build:
context: .docker/nginx
dockerfile: Dockerfile
container_name: nginx
ports:
- "80:80"
volumes:
- ./src:/www/application.local
- ./run:/var/run/
- ./logs:/var/log/nginx
networks:
- app-network

app:
build:
context: .docker/php
dockerfile: Dockerfile
container_name: app
volumes:
- ./src:/www/application.local
- ./run:/var/run/
networks:
- app-network

memcached:
image: bitnami/memcached:latest
ports:
- "11211:11211"
networks:
- app-network

redis:
image: redis:alpine
ports:
- "6379:6379"
networks:
- app-network

postgres:
image: postgres:15.1
environment:
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
volumes:
- ./data:/var/lib/postgresql/data
ports:
- "5432:5432"
networks:
- app-network

networks:
app-network:
driver: bridge
11 changes: 11 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<html>
<head>
<title>TEST</title>
</head>
<body>
<h1>Hello, OTUS!</h1>
<div>
<img src="static/php.png" width="92" height="92">
</div>
</body>
</html>
27 changes: 27 additions & 0 deletions src/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

try {
$memcache = new Memcache();
$memcache->addServer('memcached');
echo 'Memcache version ' . $memcache->getVersion() . PHP_EOL;
} catch (\Throwable $throwable) {
echo 'Ошибка подключения Memcache: ' . $throwable->getMessage();
}

try {
$redis = new Redis();
$redis->connect('redis');
echo '<br>Redis is connection ' . print_r($redis->isConnected(), true) . PHP_EOL;
} catch (\Throwable $throwable) {
echo 'Ошибка подключения Redis : ' . $throwable->getMessage();
}

try {
$dsn = 'pgsql:host=postgres;port=5432;dbname=PG_DATABASE;';
$psql = new PDO($dsn, 'PG_USERNAME', 'PG_PASSWORD');
echo '<br>PSQL is connection';
} catch (\Throwable $throwable) {
echo 'Ошибка подключения PSQL: ' . $throwable->getMessage();
}
Binary file added src/static/php.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.