Skip to content

Commit 71a1eb2

Browse files
committed
fixes and improvements
1 parent 2d069c6 commit 71a1eb2

File tree

4 files changed

+383
-83
lines changed

4 files changed

+383
-83
lines changed

content/guides/frameworks/laravel/_index.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Develop and run Laravel applications with Docker Compose
2+
title: Develop and Deploy Laravel applications with Docker Compose
33
linkTitle: Laravel applications with Docker Compose
44
summary: Learn how to efficiently set up Laravel development and production environments using Docker Compose.
55
description: A guide on using Docker Compose to manage Laravel applications for development and production, covering container configurations and service management.
@@ -23,9 +23,9 @@ params:
2323
external: true
2424
---
2525

26-
Laravel is a popular PHP framework that allows developers to build web applications quickly and effectively. Docker Compose helps manage development and production environments by defining all necessary services, like PHP, web server and database, in a single YAML file. This guide provides an overview of setting up a robust environment for Laravel using Docker Compose, with a focus on simplicity and efficiency.
26+
Laravel is a popular PHP framework that allows developers to build web applications quickly and effectively. Docker Compose simplifies the management of development and production environments by defining essential services, like PHP, a web server, and a database, in a single YAML file. This guide provides a streamlined approach to setting up a robust Laravel environment using Docker Compose, focusing on simplicity and efficiency.
2727

28-
The demonstrated examples can be found in the [GitHub repository](https://github.com/rw4lll/laravel-docker-examples). Docker Compose is used as a straightforward way to connect multiple containers to meet Laravel's requirements, but similar techniques can also be applied using Docker Swarm, Kubernetes, or even individual Docker containers.
28+
The demonstrated examples can be found in the [GitHub repository](https://github.com/rw4lll/laravel-docker-examples). Docker Compose offers a straightforward approach to connecting multiple containers for Laravel, though similar setups can also be achieved using tools like Docker Swarm, Kubernetes, or individual Docker containers.
2929

3030
This guide is intended for educational purposes, helping developers adapt and optimize configurations for their specific use cases. Additionally, there are existing tools that support Laravel in containers:
3131

@@ -42,7 +42,3 @@ This guide is intended for educational purposes, helping developers adapt and op
4242

4343
- Developers who work with Laravel and want to streamline environment management.
4444
- DevOps engineers seeking efficient ways to manage and deploy Laravel applications.
45-
46-
## Tools integration
47-
48-
Docker Compose integrates seamlessly with the Docker CLI, CI/CD tools, and container orchestration platforms like Docker Swarm and Kubernetes. This makes defining, managing, and orchestrating Laravel applications consistent across all environments.

content/guides/frameworks/laravel/common-questions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Common Questions about using Laravel with Docker
2+
title: Common Questions on Using Laravel with Docker
33
description: Find answers to common questions about setting up and managing Laravel environments with Docker Compose, including troubleshooting and best practices.
44
weight: 40
55
---
@@ -8,17 +8,17 @@ weight: 40
88

99
### 1. Why should I use Docker Compose for Laravel?
1010

11-
Docker Compose is an effective tool for managing multi-container environments, particularly in development due to its simplicity. With Docker Compose, you can define and connect all necessary services for Laravel, such as PHP, Nginx, and databases, in a single configuration (`compose.yaml`). This setup ensures consistency across development, testing, and production environments, streamlining onboarding and reducing discrepancies between local and server setups.
11+
Docker Compose is a powerful tool for managing multi-container environments, particularly in development due to its simplicity. With Docker Compose, you can define and connect all necessary services for Laravel, such as PHP, Nginx, and databases, in a single configuration (`compose.yaml`). This setup ensures consistency across development, testing, and production environments, streamlining onboarding and reducing discrepancies between local and server setups.
1212

1313
While Docker Compose is a great choice for development, tools like **Docker Swarm** or **Kubernetes** offer advanced scaling and orchestration features, which may be beneficial for complex production deployments.
1414

1515
### 2. How do I debug my Laravel application with Docker Compose?
1616

17-
To debug your Laravel application in a Docker environment, you can use **Xdebug**. In the development setup, Xdebug is installed in the `php-fpm` container to enable debugging. Make sure to enable Xdebug in your `compose.yaml` file by setting the environment variable `XDEBUG_ENABLED=true` and configuring your IDE (e.g., Visual Studio Code or PHPStorm) to connect to the remote container for debugging.
17+
To debug your Laravel application in a Docker environment, use **Xdebug**. In the development setup, Xdebug is installed in the `php-fpm` container to enable debugging. Ensure Xdebug is enabled in your `compose.yaml` file by setting the environment variable `XDEBUG_ENABLED=true` and configuring your IDE (e.g., Visual Studio Code or PHPStorm) to connect to the remote container for debugging.
1818

1919
### 3. Can I use Docker Compose with databases other than PostgreSQL?
2020

21-
Yes, Docker Compose allows you to use various database services with Laravel. In the provided examples, we use PostgreSQL, but you can easily substitute **MySQL**, **MariaDB**, or even **SQLite**. Simply update the `compose.yaml` file to specify the required Docker image, and update your `.env` file to reflect the new database configuration.
21+
Yes, Docker Compose supports various database services for Laravel. While PostgreSQL is used in the examples, you can easily substitute **MySQL**, **MariaDB**, or even **SQLite**. Update the `compose.yaml` file to specify the required Docker image and adjust your `.env` file to reflect the new database configuration.
2222

2323
### 4. How can I persist data in development and production?
2424

content/guides/frameworks/laravel/development-setup.md

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,40 @@ weight: 20
66

77
## Development Environment Setup
88

9-
This guide demonstrates how to set up a development environment for a Laravel application using Docker Compose. This setup includes essential services such as PHP-FPM, Nginx, and a database (we will use Postgres, but MySQL/MariaDB can be easily set), which enable you to develop in an isolated and consistent environment.
9+
This guide demonstrates how to set up a development environment for a Laravel application using Docker and Docker Compose. This setup includes essential services like PHP-FPM, Nginx, and a database (using Postgres, with MySQL/MariaDB as alternatives), which enable you to develop in an isolated and consistent environment.
1010

1111
> [!NOTE]
1212
> If you want to quickly test this setup without configuring everything manually, you can download the [Laravel Docker Examples](https://github.com/rw4lll/laravel-docker-examples) repository. It includes pre-configured examples for both development and production environments.
1313
1414
### Project Structure
1515

16-
To start, create a project structure that will include both the Laravel application and Docker-related files:
16+
Start by creating a project structure that includes both the Laravel application and Docker-related files:
1717

1818
```
19-
example-app
20-
├── app, config, routes, tests, etc.
19+
my-laravel-app
20+
├── app/
21+
├── bootstrap/
22+
├── config/
23+
├── database/
24+
├── public/
2125
├── docker/
2226
│ ├── php-fpm
2327
│ │ └── Dockerfile
2428
│ │ └── entrypoint.sh
2529
│ ├── workspace
2630
│ │ └── Dockerfile
27-
│ └── web
31+
│ └── nginx
2832
│ └── nginx.conf
2933
├── compose.yaml
3034
├── .dockerignore
31-
└── .env
32-
└── other files
35+
├── .env
36+
├── vendor/
37+
├── ...
3338
```
3439

40+
This structure includes a typical Laravel app, with a `docker` directory for Docker-related files like `php-fpm` and `workspace` Dockerfiles, the `nginx.conf` config file, and the `compose.yaml` file to define the services.
3541

36-
This structure includes a typical Laravel app, with a `docker` directory for Docker-related files like `php-fpm` and `workspace` Dockerfiles, as well as `nginx.conf` config file, and the `compose.yaml` file to define the services.
37-
38-
39-
### Writing the Dockerfile for PHP-FPM
42+
### Create a Dockerfile for PHP-FPM
4043

4144
The PHP-FPM Dockerfile defines the environment in which PHP will run. Here is an example:
4245

@@ -45,9 +48,9 @@ The PHP-FPM Dockerfile defines the environment in which PHP will run. Here is an
4548
# For development environment we can use one-stage build for simplicity.
4649
FROM php:8.3-fpm
4750

48-
# Install system dependencies and PHP extensions required for Laravel + MySQL/PostgreSQL support
49-
# Some dependencies are required for PHP extensions only in the build stage
50-
# We don't need to install Node.js or build assets, as it was done in the Nginx image
51+
# Install system dependencies and PHP extensions for Laravel with MySQL/PostgreSQL support.
52+
# Certain dependencies are only needed for PHP extensions in this build stage.
53+
# Node.js and asset building are handled in the Nginx container.
5154
RUN apt-get update && apt-get install -y --no-install-recommends \
5255
curl \
5356
unzip \
@@ -126,7 +129,7 @@ CMD ["php-fpm"]
126129

127130
This Dockerfile installs the necessary PHP extensions required by Laravel, including database drivers and the Xdebug extension for debugging.
128131

129-
### Writing the Dockerfile for Workspace
132+
### Create a Dockerfile for Workspace
130133

131134
The workspace container is used to run Artisan commands, Composer, and NPM. Here's the Dockerfile for the workspace:
132135

@@ -197,7 +200,7 @@ RUN if getent group ${GID}; then \
197200
# Switch to the non-root user to install NVM and Node.js
198201
USER www
199202

200-
# Install NVM as the www user
203+
# Install NVM (Node Version Manager) as the www user
201204
RUN export NVM_DIR="$HOME/.nvm" && \
202205
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash && \
203206
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" && \
@@ -220,19 +223,19 @@ ENTRYPOINT []
220223
CMD ["bash"]
221224
```
222225

223-
### Docker Compose Configuration for Development
226+
### Create Docker Compose Configuration for Development
224227

225228
Here's the `compose.yaml` file to set up the development environment:
226229

227230
```yaml
228231
services:
229232
web:
230-
image: nginx:latest # We don't need to customize the image. Just pass the configuration to the Dockerfile.
233+
image: nginx:latest # Using the default Nginx image with custom configuration.
231234
volumes:
232235
# Mount the application code for live updates
233236
- ./:/var/www
234237
# Mount the Nginx configuration file
235-
- ./docker/web/nginx.conf:/etc/nginx/nginx.conf:ro
238+
- ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
236239
ports:
237240
# Map port 80 inside the container to the port specified by 'NGINX_PORT' on the host machine
238241
- "${NGINX_PORT:-80}:80"
@@ -324,10 +327,10 @@ volumes:
324327

325328
### Running Your Development Environment
326329

327-
To start your Laravel development environment, run the following command in your terminal:
330+
To start the development environment, use:
328331

329332
```sh
330-
$ docker compose up -d
333+
$ docker compose -f compose.yaml up --build -d
331334
```
332335

333336
This command will build and start all the required services, including PHP, Nginx, and the PostgreSQL database. You can now access your Laravel application at `http://localhost/`.

0 commit comments

Comments
 (0)