Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Laravel Logo

Build Status Total Downloads Latest Stable Version License

Deploy with docker

Directory of docker:

docker
-- config
---- nginx
---- php-fpm
-- data
-- images
-- logs
---- nginx_log
---- php-fpm
projects
-- myweb.local

Create docker files

  1. Create a file myweb.local.conf in docker/config/nginx with code:
    server {
        listen   80;
    	listen [::]:80;
    	  
        root /var/www/html/myweb.local/public;
        index index.php index.html index.htm;
    	client_max_body_size 100M;    
        server_name myweb.local www.myweb.local;
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
        location ~ \.php$ {
            try_files $uri $uri/ /index.php?$query_string;
            fastcgi_pass myweb_php: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 ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
            expires 1d;
        }
        location ~ /\. {
                log_not_found off;
                deny all;
        }
       }
  2. Create a file custom.ini in docker/config/php-fpm with code:
    post_max_size = 1024M
    upload_max_filesize = 1024M
    error_log = /var/log/php-fpm.log
    display_errors = on
    opcache.enable=0
    memory_limit=1024M
    zend.assertions=-1
    enable_dl=1
    error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT
  3. Create a file composer.Dockerfile in docker/images with code:
    FROM composer:latest
  4. Create a file mysql.Dockerfile in docker/images with code:
    FROM mysql:8.0.31
  5. Create a file nginx.Dockerfile in docker/images with code:
    FROM nginx:latest
  6. Create a file php.Dockerfile in docker/images with code:
    FROM bitnami/php-fpm:8.1.11
    RUN apt-get update
    RUN apt-get install -y vim
    
  7. Create a file .env in docker directory
    COMPOSE_PROJECT_NAME=myweb
  8. Create a file docker-compose.yml in docker directory
    
    version: "3"
    services:
        myweb_nginx:
            dns:
              - 8.8.8.8
              - 4.4.4.4
            build:
              context: ./images
              dockerfile: nginx.Dockerfile
            working_dir: /var/www/html
            container_name: myweb_nginx
            ports:
              - "8181:80"
            volumes:
              - ../projects:/var/www/html
              - ./logs/nginx_log:/var/log/nginx
              - ./config/nginx/myweb.local.conf:/etc/nginx/conf.d/myweb.local.conf
            links:
              - myweb_php
              - myweb_mysql
        myweb_php:
            build:
              context: ./images
              dockerfile: php.Dockerfile
            container_name: myweb_php
            restart: always
            volumes:
                - ../projects:/var/www/html
                - ./logs/php-fpm/php-fpm.log:/var/log/php-fpm.log
                - ./config/php-fpm/custom.ini:/opt/bitnami/php/etc/conf.d/custom.ini
        myweb_mysql:
            build:
              context: ./images
              dockerfile: mysql.Dockerfile
            container_name: myweb_mysql
            restart: always
            ports:
              - "3310:3306"
            volumes:
              - ./data/mysql:/var/lib/mysql
            command: [
              --default-authentication-plugin=mysql_native_password,
              --skip-host-cache
            ]
            environment:
              #MYSQL_ALLOW_EMPTY_PASSWORD:
              MYSQL_ROOT_PASSWORD: password
              MYSQL_DATABASE: myweb
              MYSQL_USER: admin
              MYSQL_PASSWORD: password
        myweb_composer:
            build:
                context: ./images
                dockerfile: composer.Dockerfile
            container_name: myweb_composer
            links:
                - myweb_php
    
    
  9. Start build docker with command:

    Note: make sure cd to the docker directory on the terminal

    Step 1:

    docker-compose build
    After docker build is successful and next step 2

    Step 2:

    docker-compose up -d

Setup source code

First, please add the domain to the hosts file of windows or hosts on macos:

Windows : C:\Windows\System32\drivers\etc\hosts
Macos: /etc/hosts

127.0.0.1	myweb.local
::1 myweb.local
The source code is located in the directory myweb.local
projects
-- myweb.local
=> Clone the source code from git

Install laravel

Open terminal and run with code :

  1. Composer update
    docker exec myweb_php bash -c "cd /var/www/html/myweb.local && composer update"
  2. Copy .env file from .env.example
    docker exec myweb_php bash -c "cp /var/www/html/myweb.local/.env.example /var/www/html/myweb.local/.env"
  3. Run artisan migrate
    docker exec myweb_php bash -c "cd /var/www/html/myweb.local && php artisan migrate"
  4. Run npm install for format code with re-commit

    Note: make sure cd to the myweb.local directory on the terminal

    projects
    -- myweb.local
    And run
    npm i

About

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors