Skip to content

Instantly share code, notes, and snippets.

@mvlsqz
Last active July 17, 2018 13:05
Show Gist options
  • Save mvlsqz/15403bc1e13a328e884207a490974be6 to your computer and use it in GitHub Desktop.
Save mvlsqz/15403bc1e13a328e884207a490974be6 to your computer and use it in GitHub Desktop.
Laravel development environment on Docker

Setup your development environment

Run all the follow commands into your project directory

# creating application bootstrap
docker run --rm -v $(pwd):/app composer/composer create-project laravel/laravel app 5.4
# installing dependencies (if is needed)
docker run --rm -v $(pwd)/app:/app composer/composer install

Pull from this gist the required files docker-compose.yml, app.dockerfile, etc..

curl -O https://gist.githubusercontent.com/mvlsqz/15403bc1e13a328e884207a490974be6/raw/6c48f83fc074950a5dc5cf1605c8babcd4b02f7d/docker-compose.yml
curl -O https://gist.githubusercontent.com/mvlsqz/15403bc1e13a328e884207a490974be6/raw/6c48f83fc074950a5dc5cf1605c8babcd4b02f7d/app.dockerfile
curl -O https://gist.githubusercontent.com/mvlsqz/15403bc1e13a328e884207a490974be6/raw/6c48f83fc074950a5dc5cf1605c8babcd4b02f7d/web.dockerfile
curl -O https://gist.githubusercontent.com/mvlsqz/15403bc1e13a328e884207a490974be6/raw/6c48f83fc074950a5dc5cf1605c8babcd4b02f7d/vhost.conf

Start all the services, will take some time on the first run

docker-compose up

application key & optimize

docker-compose exec app php artisan key:generate
docker-compose exec app php artisan optimize

go to http://localhost:8080 and have fun!

FROM php:5-fpm
ENV PHP_VERSION 5.4.6
RUN apt-get update && apt-get install -y libmcrypt-dev \
mysql-client libmagickwand-dev --no-install-recommends \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& docker-php-ext-install mcrypt pdo_mysql
version: '2'
services:
app:
build:
context: ./
dockerfile: app.dockerfile
working_dir: /var/www
volumes:
- ./app:/var/www
environment:
- "DB_PORT=3306"
- "DB_HOST=database"
web:
build:
context: ./
dockerfile: web.dockerfile
working_dir: /var/www
volumes_from:
- app
ports:
- 8080:80
database:
image: mysql:5.6
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_DATABASE=homestead"
- "MYSQL_USER=homestead"
- "MYSQL_PASSWORD=secret"
- "MYSQL_ROOT_PASSWORD=secret"
ports:
- "33061:3306"
volumes:
dbdata:
server {
listen 80;
index index.php index.html;
root /var/www/public;
location / {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
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;
}
}
FROM nginx:1.10
ADD vhost.conf /etc/nginx/conf.d/default.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment