PHPackages                             malickteuwdev/docker-for-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [DevOps &amp; Deployment](/categories/devops)
4. /
5. malickteuwdev/docker-for-laravel

ActiveLibrary[DevOps &amp; Deployment](/categories/devops)

malickteuwdev/docker-for-laravel
================================

A complete Docker setup for Laravel applications with PostgreSQL, Nginx, and PHP-FPM

01PHP

Since Nov 3Pushed 6mo agoCompare

[ Source](https://github.com/MalickDevWeb/docker_for_laravel)[ Packagist](https://packagist.org/packages/malickteuwdev/docker-for-laravel)[ RSS](/packages/malickteuwdev-docker-for-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Docker for Laravel
==================

[](#docker-for-laravel)

[![Latest Version](https://camo.githubusercontent.com/37b8c51790f8c1467605544af2cbba7b6b7f3129cc2331cf14d753065b2a07b6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d616c69636b746575776465762f646f636b65722d666f722d6c61726176656c2e737667)](https://packagist.org/packages/malickteuwdev/docker-for-laravel)[![PHP Version](https://camo.githubusercontent.com/36abc1cc0fb0af7380a6ab0f2263432cafc1badc73ed0145a3e5cffa77364852/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d616c69636b746575776465762f646f636b65722d666f722d6c61726176656c2e737667)](https://packagist.org/packages/malickteuwdev/docker-for-laravel)[![License](https://camo.githubusercontent.com/7f37c071e467aba2abed4b5131e7bdbee1f0737ef778bcef352d203c6fea3603/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d616c69636b746575776465762f646f636b65722d666f722d6c61726176656c2e737667)](https://packagist.org/packages/malickteuwdev/docker-for-laravel)

A complete Docker setup for Laravel applications with PostgreSQL database, Nginx web server, and PHP-FPM. This package provides an easy-to-use environment for developing and deploying Laravel applications.

Features
--------

[](#features)

- **PHP 8.3** with essential extensions for Laravel
- **PostgreSQL 16** database
- **Nginx** web server with optimized configuration
- **Composer** for dependency management
- **Automatic port detection** to avoid conflicts
- **Production deployment** scripts
- **Database synchronization** tools
- **Permission management** for Laravel storage

Installation
------------

[](#installation)

### Via Composer

[](#via-composer)

```
composer require malickteuwdev/docker-for-laravel --dev
```

Or add it manually to your `composer.json`:

```
{
    "require-dev": {
        "malickteuwdev/docker-for-laravel": "^1.0"
    }
}
```

Then run:

```
composer install
```

### Manual Installation

[](#manual-installation)

If you prefer manual installation, you can download the package and copy the `docker/` directory and `docker-compose.yml` file into your Laravel project root.

Prerequisites
-------------

[](#prerequisites)

Before using this Docker setup, ensure you have the following installed on your system:

- [Docker](https://docs.docker.com/get-docker/) (version 20.10 or later)
- [Docker Compose](https://docs.docker.com/compose/install/) (version 2.0 or later)
- A Laravel project with `artisan` file in the root directory

Quick Start
-----------

[](#quick-start)

1. **Install the package via Composer** (see Installation section above)
2. **Initialize the environment:**

    ```
    php artisan docker:init
    ```

    Or if you prefer using the script directly:

    ```
    bash vendor/your-vendor/docker-for-laravel/docker/scripts/init.sh
    ```

    This script will:

    - Detect your Laravel project
    - Create/update the `.env` file with necessary variables
    - Detect a free port for the application
    - Build and start the Docker containers
    - Set proper permissions for Laravel storage
3. **Access your application:**Open your browser and navigate to `http://localhost:{APP_PORT}` (default: 8080)

Configuration
-------------

[](#configuration)

### Environment Variables

[](#environment-variables)

The setup uses the following environment variables (configured automatically in `.env`):

- `APP_PORT`: Port for the web application (auto-detected)
- `PROJECT_NAME`: Name of your project (defaults to directory name)
- `DB_CONNECTION`: Database connection (set to `pgsql`)
- `DB_HOST`: Database host (set to `db`)
- `DB_PORT`: Database port (5432)
- `DB_DATABASE`: Database name
- `DB_USERNAME`: Database username
- `DB_PASSWORD`: Database password
- `CONTAINER_SUFFIX`: Unique suffix for container names

### Customizing PHP Version

[](#customizing-php-version)

composer create-project laravel/laravel projet-laravel10 "10.\*"

To use a different PHP version, modify the `ARG PHP_VERSION` in `docker/php/Dockerfile`:

```
ARG PHP_VERSION=8.2  # or 8.1, 8.0, etc.
```

### Nginx Configuration

[](#nginx-configuration)

The Nginx configuration is in `docker/nginx/default.conf.template`. It includes:

- PHP-FPM upstream to the app container
- Optimized settings for Laravel
- Security headers (htaccess protection)

Usage
-----

[](#usage)

### Starting the Application

[](#starting-the-application)

```
php artisan docker:start
```

Or using the script directly:

```
bash vendor/malickteuwdev/docker-for-laravel/docker/scripts/init.sh
```

### Stopping the Application

[](#stopping-the-application)

```
php artisan docker:stop
```

Or:

```
docker compose down
```

### Rebuilding Containers

[](#rebuilding-containers)

```
php artisan docker:rebuild
```

Or:

```
docker compose up -d --build
```

### Accessing Containers

[](#accessing-containers)

```
# PHP container
php artisan docker:shell

# Database container
php artisan docker:db-shell
```

Or manually:

```
# PHP container
docker exec -it {PROJECT_NAME}_{CONTAINER_SUFFIX}_app bash

# Database container
docker exec -it {PROJECT_NAME}_{CONTAINER_SUFFIX}_db psql -U {DB_USERNAME} -d {DB_DATABASE}
```

### Laravel Artisan Commands

[](#laravel-artisan-commands)

```
php artisan docker:artisan migrate
php artisan docker:artisan cache:clear
```

Or directly:

```
docker exec {PROJECT_NAME}_{CONTAINER_SUFFIX}_app php artisan migrate
docker exec {PROJECT_NAME}_{CONTAINER_SUFFIX}_app php artisan cache:clear
```

Production Deployment
---------------------

[](#production-deployment)

For production deployment, use the provided script:

```
php artisan docker:deploy-prod
```

Or using the script directly:

```
bash vendor/malickteuwdev/docker-for-laravel/docker/scripts/deploy_prod.sh
```

This script will:

1. Create a `.env.production` file with production settings
2. Prompt for production database credentials
3. Dump your local database
4. Push the dump to the production database

**⚠️ Warning:** This will overwrite the production database. Make sure to backup your data first.

Database Synchronization
------------------------

[](#database-synchronization)

The database sync tool allows you to synchronize databases between local and remote environments:

```
php artisan docker:sync-db
```

Or using the script directly:

```
bash vendor/malickteuwdev/docker-for-laravel/docker/scripts/sync_db.sh
```

Choose between:

- **push**: Send local database to remote
- **pull**: Get remote database to local

The script includes safety features like optional remote backups before overwriting.

Laravel Integration
-------------------

[](#laravel-integration)

This package includes Laravel service provider integration for easier management:

### Service Provider

[](#service-provider)

The package registers a service provider that adds the following Artisan commands:

- `php artisan docker:init` - Initialize Docker environment
- `php artisan docker:start` - Start Docker containers
- `php artisan docker:stop` - Stop Docker containers
- `php artisan docker:rebuild` - Rebuild Docker containers
- `php artisan docker:shell` - Access PHP container shell
- `php artisan docker:db-shell` - Access database shell
- `php artisan docker:artisan {command}` - Run Laravel artisan commands in container
- `php artisan docker:deploy-prod` - Deploy to production
- `php artisan docker:sync-db` - Synchronize databases

### Publishing Assets

[](#publishing-assets)

To publish the Docker configuration files to your project:

```
php artisan vendor:publish --provider="MalickTeuwDev\DockerForLaravel\DockerForLaravelServiceProvider"
```

This will copy the Docker files to your project's root directory.

Project Structure
-----------------

[](#project-structure)

After publishing/installation, your project will have:

```
your-laravel-project/
├── docker/
│   ├── docker_for_laravel/     # (empty directory for potential future use)
│   ├── nginx/
│   │   └── default.conf.template  # Nginx configuration template
│   ├── php/
│   │   └── Dockerfile            # PHP-FPM container definition
│   └── scripts/
│       ├── init.sh              # Main initialization script
│       ├── setup_env.sh         # Environment setup
│       ├── entrypoint.sh        # Container entrypoint
│       ├── deploy_prod.sh       # Production deployment
│       ├── sync_db.sh           # Database sync
│       ├── helpers.sh           # Utility functions
│       └── detect_free_port.sh  # Port detection
├── docker-compose.yml           # Docker Compose configuration
└── vendor/
    └── your-vendor/
        └── docker-for-laravel/  # Package source

```

Troubleshooting
---------------

[](#troubleshooting)

### Common Issues

[](#common-issues)

1. **Port already in use:**

    - The setup automatically detects free ports
    - Check `APP_PORT` in your `.env` file
2. **Permission issues:**

    - The init script sets proper permissions automatically
    - If issues persist, run: ```
        docker exec {CONTAINER_NAME}_app chown -R www-data:www-data storage bootstrap/cache
        ```
3. **Database connection failed:**

    - Ensure containers are running: `docker compose ps`
    - Check database logs: `docker compose logs db`
    - Verify `.env` database settings
4. **Composer install fails:**

    - Check PHP version compatibility
    - Ensure proper file permissions

### Logs

[](#logs)

View logs for all services:

```
docker compose logs
```

View logs for specific service:

```
docker compose logs app
docker compose logs db
docker compose logs nginx
```

### Cleanup

[](#cleanup)

To completely reset the environment:

```
docker compose down --volumes --remove-orphans
docker system prune -f
```

Versioning
----------

[](#versioning)

This package follows [Semantic Versioning](https://semver.org/).

Contributing
------------

[](#contributing)

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

See [CHANGELOG](CHANGELOG.md) for recent changes.

Credits
-------

[](#credits)

- [Laravel](https://laravel.com/) - The PHP framework
- [Docker](https://www.docker.com/) - Container platform
- [PostgreSQL](https://www.postgresql.org/) - Database system

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance47

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/ecd4597cce343de35eb34abd6239dfc8a9fd1d4b43dc1d7ef4af01672bdeea3a?d=identicon)[MalickDevWeb](/maintainers/MalickDevWeb)

---

Top Contributors

[![demon003teuw-cyber](https://avatars.githubusercontent.com/u/240940154?v=4)](https://github.com/demon003teuw-cyber "demon003teuw-cyber (2 commits)")

### Embed Badge

![Health badge](/badges/malickteuwdev-docker-for-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/malickteuwdev-docker-for-laravel/health.svg)](https://phpackages.com/packages/malickteuwdev-docker-for-laravel)
```

###  Alternatives

[deployer/deployer

Deployment Tool

11.0k25.4M207](/packages/deployer-deployer)[appwrite/server-ce

End to end backend server for frontend and mobile apps.

55.3k84.2k](/packages/appwrite-server-ce)[pragmarx/health

Laravel Server &amp; App Health Monitor and Notifier

2.0k1.0M2](/packages/pragmarx-health)[felixfbecker/language-server-protocol

PHP classes for the Language Server Protocol

22476.7M6](/packages/felixfbecker-language-server-protocol)[heroku/heroku-buildpack-php

Toolkit for starting a PHP application locally, with or without foreman, using the same config for PHP and Apache2/Nginx as on Heroku

8161.3M10](/packages/heroku-heroku-buildpack-php)[tiamo/phpas2

PHPAS2 is a php-based implementation of the EDIINT AS2 standard

4674.7k](/packages/tiamo-phpas2)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
