Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel and Docker for prod with Apache #2

Merged
merged 1 commit into from Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
@@ -0,0 +1,2 @@
.git
.env
47 changes: 47 additions & 0 deletions .env.prod
@@ -0,0 +1,47 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:iq1jUp348I61Y2KYw64+MQ37qWhFEIUrhG90LwKX3aw=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=remotemysql.com
DB_PORT=3306
DB_DATABASE=OWFEdHyssp
DB_USERNAME=OWFEdHyssp
DB_PASSWORD=b4LsLiaSHP

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

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}"
22 changes: 22 additions & 0 deletions Dockerfile
@@ -0,0 +1,22 @@
FROM composer:2.0 as build
COPY . /app/
RUN composer install --prefer-dist --no-dev --optimize-autoloader --no-interaction

FROM php:8.0-apache-buster as production

ENV APP_ENV=production
ENV APP_DEBUG=false

RUN docker-php-ext-configure opcache --enable-opcache && \
docker-php-ext-install pdo pdo_mysql
COPY docker/php/conf.d/opcache.ini /usr/local/etc/php/conf.d/opcache.ini

COPY --from=build /app /var/www/html
COPY docker/000-default.conf /etc/apache2/sites-available/000-default.conf
COPY .env.prod /var/www/html/.env

RUN php artisan config:cache && \
php artisan route:cache && \
chmod 777 -R /var/www/html/storage/ && \
chown -R www-data:www-data /var/www/ && \
a2enmod rewrite
12 changes: 11 additions & 1 deletion README.md
Expand Up @@ -13,4 +13,14 @@ cp .env.example .env
./vendor/bin/sail -f docker-compose-dev-sail.yml up
```

Then hit `http://localhost/students` on your favorite browser to see if the app is working.
Then hit `http://localhost/students` on your favorite browser to see if the app is working.

## Run with plain docker compose

To run the Laravel application in a production like way, please execute the following command:

```
docker-compose up
```

The go to `http://localhost/students` to view the output.
12 changes: 12 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,12 @@
version: '3'
services:
app:
build:
context: ./
volumes:
- .:/var/www/html
ports:
- "80:80"
environment:
- APP_ENV=local
- APP_DEBUG=true
14 changes: 14 additions & 0 deletions docker/000-default.conf
@@ -0,0 +1,14 @@
<VirtualHost *:80>

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/public/

<Directory /var/www/>
AllowOverride All
Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>
8 changes: 8 additions & 0 deletions docker/php/conf.d/opcache.ini
@@ -0,0 +1,8 @@
[opcache]
opcache.enable=1
opcache.revalidate_freq=0
opcache.validate_timestamps=0
opcache.max_accelerated_files=10000
opcache.memory_consumption=192
opcache.max_wasted_percentage=10
opcache.interned_strings_buffer=16