You are here

11 May 2019
Another way to setup Laravel expecting that you have git and composer installed on your machine. Presented in configuration file examples for fastest reading/setup.
Source code viewer
  1. # Replace branch with the latest release.
  2. git clone -b 'v5.8.16' --single-branch --depth 1 https://github.com/laravel/laravel.git
  3. cd laravel
  4. rm -Rf .git
  5. composer install
  6. cp .env.example .env
  7.  
  8. # Create configuration files for docker, example content of the files is given below.
  9. touch docker-compose.yml
  10. touch app.dockerfile
  11. touch web.dockerfile
  12. touch vhost.conf
  13.  
  14. # The containers are build and ran. When you need to change config files then you need to run build, separately.
  15. docker-compose up
Programming Language: Bash

docker-compose.yml

Source code viewer
  1. version: '2'
  2. services:
  3.   app:
  4.   build:
  5.   context: ./
  6.   dockerfile: app.dockerfile
  7.   working_dir: /var/www
  8.   volumes:
  9. - ./:/var/www
  10.   environment:
  11. - "DB_PORT=3306"
  12. - "DB_HOST=database"
  13.  
  14.   web:
  15.   build:
  16.   context: ./
  17.   dockerfile: web.dockerfile
  18.   working_dir: /var/www
  19.   volumes_from:
  20. - app
  21.   ports:
  22. - 8080:80
  23.  
  24.   database:
  25.   image: mysql:5.6
  26.   volumes:
  27. - dbdata:/var/lib/mysql
  28.   environment:
  29. - "MYSQL_DATABASE=homestead"
  30. - "MYSQL_USER=homestead"
  31. - "MYSQL_PASSWORD=secret"
  32. - "MYSQL_ROOT_PASSWORD=secret"
  33.   ports:
  34. - "33061:3306"
  35.  
  36. volumes:
  37. dbdata:
Programming Language: YAML

app.dockerfile

Source code viewer
  1. FROM php:7.3.5-fpm
  2.  
  3. RUN apt-get update && apt-get install -y libmcrypt-dev \
  4. mysql-client libmagickwand-dev --no-install-recommends \
  5. && pecl install imagick mcrypt-1.0.2 \
  6. && docker-php-ext-enable imagick mcrypt \
  7. && docker-php-ext-install pdo_mysql
Programming Language: Text

web.dockerfile

Source code viewer
  1. FROM nginx:1.15.12
  2.  
  3. ADD vhost.conf /etc/nginx/conf.d/default.conf
Programming Language: Text

vhost.conf

Source code viewer
  1. listen 80;
  2. index index.php index.html;
  3. root /var/www/public;
  4.  
  5. try_files $uri /index.php?$args;
  6. }
  7.  
  8. location ~ \.php$ {
  9. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  10. fastcgi_pass app:9000;
  11. include fastcgi_params;
  12. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  13. fastcgi_param PATH_INFO $fastcgi_path_info;
  14. }
  15. }
Programming Language: nginx
Source code viewer
  1. find storage/ -type f -print0 | xargs -0 sudo chmod 666
  2. find storage/ -type d -print0 | xargs -0 sudo chmod 777
  3. find bootstrap/cache -type f -print0 | xargs -0 sudo chmod 666
  4. find bootstrap/cache -type d -print0 | xargs -0 sudo chmod 777
Programming Language: Bash
Source code viewer
  1. docker exec laravel_app_1 php artisan key:generate
  2. docker exec laravel_app_1 php artisan optimize
Programming Language: Bash
Configure your IDE accordingly.