https://github.com/shipping-docker/php-app
A containerized Laravel application
https://github.com/shipping-docker/php-app
Last synced: 6 months ago
JSON representation
A containerized Laravel application
- Host: GitHub
- URL: https://github.com/shipping-docker/php-app
- Owner: shipping-docker
- Created: 2016-08-28T21:19:34.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-10-08T17:32:10.000Z (almost 8 years ago)
- Last Synced: 2025-02-25T02:43:03.796Z (over 1 year ago)
- Language: Dockerfile
- Size: 29.3 KB
- Stars: 278
- Watchers: 17
- Forks: 73
- Open Issues: 11
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Containerized PHP Application
## 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](https://shippingdocker.com/) 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!**
## How to use
### 1. Get the files and spin up containers
```bash
# 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
```bash
# 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:
```bash
# 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:
```bash
# 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.

