Skip to content

Instantly share code, notes, and snippets.

@devig
Last active November 20, 2019 14:05
Show Gist options
  • Save devig/eed4de19bc02b1c741a3682878cb5f5a to your computer and use it in GitHub Desktop.
Save devig/eed4de19bc02b1c741a3682878cb5f5a to your computer and use it in GitHub Desktop.
Docker php7.3 xdebug phpStorm
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://0.0.0.0:8080
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=laraveluser
DB_PASSWORD=my_password
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

mkdir -p nginx/conf.d

touch nginx/conf.d/app.conf

создаём все нужные папки...

cd /var/www/laradock

composer create-project — prefer-dist laravel/laravel .

sudo chmod 777 -R storage/

sudo chmod 777 -R storage/logs/

sudo chmod 777 -R bootstrap/cache/

docker run --rm -v $(pwd):/app composer install

запускаем ip addr show выдаёт примерно inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0 - нужная подсеть

docker-compose up -d

docker ps

docker-compose exec db bash

mysql -u root -p

GRANT ALL ON laravel.* TO 'laraveluser'@'%' IDENTIFIED BY 'my_password';

FLUSH PRIVILEGES;

EXIT;

exit

docker-compose exec app php artisan migrate

http://0.0.0.0:8080/ или http://127.0.0.1:8080/

version: '3'
services:
#PHP Service
app:
build:
context: .
args:
- WITH_XDEBUG=true
dockerfile: Dockerfile
image: php:7.3-fpm
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
XDEBUG_CONFIG: "remote_host=172.17.0.1 remote_enable=1"
PHP_IDE_CONFIG: "serverName=php7.3"
working_dir: /var/www
volumes:
- ./:/var/www
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "8080:80"
- "8443:443"
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#MySQL Service
db:
image: mysql:5.7.24
container_name: db
restart: unless-stopped
tty: true
ports:
- "33061:3306"
environment:
MYSQL_DATABASE: laravel
MYSQL_ROOT_PASSWORD: root
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata:/var/lib/mysql/
- ./mysql/my.cnf:/etc/mysql/my.cnf
networks:
- app-network
# adminer:
# image: adminer
# restart: always
# depends_on:
# - db
# ports:
# - 8083:8080
#Docker Networks
networks:
app-network:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.17.0.1/16
#Volumes
volumes:
dbdata:
driver: local
FROM php:7.3-fpm-stretch
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Set working directory
WORKDIR /var/www
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libzip-dev \
libpng-dev \
libjpeg62-turbo-dev \
libwebp-dev libjpeg62-turbo-dev libpng-dev libxpm-dev \
libfreetype6 \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl \
&& docker-php-source extract \
&& pecl install xdebug redis \
&& docker-php-ext-enable xdebug redis
# sudo apt-get install php-xdebug
# wget \
# && pecl install xdebug \
# && docker-php-ext-enable xdebug
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www
# Change current user to www
USER www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
[mysqld]
general_log = 1
general_log_file = /var/lib/mysql/general.log
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 ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app: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 / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}
upload_max_filesize=50M
post_max_size=50M
max_execution_time = 1000
max_input_time = 1000
[Xdebug]
xdebug.remote_autostart=0
xdebug.remote_enable=1
xdebug.default_enable=0
xdebug.remote_host=172.17.0.1
xdebug.remote_port=9000
xdebug.remote_connect_back=0
xdebug.profiler_enable=0
xdebug.remote_log="/tmp/xdebug.log"
xdebug.profiler_output_dir="/var/www/profiler"
xdebug.profiler_output_name="cachegrind.out.%p"
xdebug.cli_color=1
xdebug.profiler_append=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment