Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.

Commit 6e47eed

Browse files
committed
Laravel is now up and running with docker
- docker .env PHP mount points modified. For laravel, serving from /public/ should be done at the NGINX level. PHP still needs access to everything that is in /src/ - Renamed the nginx php.conf file into nginx-webserver.conf - changed nginx-webserver.conf to match more closely the official Laravel settings. The previous config did not work with the Laravel Routes - in the php Dockerfile, added error files init for xdebug and php-errors - made small changes in xdebug.ini (php container) to get rid of unwanted "error" messages such as Client is not listening. NOT TESTED WITH ACTUAL STEp-DEBUG yet. Next: try devcontainer Next: try localhost step-debug
1 parent d4cea02 commit 6e47eed

File tree

8 files changed

+123
-27
lines changed

8 files changed

+123
-27
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# this server config works with Laravel too
2+
server {
3+
listen 80;
4+
listen [::]:80 default_server;
5+
6+
# not needed for now
7+
# server_name example.com;
8+
9+
root /var/www/htdoc/public;
10+
11+
add_header X-Frame-Options "SAMEORIGIN";
12+
add_header X-Content-Type-Options "nosniff";
13+
14+
index index.php;
15+
16+
charset utf-8;
17+
18+
location / {
19+
try_files $uri $uri/ /index.php?$query_string;
20+
}
21+
22+
location = /favicon.ico { access_log off; log_not_found off; }
23+
location = /robots.txt { access_log off; log_not_found off; }
24+
25+
error_page 404 /index.php;
26+
27+
location ~* \.php$ {
28+
fastcgi_pass php:9000;
29+
30+
include fastcgi_params;
31+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
32+
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
33+
}
34+
35+
location ~ /\.(?!well-known).* {
36+
deny all;
37+
}
38+
}

.devcontainer/.docker/nginx/conf.d/php.conf

Lines changed: 0 additions & 14 deletions
This file was deleted.

.devcontainer/.docker/php/Dockerfile

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ ARG RUNTIME_PHP_IMAGE
44
# Use the specified image as the base
55
FROM ${RUNTIME_PHP_IMAGE}
66

7+
# create the log file and provide permission to the www-data user
8+
RUN touch /tmp/xdebug.log && chown www-data:www-data /tmp/xdebug.log
9+
10+
# same thing for the PHP error log
11+
RUN touch /var/log/php-errors.log && chown www-data:www-data /var/log/php-errors.log
12+
713
# Update the packages
814
# Install system packages required for MongoDB extension
915
RUN apt-get update \
@@ -51,4 +57,14 @@ RUN mv composer.phar /usr/local/bin/composer
5157

5258
# NOT REQUIRED
5359
# Change to non-root privilege
54-
# USER www-data
60+
# USER www-data
61+
62+
# Enable Error-logging in the PHP container
63+
# ----------------------------------------------------------
64+
65+
# RUN echo "error_log = /var/log/php-fpm.log" >> /usr/local/etc/php-fpm.d/docker.conf
66+
67+
#RUN echo "php_admin_value[error_log] = /var/log/php-fpm/www-error.log" >> /usr/local/etc/php-fpm.d/www.conf && \
68+
# echo "php_admin_flag[log_errors] = on" >> /usr/local/etc/php-fpm.d/www.conf && \
69+
# echo "catch_workers_output = yes" >> /usr/local/etc/php-fpm.d/www.conf
70+
Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,47 @@
11
# already loaded in /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
22
#zend_extension=xdebug
33

4+
; FIXME : should be elsewhere, like docker-php.ini
5+
error_log = /var/log/php-errors.log
6+
catch_workers_output = yes
7+
48
[xdebug]
5-
xdebug.mode=debug
6-
xdebug.client_host=host.docker.internal
7-
xdebug.start_with_request=yes
8-
;xdebug.discover_client_host=1
9+
10+
; enables step by step debugging
11+
; xdebug.mode=debug,develop
12+
xdebug.mode=develop
13+
14+
; xdebug.client_host=host.docker.internal
15+
16+
; set this to 'yes' to ALWAYS start a request/
17+
; it will complain if not debugger is found listening
18+
; default value is xdebug.start_with_request=trigger, which should be fine
19+
;
20+
; xdebug.start_with_request=yes
21+
xdebug.discover_client_host=1
22+
923
xdebug.client_port=9003
10-
xdebug.idekey=PHPSTORM
11-
xdebug.log=/tmp/xdebug.log
24+
25+
; No need. By default, this is redirected to the general log of
26+
; of your PHP container and visible from tools like Docker Desktop
27+
;
28+
;xdebug.log=/var/tmp/xdebug.log
29+
30+
; Color var_dumps when in CLI
31+
xdebug.cli_color=1
32+
33+
; redirect the xdebug log to the container's STDOUT (/proc/self/fd/1) or STDERR (/proc/self/fd/2)
34+
xdebug.log=/tmp/xdebug.log
35+
36+
; 2.x way to activate the debugger.
37+
; generates this message, if not debugger is listening:
38+
; NOTICE: PHP message: Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: host.docker.internal:9003
39+
;
40+
; xdebug.idekey=PHPSTORM
41+
42+
; NOTES
43+
;
44+
; the log error "Trigger value for 'XDEBUG_TRIGGER' not found, falling back to 'XDEBUG_SESSION'"
45+
; can be avoided by adding /?XDEBUG_SESSION=start to the page URL being browsed
46+
;
47+
; NOTICE: PHP message: Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: host.docker.internal:9003

.devcontainer/.env

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ NGINX_CONTAINER_PORT=80
66
NGINX_HOST_CONFD_DIR=./.docker/nginx/conf.d
77
NGINX_CONTAINER_CONFD_DIR=/etc/nginx/conf.d
88

9-
WEBROOT_HOST_PATH=../src/public
10-
WEBROOT_CONTAINER_PATH=/var/www/htdoc
9+
PHP_WEBROOT_HOST_PATH=../src/
10+
PHP_WEBROOT_CONTAINER_PATH=/var/www/htdoc
1111

12-
NGINX_WEBROOT_HOST_PATH=../src/public
12+
NGINX_WEBROOT_HOST_PATH=../src/
1313
NGINX_WEBROOT_CONTAINER_PATH=/var/www/htdoc
1414

1515
MYSQL_IMAGE=mysql:5.7

.devcontainer/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ services:
3636
RUNTIME_PHP_IMAGE: ${PHP_IMAGE}
3737
image: ${PHP_IMAGE}
3838
# container-path
39-
working_dir: ${WEBROOT_CONTAINER_PATH}
39+
working_dir: ${PHP_WEBROOT_CONTAINER_PATH}
4040
# disk local-path
4141
volumes:
42-
- ${WEBROOT_HOST_PATH}:${WEBROOT_CONTAINER_PATH}
42+
- ${PHP_WEBROOT_HOST_PATH}:${PHP_WEBROOT_CONTAINER_PATH}
4343

4444

4545
# MySQL Service

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,25 @@ The article mentions several ways to get a Laravel development environment up an
1515

1616
## .env file
1717

18-
Not included in this repo is the .env file that contains the MongoDB connection string with the username / password. You'll have to make a cope of the .env.example file and add this variable:
18+
#### Application key
19+
20+
Laravel might ask to generate a new application key. You can do it by running this command in the laravel project folder.
21+
22+
`php artisan key:generate`
23+
24+
#### MongoDB connection string
25+
26+
Not included in this repo is the Laravel .env file that contains the MongoDB connection string with the username / password. You'll have to make a cope of the .env.example file and add this variable:
1927

2028
`DB_URI=`
2129

2230
The complete URI looks like this:
2331

2432
`DB_URI=mongodb+srv://USERNAME:PASSWORD@clustername.subdomain.mongodb.net/?retryWrites=true&w=majority`
2533

34+
# Troubleshooting
35+
36+
2637
# Disclaimer
2738

2839
Use at your own risk; not a supported MongoDB product

src/public/index.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<?php
22

3+
//echo "hello Laravel world";
4+
5+
//phpinfo();
6+
37
use Illuminate\Contracts\Http\Kernel;
48
use Illuminate\Http\Request;
59

@@ -20,6 +24,8 @@
2024
require $maintenance;
2125
}
2226

27+
28+
2329
/*
2430
|--------------------------------------------------------------------------
2531
| Register The Auto Loader
@@ -48,8 +54,11 @@
4854

4955
$kernel = $app->make(Kernel::class);
5056

57+
// CRASH at the line below:
58+
5159
$response = $kernel->handle(
5260
$request = Request::capture()
5361
)->send();
5462

5563
$kernel->terminate($request, $response);
64+

0 commit comments

Comments
 (0)