php-laravelHow do I use Docker Compose to deploy a Laravel application in PHP?
To deploy a Laravel application in PHP using Docker Compose, follow these steps:
- Create a
docker-compose.yml
file in the root of your Laravel application.
version: '3'
services:
web:
build: .
ports:
- "80:80"
volumes:
- ./:/var/www/html
links:
- mysql
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: laravel
- Run the
docker-compose up -d
command to start the containers in detached mode.
$ docker-compose up -d
Creating network "laravel_default" with the default driver
Creating laravel_web_1 ... done
Creating laravel_mysql_1 ... done
- Install the dependencies for the application with
docker-compose exec web composer install
.
$ docker-compose exec web composer install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 11 installs, 0 updates, 0 removals
- Installing symfony/psr-http-message-bridge (v1.2.0): Downloading (100%)
- Installing symfony/http-foundation (v4.4.9): Downloading (100%)
- Installing symfony/http-kernel (v4.4.9): Downloading (100%)
- Installing psr/http-message (1.0.1): Downloading (100%)
- Installing psr/container (1.0.0): Downloading (100%)
- Installing symfony/event-dispatcher (v4.4.9): Downloading (100%)
- Installing symfony/debug (v4.4.9): Downloading (100%)
- Installing symfony/http-client (v4.4.9): Downloading (100%)
- Installing symfony/finder (v4.4.9): Downloading (100%)
- Installing psr/http-factory (1.0.1): Downloading (100%)
- Installing psr/http-client (1.0.1): Downloading (100%)
Writing lock file
Generating optimized autoload files
- Generate the application key with
docker-compose exec web php artisan key:generate
.
$ docker-compose exec web php artisan key:generate
Application key [base64:TK5L6qgG1U9QxhZfhjPJHVqpVgHn3yQN8HxKDU/3zR4=] set successfully.
- Run the migrations with
docker-compose exec web php artisan migrate
.
$ docker-compose exec web php artisan migrate
Migration table created successfully.
Migrated: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_100000_create_password_resets_table
Migrated: 2019_08_19_000000_create_failed_jobs_table
- Access the application at
http://localhost
.
Helpful links
More of Php Laravel
- How can I use Laravel's mapping capabilities with PHP?
- How can I find PHP Laravel jobs in Canada?
- How do I set up a Laravel worker using PHP?
- How do I use Laravel traits in PHP?
- How do I use a template in Laravel with PHP?
- How do I write a PHP Laravel query to access a database?
- How can I use PHP Laravel and MongoDB together?
- How do I install Laravel using XAMPP and PHP?
- How can I use the upsert feature in Laravel with PHP?
- How do I use PHP Laravel Tinker to debug my code?
See more codes...