GithubHelp home page GithubHelp logo

kinkir / docker-for-laravel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cs-eliseev/docker-for-laravel

0.0 1.0 0.0 72 KB

Build Laravel's development environment using docker LEMP.

License: MIT License

Dockerfile 100.00%

docker-for-laravel's Introduction

English | Русский

DOCKER FOR LARAVEL

Packagist GitHub repo size

Description

Build Laravel's development environment using docker LEMP. Uses a persistant database store and stack PHP, MySQL, Redis, Nginx (http, https).

Info

Project link

Laravel project path

src/

Logs path

src/logs

Usage

Install

Git

Clone this repository locally:

git clone https://github.com/cs-eliseev/docker-for-laravel.git

Download

Download the latest release here.

Install developments tools

Create laravel project

  1. Create a new Laravel project to Docker

    composer create-project --prefer-dist laravel/laravel src
  2. Git clone project to Docker

    git clone <link> src

Build application

  1. Go to the Laravel project

    cd src
  2. Add composer Laravel dependency

    composer require predis/predis
  3. Update Composer Laravel dependency

    composer update
  4. Install NPM Larave dependency

    npm i
  5. Add needs write permissions to Laravel project

    sudo chmod 777 -R storage bootstrap/cache
  6. Add group to Laravel project

    sudo chown -R 1000:1000 storage bootstrap/cache
  7. Build all Docker containers

    docker-compose up --build
  8. Create Laravel application key

    docker exec -it laravel-container php artisan key:generate
  9. Use project

    HTTP - http://localhost:5101

    HTTPS - https://localhost:5102

    XDebug - http://192.168.220.1:5104

MySQL connection

  1. Get MySQL network info in a Docker container

    docker inspect datebase-container
  2. Settings MySQL to Laravel

    Edit src/.env file

    DB_CONNECTION=mysql
    DB_HOST=datebase-container
    DB_PORT=3306
    DB_DATABASE=laravel_project
    DB_USERNAME=root
    DB_PASSWORD=123456
    
  3. Use MySQL in a Docker container

    docker-compose exec database bash -c 'mysql -u root -p 123456 laravel_project'
  4. Run Laravel Migration to Docker container

    docker-compose exec laravel php artisan migrate
  5. Clear database to Docker container

    docker-compose down --volumes --rmi all
    docker-compose up -d --build
    docker-compose exec laravel php artisan migrate

Redis

  1. Settings Redis to Laravel

    Edit src/.env file

    REDIS_HOST=redis-container
    REDIS_PASSWORD=null
    REDIS_PORT=6379
    
  2. Test Redis

    docker-compose exec laravel php artisan tinker
    Illuminate\Support\Facades\Redis::set('name', 'hoge');
    Illuminate\Support\Facades\Redis::get('name');
    exit
  3. Use Redis cli

    docker-compose exec redis redis-cli

XDebug

  1. Change XDebug config for Mac or Windows

    Change file docker/laravelxdebug.ini

    xdebug.remote_host=host.docker.internal 
    

Use UnitTest

PHPUnit is used for unit testing. Unit tests ensure that class and methods does exactly what it is meant to do.

General PHPUnit documentation can be found at https://phpunit.de/documentation.html.

  1. Add unit test Laravel application, db connection to Docker container

    Create a new PHPUnit Test class DbConnectivityTest in folder src/tests/Feature

    <?php
    
    namespace Tests\Feature;
    
    use Illuminate\Database\Connection;
    use Tests\TestCase;
    
    class DbConnectivityTest extends TestCase
    {
        public function testDbConnectivity()
        {
            /** @var Connection $db */
            $db = $this->app->make("db");
            $row = $db->selectOne("SELECT 1 AS one");
            $this->assertEquals(1, $row->one);
        }
    }
  2. To run the PHPUnit unit tests, execute in a Docker container:

    docker-compose exec laravel ./vendor/bin/phpunit

Create SSL cert

  1. Running OpenSSL command create ssl certs

    sudo openssl req -x509 -nodes -days 999999 -newkey rsa:2048 -keyout docker/laravel/nginx/cert/nginx.key -out docker/laravel/nginx/cert/nginx.crt

Project managment

Git

Please see Git File for information.

Composer

Please see Composer File for information.

NPM

Please see NPM File for information.

PHPStan

Please see PHPStan File for information.

PHPCPD

Please see PHPCPD File for information.

PHP CS Fixer

Please see PHP CS Fixer File for information.

PHPUnit

Please see PHPUnit File for information.

XDebug

Please see Xdebug File for information.

Docker

Please see Docker File for information.

Laravel

Please see Laravel File for information.

Use command to Docker container: docker exec -it laravel-container <command>

Donating

You can support this project here. You can also help out by contributing to the project, or reporting bugs. Even voicing your suggestions for features is great. Anything to help is much appreciated.

License

The DOCKER FOR LARAVEL set of settings and configurations licensed under the MIT license. Please see License File for more information.


GitHub @cs-eliseev

docker-for-laravel's People

Contributors

cs-eliseev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.