From 9298c640911e993d5cc96776d48056abfeb685ee Mon Sep 17 00:00:00 2001 From: y9938 Date: Mon, 6 Oct 2025 02:53:44 +0300 Subject: [PATCH] Initial commit --- .gitignore | 1 + LICENSE | 18 ++++++++++++ README.md | 32 +++++++++++++++++++++ compose.yaml | 56 +++++++++++++++++++++++++++++++++++++ docker/Dockerfile | 33 ++++++++++++++++++++++ docker/docker-entrypoint.sh | 37 ++++++++++++++++++++++++ docker/nginx.conf | 25 +++++++++++++++++ docker/php-fpm.conf | 12 ++++++++ 8 files changed, 214 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 compose.yaml create mode 100644 docker/Dockerfile create mode 100755 docker/docker-entrypoint.sh create mode 100644 docker/nginx.conf create mode 100644 docker/php-fpm.conf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e9d9de0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,18 @@ +MIT License + +Copyright (c) 2025 y9938 + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the +following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO +EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e897784 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# Laravel Docker Setup + +- NGINX, MySQL, phpMyAdmin + +## Создание проекта: + +```bash +docker compose run --rm php-fpm bash +``` + +```bash +composer global require laravel/installer + +export PATH="$HOME/.composer/vendor/bin:$PATH" + +laravel new example-app + +mv example-app/* example-app/.* ./ +rmdir example-app +``` + +Изменить `.env` + +``` +DB_CONNECTION=mysql +DB_HOST=mysql +DB_PORT=3306 +DB_DATABASE=app +DB_USERNAME=laravel +DB_PASSWORD=secret +DB_ROOT_PASSWORD=secret +``` diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..05fa801 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,56 @@ +services: + web: + image: nginx:latest + volumes: + - ./:/var/www + - ./docker/nginx.conf:/etc/nginx/conf.d/default.conf + ports: + - "8000:80" + environment: + - NGINX_HOST=localhost + depends_on: + php-fpm: + condition: service_started + + php-fpm: + build: + context: . + dockerfile: ./docker/Dockerfile + args: + UID: ${UID:-1000} + GID: ${GID:-1000} + env_file: + - .env + volumes: + - ./:/var/www + - ./docker/docker-entrypoint.sh:/usr/local/bin/docker-entrypoint.sh + depends_on: + mysql: + condition: service_started + + mysql: + image: mysql:8.0 + ports: + - "${DB_PORT:-3306}:3306" + environment: + - MYSQL_DATABASE=${DB_DATABASE} + - MYSQL_USER=${DB_USERNAME} + - MYSQL_PASSWORD=${DB_PASSWORD} + - MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD} + volumes: + - mysql-data:/var/lib/mysql + + phpmyadmin: + image: phpmyadmin:latest + restart: unless-stopped + ports: + - "8080:80" + environment: + - PMA_HOST=mysql + - PMA_PORT=${DB_PORT:-3306} + - UPLOAD_LIMIT=100M + depends_on: + - mysql + +volumes: + mysql-data: diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..578796b --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,33 @@ +FROM php:8.3-fpm + +ARG UID +ARG GID + +RUN apt-get update && apt-get install -y \ + netcat-traditional \ + libpng-dev \ + libonig-dev \ + libxml2-dev \ + libzip-dev \ + zip \ + unzip \ + git \ +&& docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip \ +&& apt-get clean && rm -rf /var/lib/apt/lists/* + +COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ + +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +COPY ./docker/php-fpm.conf /usr/local/etc/php-fpm.d/zz-docker.conf + +COPY ./docker/docker-entrypoint.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/docker-entrypoint.sh + +RUN groupadd -g $GID laravel && useradd -u $UID -g $GID -m laravel +USER laravel +WORKDIR /var/www + +EXPOSE 9000 +ENTRYPOINT ["docker-entrypoint.sh"] +CMD ["php-fpm"] diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh new file mode 100755 index 0000000..85e4f73 --- /dev/null +++ b/docker/docker-entrypoint.sh @@ -0,0 +1,37 @@ +#!/bin/sh +set -e + +cd /var/www + +if [ -f "artisan" ]; then + chown -R laravel:laravel /var/www/storage /var/www/bootstrap/cache + chmod -R 775 /var/www/storage /var/www/bootstrap/cache + + if [ ! -d "vendor" ]; then + echo ">> Installing composer dependencies..." + composer install --optimize-autoloader + else + echo ">> Vendor directory exists, skipping installation" + fi + + if [ -f ".env" ] && grep -q '^APP_KEY=$' .env; then + echo ">> APP_KEY is missing. Generating application key..." + php artisan key:generate --ansi + fi + + echo ">> Waiting for MySQL to be ready..." + while ! nc -z mysql 3306; do + sleep 1 + done + echo ">> MySQL is ready!" + + echo ">> Running migrations..." + php artisan migrate --force || true + + echo ">> Running seeders..." + php artisan db:seed --force || true +else + echo ">> Not a Laravel project" +fi + +exec "$@" diff --git a/docker/nginx.conf b/docker/nginx.conf new file mode 100644 index 0000000..9869f38 --- /dev/null +++ b/docker/nginx.conf @@ -0,0 +1,25 @@ +server { + listen 80; + index index.php index.html; + error_log /var/log/nginx/error.log; + access_log /var/log/nginx/access.log; + root /var/www/public; + + 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; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; + } + + location ~ /\.ht { + deny all; + } +} diff --git a/docker/php-fpm.conf b/docker/php-fpm.conf new file mode 100644 index 0000000..56a58f6 --- /dev/null +++ b/docker/php-fpm.conf @@ -0,0 +1,12 @@ +[global] +daemonize = no + +[www] +user = laravel +group = laravel +listen = 9000 +pm = dynamic +pm.max_children = 5 +pm.start_servers = 2 +pm.min_spare_servers = 1 +pm.max_spare_servers = 3