Giter Site home page Giter Site logo

php-app's Introduction

Containerized PHP Application

Shipping Docker video series

What is this?

This is an example of how you can quickly get up and running with Docker to develop a PHP application. This is a companion to the ๐Ÿณ Shipping Docker video series.

Teach me how to use it!

I have a mini-course that uses this example to show you how to get up and running in Docker for development!

Sign up here to get an email with a link to the mini course to see how this works!

Shipping Docker mini-course

How to use

1. Get the files and spin up containers

# Get shipping-docker files
git clone https://github.com/shipping-docker/php-app.git
cd php-app

# Start the app, run containers
#   in the background
# This will download and build the images
#   the first time you run this
docker-compose up -d

At this point, we've created containers and have them up and running. However, we didn't create a Laravel application to serve yet. We waited because we wanted a PHP image to get created so we can re-use it and run composer commands.

2. Create a new Laravel application

# From directory "php-app"
# Create a Laravel application
docker run -it --rm \
    -v $(pwd):/opt \
    -w /opt \
    --network=phpapp_appnet \
    shippingdocker/php \
    composer create-project laravel/laravel application

docker run -it --rm \
    -v $(pwd)/application:/opt \
    -w /opt \
    --network=phpapp_appnet \
    shippingdocker/php \
    composer require predis/predis

# Restart required to ensure
# app files shares correctly
docker-compose restart

Edit the application/.env file to have correct settings for our containers. Adjust the following as necessary:

DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=redis
SESSION_DRIVER=redis
QUEUE_DRIVER=sync

REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379

If you already have an application, you can move it to the application directory here. Else, you can adjust the shared volume file paths within the docker-compose.yml file.

If you edit the docker-compose.yml file, run docker-compose down; docker-compose up -d to suck in the new Volume settings.

NOTE: If you're not running Docker Mac/Windows (which run Docker in a small virtualized layer), you may need to set permissions on the shared directories that Laravel needs to write to. The following will let Laravel write the storage and bootstrap directories:

# From directory php-app
chmod -R o+rw application/bootstrap application/storage

3. (Optionally) Add Auth Scaffolding:

If you'd like, we can add Laravel's Auth scaffolding as well. To do that, we need to run some Artisan commands:

# Scaffold authentication views/routes
docker run -it --rm \
    -v $(pwd)/application:/opt \
    -w /opt \
    --network=phpapp_appnet \
    shippingdocker/php \
    php artisan make:auth

# Run migrations for auth scaffolding
docker run -it --rm \
    -v $(pwd)/application:/opt \
    -w /opt \
    --network=phpapp_appnet \
    shippingdocker/php \
    php artisan migrate

Now we can start using our application! Head to http://localhost/register to see your Laravel application with auth scaffolding in place.

image

php-app's People

Contributors

fideloper avatar kbond avatar guiwoda avatar samasend avatar

Watchers

James Cloos 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.