Skip to content

Instantly share code, notes, and snippets.

@MMazoni
Last active July 13, 2020 15:13
Show Gist options
  • Select an option

  • Save MMazoni/c1d3cd16d4ed2ad7619b31198c19c3a7 to your computer and use it in GitHub Desktop.

Select an option

Save MMazoni/c1d3cd16d4ed2ad7619b31198c19c3a7 to your computer and use it in GitHub Desktop.
Laravel-docker - php7.2, nginx, oci8

Installing Laravel project with docker (php7.2, nginx, oci8)

Enter the project folder and use composer command.

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

Define the ownership properties of the folder.

$ sudo chown -R $USER:$USER ~/laravel-app

Crete the files below and start the containers:

$ docker-compose up -d
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;
}
}
version: '3'
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: php-laravel
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
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:
- "8000:80"
- "443:443"
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
FROM php:7.2-fpm
# 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 \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl \
libaio1
# 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
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
# Install oci8
ADD /oracle/instantclient-basic-linux.x64-19.6.0.0.0dbru.zip /tmp/
ADD /oracle/instantclient-sdk-linux.x64-19.6.0.0.0dbru.zip /tmp/
RUN unzip /tmp/instantclient-basic-linux.x64-19.6.0.0.0dbru.zip -d /usr/local/ \
&& unzip /tmp/instantclient-sdk-linux.x64-19.6.0.0.0dbru.zip -d /usr/local/ \
&& mv /usr/local/instantclient_19_6 /usr/local/instantclient \
&& docker-php-ext-configure oci8 --with-oci8=instantclient,/usr/local/instantclient \
&& docker-php-ext-install oci8 \
&& export LD_LIBRARY_PATH=/opt/oracle/instantclient \
&& echo /usr/local/instantclient/ > /etc/ld.so.conf.d/oracle-instantclient.conf \
&& ldconfig
# 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"]
upload_max_filesize=40M
post_max_size=40M
@MMazoni
Copy link
Author

MMazoni commented Jul 13, 2020

Important commands

docker-compose exec app composer install

docker-compose exec app php artisan key:generate

docker-compose exec app php artisan config:cache

docker-compose exec app php artisan migrate

docker-compose exec app php artisan tinker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment