-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df0d466
commit 13c70fe
Showing
7 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
MYSQL_USER= | ||
MYSQL_PASSWORD= | ||
MYSQL_ROOT_PASSWORD= | ||
REDIS_PASSWORD= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
init: docker-down docker-build docker-up | ||
|
||
docker-down: | ||
docker compose down --remove-orphans | ||
|
||
docker-build: | ||
docker compose build | ||
|
||
docker-up: | ||
docker compose up -d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
echo "<pre>"; | ||
|
||
$redis = new Redis(); | ||
$redis->connect('redis', 6379); | ||
$redis->auth(getenv("REDIS_PASSWORD")); | ||
|
||
if ($redis->ping()) { | ||
print_r('Redis is alive!!!!!!'); | ||
echo "<hr />"; | ||
} | ||
|
||
$mc = new Memcached(); | ||
$mc->addServer("memcached", 11211); | ||
$mc->set("foo", "Hello!"); | ||
$mc->set("bar", "Memcached..."); | ||
$data = [ | ||
$mc->get("foo"), | ||
$mc->get("bar") | ||
]; | ||
|
||
print_r($data); | ||
echo "<hr />"; | ||
|
||
try { | ||
$user = getenv("DB_USER"); | ||
$pass = getenv("DB_PASSWORD"); | ||
$opt = [ | ||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, | ||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, | ||
PDO::ATTR_EMULATE_PREPARES => false, | ||
]; | ||
$pdo = new PDO("mysql:host=mysql;dbname=mysite", $user, $pass, $opt); | ||
$stmt = $pdo->query('SHOW DATABASES;'); | ||
|
||
while ($row = $stmt->fetch()) { | ||
print_r($row); | ||
} | ||
} catch (\Throwable $e) { | ||
print_r($e->getMessage()); | ||
} | ||
|
||
echo "<hr />"; | ||
|
||
echo "</pre>"; | ||
|
||
phpinfo(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
version: '3' | ||
|
||
services: | ||
nginx: | ||
image: nginx:latest | ||
container_name: mysite-nginx | ||
depends_on: | ||
- php-fpm | ||
ports: | ||
- "80:80" | ||
volumes: | ||
- ./code:/data/mysite.local | ||
- ./nginx/hosts/mysite.local.conf:/etc/nginx/conf.d/mysite.local.conf | ||
networks: | ||
- app-network | ||
|
||
php-fpm: | ||
build: | ||
context: ./fpm | ||
dockerfile: Dockerfile | ||
image: mysite/php-fpm | ||
container_name: mysite-php-fpm | ||
environment: | ||
- REDIS_PASSWORD=${REDIS_PASSWORD} | ||
- DB_USER=${MYSQL_USER} | ||
- DB_PASSWORD=${MYSQL_PASSWORD} | ||
depends_on: | ||
- memcached | ||
- redis | ||
volumes: | ||
- ./code:/data/mysite.local | ||
networks: | ||
- app-network | ||
|
||
memcached: | ||
image: memcached:latest | ||
container_name: mysite-memcached | ||
ports: | ||
- '11211:11211' | ||
networks: | ||
- app-network | ||
|
||
redis: | ||
image: redis:latest | ||
container_name: mysite-redis | ||
environment: | ||
- REDIS_PASSWORD=${REDIS_PASSWORD} | ||
command: sh -c 'exec redis-server --requirepass "$REDIS_PASSWORD"' | ||
ports: | ||
- '6379:6379' | ||
networks: | ||
- app-network | ||
|
||
mysql: | ||
image: mysql:8.0 | ||
container_name: mysite-mysql | ||
ports: | ||
- "3306:3306" | ||
environment: | ||
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} | ||
MYSQL_DATABASE: mysite | ||
MYSQL_USER: ${MYSQL_USER} | ||
MYSQL_PASSWORD: ${MYSQL_PASSWORD} | ||
volumes: | ||
- mysite-dbdata:/var/lib/mysql | ||
networks: | ||
- app-network | ||
|
||
networks: | ||
app-network: | ||
driver: bridge | ||
|
||
volumes: | ||
mysite-dbdata: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
FROM php:8.2-fpm | ||
|
||
# ставим необходимые для нормальной работы модули | ||
RUN apt-get update \ | ||
&& apt-get install -y \ | ||
libfreetype6-dev \ | ||
libjpeg62-turbo-dev \ | ||
libpng-dev \ | ||
libonig-dev \ | ||
libzip-dev \ | ||
libmemcached-dev \ | ||
zlib1g-dev \ | ||
libssl-dev \ | ||
libz-dev \ | ||
libmcrypt-dev \ | ||
&& pecl install mcrypt-1.0.6 \ | ||
&& docker-php-ext-enable mcrypt \ | ||
&& docker-php-ext-install -j$(nproc) iconv mbstring mysqli pdo_mysql zip \ | ||
&& docker-php-ext-configure gd --with-freetype --with-jpeg \ | ||
&& docker-php-ext-install -j$(nproc) gd \ | ||
&& pecl install redis \ | ||
&& docker-php-ext-enable redis | ||
|
||
RUN yes '' | pecl install -f memcached-3.2.0 \ | ||
&& docker-php-ext-enable memcached | ||
|
||
# Устанавливаем Composer | ||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer | ||
|
||
COPY ./php.ini /usr/local/etc/php/conf.d/php-custom.ini | ||
|
||
WORKDIR /data | ||
|
||
VOLUME /data | ||
|
||
CMD ["php-fpm"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
session.save_handler = memcache | ||
session.save_path = "tcp://memcache:11211" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
server { | ||
# указываем 80 порт для соединения | ||
listen 80; | ||
# нужно указать, какому доменному имени принадлежит наш конфиг | ||
server_name mysite.local; | ||
|
||
# задаём корневую директорию | ||
root /data/mysite.local; | ||
|
||
# стартовый файл | ||
index index.php index.html; | ||
|
||
# при обращении к статическим файлам логи не нужны, равно как и обращение к fpm | ||
# http://mysite.local/static/some.png | ||
location ~* .(jpg|jpeg|gif|css|png|js|ico|html)$ { | ||
access_log off; | ||
expires max; | ||
} | ||
|
||
# помним про единую точку доступа | ||
# все запросы заворачиваются в корневую директорию root на index.php | ||
location / { | ||
try_files $uri $uri/ /index.php?$query_string; | ||
} | ||
|
||
# и наконец правило обращения к php-fpm | ||
location ~* .php$ { | ||
try_files $uri = 404; | ||
fastcgi_split_path_info ^(.+.php)(/.+)$; | ||
fastcgi_pass php-fpm:9000; | ||
#fastcgi_pass unix:/var/run/php-fpm.sock; | ||
fastcgi_index index.php; | ||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | ||
include fastcgi_params; | ||
} | ||
} |