Giter Site home page Giter Site logo

laravel-captain's Introduction

Laravel Captain Workflow

This is a pretty simplified, but complete, workflow for using Docker and Docker Compose with Laravel development. The included docker-compose.yml file, Dockerfiles, and config files, set up a LEMP stack powering a Laravel application in the src directory.

Installation

First you need to download a fresh laravel application, and put into a src folder to the root of this project.

You can use the composer container to create a new laravel application:

docker-compose run --rm composer create-project laravel/laravel .

By default, the nginx config redirect the port 80 to 443, so you need a certificate to use https on local environment.

To do this, go to ./nginx/certs and create a new certificate by running this command:

mkcert captain.test

If you don't have mkcert installed, check the mkcert documentation.

Next, spin up the containers for the full web server stack by running docker-compose up -d --build nginx.

After that completes, run the following to install and compile the dependencies for the application:

  • docker-compose run --rm composer install
  • docker-compose run --rm npm install
  • docker-compose run --rm npm run dev

When the container network is up, the following services and their ports are available to the host machine:

  • nginx - :80
  • mysql - :3306
  • php - :9000
  • redis - :6379

You would use them just like you would with their native counterparts, including your command after any of those lines above (e.g. docker-compose run --rm artisan db:seed).

Usage

Inspired in Laravel Sail, this project has a builder file that allows you to run commands more easily.

To run a command, you can use the ./builder file.

For example, to run php artisan migrate, you can run ./builder artisan migrate.

The builder is just a wrapper for docker-compose run --rm composer install, so you can run any command you want.

You can create an alias for the builder file in your .bashrc or .zshrc file adding the following line to your .zshrc:

alias captain='sh ./builder'

Now, you can run captain artisan migrate to run php artisan migrate.

Some cases you may need to run source ~/.zshrc to reload your shell, or give execution permissions to the builder file, by running chmod +x ./builder.

More examples:

  • captain composer install
  • captain npm install
  • captain npm run dev
  • captain artisan migrate
  • captain artisan db:seed

Three additional containers are included that are not brought up with the webserver stack, and are instead used as "command services". These allow you to run commands that interact with your application's code, without requiring their software to be installed and maintained on the host machine. These are:

  • captain composer
  • captain artisan
  • captain npm

Production Usage

To use this workflow in production, you can use the docker-compose.prod.yml file. This file is a copy of the docker-compose.yml file, but with some changes to make it more suitable for production environments.

To use it, you can run docker-compose -f docker-compose.prod.yml up -d --build nginx. Also, you can use the captain alias to run commands in the production environment, you just need to pass the prod argument after the alias. For example, to run npm run production, you can run captain prod npm run production.

Permissions Issues

During the PHP service setup, there are portions that reference permission issues and utilizing some commands in the php.dockerfile to work around them. That solution might not work for every system, and if your machine throws an error after implementing them, please see the updated php.dockerfile and php/www.conf files included in this code archive.

Using these updates, rebuilding your Docker network with docker-compose up -d --build should resolve any permissions issues during site loads, composer installations, or artisan commands.

laravel-captain's People

Contributors

thobiasvicente avatar

Stargazers

 avatar  avatar

Watchers

 avatar  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.