You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/guides/frameworks/laravel/_index.md
+3-7Lines changed: 3 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: Develop and run Laravel applications with Docker Compose
2
+
title: Develop and Deploy Laravel applications with Docker Compose
3
3
linkTitle: Laravel applications with Docker Compose
4
4
summary: Learn how to efficiently set up Laravel development and production environments using Docker Compose.
5
5
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:
23
23
external: true
24
24
---
25
25
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.
27
27
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.
29
29
30
30
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:
31
31
@@ -42,7 +42,3 @@ This guide is intended for educational purposes, helping developers adapt and op
42
42
43
43
- Developers who work with Laravel and want to streamline environment management.
44
44
- 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.
Copy file name to clipboardExpand all lines: content/guides/frameworks/laravel/common-questions.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: Common Questions about using Laravel with Docker
2
+
title: Common Questions on Using Laravel with Docker
3
3
description: Find answers to common questions about setting up and managing Laravel environments with Docker Compose, including troubleshooting and best practices.
4
4
weight: 40
5
5
---
@@ -8,17 +8,17 @@ weight: 40
8
8
9
9
### 1. Why should I use Docker Compose for Laravel?
10
10
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.
12
12
13
13
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.
14
14
15
15
### 2. How do I debug my Laravel application with Docker Compose?
16
16
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.
18
18
19
19
### 3. Can I use Docker Compose with databases other than PostgreSQL?
20
20
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.
22
22
23
23
### 4. How can I persist data in development and production?
Copy file name to clipboardExpand all lines: content/guides/frameworks/laravel/development-setup.md
+24-21Lines changed: 24 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,37 +6,40 @@ weight: 20
6
6
7
7
## Development Environment Setup
8
8
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.
10
10
11
11
> [!NOTE]
12
12
> 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.
13
13
14
14
### Project Structure
15
15
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:
17
17
18
18
```
19
-
example-app
20
-
├── app, config, routes, tests, etc.
19
+
my-laravel-app
20
+
├── app/
21
+
├── bootstrap/
22
+
├── config/
23
+
├── database/
24
+
├── public/
21
25
├── docker/
22
26
│ ├── php-fpm
23
27
│ │ └── Dockerfile
24
28
│ │ └── entrypoint.sh
25
29
│ ├── workspace
26
30
│ │ └── Dockerfile
27
-
│ └── web
31
+
│ └── nginx
28
32
│ └── nginx.conf
29
33
├── compose.yaml
30
34
├── .dockerignore
31
-
└── .env
32
-
└── other files
35
+
├── .env
36
+
├── vendor/
37
+
├── ...
33
38
```
34
39
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.
35
41
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
40
43
41
44
The PHP-FPM Dockerfile defines the environment in which PHP will run. Here is an example:
42
45
@@ -45,9 +48,9 @@ The PHP-FPM Dockerfile defines the environment in which PHP will run. Here is an
45
48
# For development environment we can use one-stage build for simplicity.
46
49
FROM php:8.3-fpm
47
50
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.
51
54
RUN apt-get update && apt-get install -y --no-install-recommends \
52
55
curl \
53
56
unzip \
@@ -126,7 +129,7 @@ CMD ["php-fpm"]
126
129
127
130
This Dockerfile installs the necessary PHP extensions required by Laravel, including database drivers and the Xdebug extension for debugging.
128
131
129
-
### Writing the Dockerfile for Workspace
132
+
### Create a Dockerfile for Workspace
130
133
131
134
The workspace container is used to run Artisan commands, Composer, and NPM. Here's the Dockerfile for the workspace:
132
135
@@ -197,7 +200,7 @@ RUN if getent group ${GID}; then \
197
200
# Switch to the non-root user to install NVM and Node.js
198
201
USER www
199
202
200
-
# Install NVM as the www user
203
+
# Install NVM (Node Version Manager) as the www user
# Map port 80 inside the container to the port specified by 'NGINX_PORT' on the host machine
238
241
- "${NGINX_PORT:-80}:80"
@@ -324,10 +327,10 @@ volumes:
324
327
325
328
### Running Your Development Environment
326
329
327
-
To start your Laravel development environment, run the following command in your terminal:
330
+
To start the development environment, use:
328
331
329
332
```sh
330
-
$ docker compose up -d
333
+
$ docker compose -f compose.yaml up --build -d
331
334
```
332
335
333
336
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