diff --git a/docker/.env b/docker/.env new file mode 100644 index 000000000..31897e06d --- /dev/null +++ b/docker/.env @@ -0,0 +1,11 @@ +# MySQL settings +MYSQL_DATABASE = sitemanager +MYSQL_USER = sitemanager +MYSQL_PASSWORD = 123 +MYSQL_ROOT_PASSWORD = 123 + +# Site path +SITE_PATH=~/otus/hw1/www/ + +# ADD PROJECT NAME HERE +COMPOSE_PROJECT_NAME = otus \ No newline at end of file diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml new file mode 100644 index 000000000..8be1cace4 --- /dev/null +++ b/docker/docker-compose.yaml @@ -0,0 +1,70 @@ +version: '3' + +services: + nginx: + build: + context: ./nginx + dockerfile: Dockerfile + image: nginx + container_name: nginx + ports: + - "80:80" + volumes: + - ${SITE_PATH}:/data/mysite.local + - php-fpm-socket:/var/run/d-socket + networks: + - app-network + + php-fpm: + build: + context: ./php-fpm + dockerfile: Dockerfile + image: php-fpm + container_name: php-fpm + volumes: + - ${SITE_PATH}:/data/mysite.local + - php-fpm-socket:/var/run/d-socket + networks: + - app-network + + redis: + image: redis:latest + container_name: redis + ports: + - "6379:6379" + volumes: + - ./var/redis/data:/data/mysite.local/redis + networks: + - app-network + + memcached: + image: memcached:latest + container_name: memcached + volumes: + - ./var/memcached/data:/data/mysite.local/memcached + networks: + - app-network + + mysql: + image: mysql:latest + container_name: mysql + restart: always + environment: + MYSQL_DATABASE: ${MYSQL_DB} + MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} + MYSQL_USER: ${MYSQL_USER} + MYSQL_PASSWORD: ${MYSQL_PASSWORD} + ports: + - "3306:3306" + volumes: + - ./var/mysql:/var/lib/mysql + networks: + - app-network + + +volumes: + php-fpm-socket: + +networks: + app-network: + driver: bridge diff --git a/docker/nginx/Dockerfile b/docker/nginx/Dockerfile new file mode 100644 index 000000000..71aff70c7 --- /dev/null +++ b/docker/nginx/Dockerfile @@ -0,0 +1,11 @@ +FROM nginx:latest + +COPY ./conf/mysite.local.conf /etc/nginx/conf.d/mysite.local.conf + +WORKDIR /data + +VOLUME /data + +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/docker/nginx/conf/mysite.local.conf b/docker/nginx/conf/mysite.local.conf new file mode 100644 index 000000000..8a450dca9 --- /dev/null +++ b/docker/nginx/conf/mysite.local.conf @@ -0,0 +1,28 @@ +server { + + listen 80; + + server_name mysite.local; + + root /data/mysite.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 php-fpm:9000; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } +} \ No newline at end of file diff --git a/docker/php-fpm/Dockerfile b/docker/php-fpm/Dockerfile new file mode 100644 index 000000000..29535d1a2 --- /dev/null +++ b/docker/php-fpm/Dockerfile @@ -0,0 +1,30 @@ +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 \ + && 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 memcached \ + && docker-php-ext-enable memcached \ + && apt-get install -y libpq-dev \ + && docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \ + && docker-php-ext-install pdo pdo_pgsql pgsql \ + && pecl install redis \ + && docker-php-ext-enable redis.so \ + && 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/mysite.local + +VOLUME /data + +CMD ["php-fpm"] \ No newline at end of file diff --git a/docker/php-fpm/php.ini b/docker/php-fpm/php.ini new file mode 100644 index 000000000..ff806bb1f --- /dev/null +++ b/docker/php-fpm/php.ini @@ -0,0 +1,2 @@ +session.save_handler = memcache +session.save_path = "tcp://memcache:11211" \ No newline at end of file diff --git a/www/index.php b/www/index.php new file mode 100644 index 000000000..5765db0e0 --- /dev/null +++ b/www/index.php @@ -0,0 +1,7 @@ +" . date("Y-m-d H:i:s") . "

"; + +echo "Что-то еще"; + +phpinfo();