Skip to content

Instantly share code, notes, and snippets.

@PokeGuys
Last active March 21, 2021 17:22
Show Gist options
  • Save PokeGuys/0d7181fca7380cac9bedaaa925b9cbae to your computer and use it in GitHub Desktop.
Save PokeGuys/0d7181fca7380cac9bedaaa925b9cbae to your computer and use it in GitHub Desktop.
LNMP dockerize setup scripts.
NGINX_HOST_PORT=8000
PHP_FPM_XDEBUG_PORT=9003
MYSQL_HOST_PORT=3306
MEMCACHED_HOST_PORT=11121
server {
listen 80;
index index.php index.html;
server_name app.local;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
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;
}
}
version: '3.5'
services:
# The Web Server
nginx:
image: nginx:stable-alpine
ports:
- "${NGINX_HOST_PORT}:80"
volumes:
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
volumes_from:
- app
networks:
- frontend
- backend
# The Application
app:
build:
context: .
dockerfile: Dockerfile
working_dir: /var/www
volumes:
- .:/var/www/html
ports:
- "${PHP_FPM_XDEBUG_PORT}:9003"
networks:
- backend
# Database
database:
image: mysql:5.7
environment:
- "MYSQL_DATABASE=homestead"
- "MYSQL_USER=user"
- "MYSQL_PASSWORD=secret"
- "MYSQL_ROOT_PASSWORD=secret"
ports:
- "${MYSQL_HOST_PORT}:3306"
networks:
- backend
memcached:
image: memcached:latest
ports:
- "${MEMCACHED_HOST_PORT}:11211"
networks:
- backend
networks:
frontend:
driver: bridge
backend:
driver: bridge
FROM php:7.4-fpm-alpine
# Set working directory
WORKDIR /var/www
# Install zip
RUN apk update && apk add libzip-dev zip unzip && docker-php-ext-configure zip && docker-php-ext-install zip
# Install pdo_mysql json mbstring openssl
RUN docker-php-ext-install pdo pdo_mysql json mbstring openssl exif
# Enable XDebug
RUN pecl install xdebug-2.9.8 && docker-php-ext-enable xdebug
## Copy xdebug configuration for remote debugging
COPY ./xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
RUN sed -i "s/xdebug.remote_autostart=0/xdebug.remote_autostart=1/" /usr/local/etc/php/conf.d/xdebug.ini && \
sed -i "s/xdebug.remote_enable=0/xdebug.remote_enable=1/" /usr/local/etc/php/conf.d/xdebug.ini && \
sed -i "s/xdebug.cli_color=0/xdebug.cli_color=1/" /usr/local/etc/php/conf.d/xdebug.ini
# Install Memcached
RUN pecl install memcached-3.1.3 && docker-php-ext-enable memcached
# Installing composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Install dependencies
RUN composer install
# Remove Cache
RUN rm -rf /var/cache/apk/*
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www 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"]
xdebug.remote_host="host.docker.internal"
xdebug.remote_connect_back=0
xdebug.remote_port=9000
xdebug.idekey=PHPSTORM
xdebug.remote_autostart=0
xdebug.remote_enable=0
xdebug.cli_color=0
xdebug.profiler_enable=0
xdebug.profiler_output_dir="~/xdebug/phpstorm/tmp/profiling"
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.var_display_max_children=-1
xdebug.var_display_max_data=-1
xdebug.var_display_max_depth=-1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment