Laravel 9 Docker template using PHP 8.1.6, nginx, redis, and Postgres SQL 14.4.
- Docker
- Dockerfile and docker compose V3 with Alpine
- Nginx
- Laravel 9
- Postgres 14.4
- PHP 8.1.6
- PHPStan
- PHP Mess Detector
- PHP Copy/Paste Detector
- PHP Coding Standard Fixer
- Laravel IDE Helper
- Laravel Telescope
- Prettier
- Prettier plugin for PHP
- Github Action
- Makefile
- API Error Handler
- Using UNIX-based system.
- Download and Install Docker.
The given configuration will be used by Docker to build the containers.
If you change NGINX_PORT
to other than port 8000 or PHP_PORT
to other than port 9000,
you need to adjust listen
and fastcgi_pass
in nginx configuration at
/nginx/default.conf
.
For example, if you change NGINX_PORT
to port 8005 or PHP_PORT
to port 9005, the
/nginx/default.conf
will be filled
like this:
server {
listen 8005;
...
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(\.+)$;
fastcgi_pass php:9005;
...
}
...
}
This command will build Docker Compose containers.
This command will run Docker Compose containers.
This command will open PHP container terminal.
The given DB credentials, DB port, and Redis port in /src/.env
must be equal to the given values in /.env
.
You also need to change DB_HOST
value in /src/.env
based on this format: {CONTAINER_PREFIX}_postgres
.
You can see the value of CONTAINER_PREFIX
in /.env
at the project root directory.
6. Go to http://localhost:8000/ or any port you assign to NGINX_PORT
in the root directory .env
file
This action will open Laravel application in a web browser.
If you want to open Laravel Telescope page, you can access
http://localhost:8000/telescope or any port you assign to NGINX_PORT
in the root directory .env
file.
To run NPM or composer command, your terminal need to be inside src
directory in PHP container terminal.
To do that, you need to open PHP container terminal by running make ex
on the project root directory.
Then, in the PHP container terminal, go to src
directory by running cd src
.
Makefile command can be run on the project root directory, where
Makefile
resides in.
make build
: build Docker Compose containersmake up
: run Docker Compose containersmake stop
: stop Docker Compose containersmake down
: remove Docker Compose containersmake purge
: remove Postgres SQL volume in host.make ex
: open PHP container terminalmake analyse
: run static analysis and store the result in/src/storage/logs/analyse.log
Your terminal needs to be inside
src
directory in PHP container terminal.
composer test
: run Laravel automated test in parallelcomposer ide-helper
: run Laravel IDE Helper
Your terminal needs to be inside
src
directory in PHP container terminal.