Coding and ProgrammingTutorials

How to Deploy Laravel PHP application on Coolify: A Complete Tutorial

Share This Post, Help Others!

As a developer who has managed deployments across various platforms, I've found myself increasingly frustrated with the limitations of traditional hosting solutions. The escalating costs of platform-as-a-service providers, coupled with reduced flexibility on their free tiers, led me on a quest for a more sustainable solution. That's when I discovered Coolify, an open-source, self-hostable alternative to popular platforms like Heroku and Netlify .

Why I Choose Coolify for Laravel Deployment

What immediately appealed to me about Coolify was its promise of giving developers complete control over their infrastructure without sacrificing the convenience of modern deployment workflows. After extensively testing it with multiple Laravel applications, I can confidently say it delivers on this promise. In this comprehensive guide, I'll walk you through the entire process of deploying a Laravel application with Coolify, sharing insights from my experience to help you avoid common pitfalls.

How to Deploy Laravel PHP application on Coolify: A Complete Tutorial

Coolify is particularly well-suited for Laravel deployments because it understands the framework's specific needs – queues, schedulers, databases, and storage management. Whether you're a solo developer looking to reduce hosting costs or part of a team needing more deployment flexibility, this guide will provide you with the technical depth needed to successfully deploy your Laravel applications with Coolify.

Understanding Coolify and How It Compares to Alternatives

What Exactly Is Coolify?

Coolify is a self-hosted deployment platform that functions as a complete application hosting environment. Under the hood, it uses Docker and Traefik to manage containerization and traffic routing, providing a similar experience to commercial platforms but with full control over your infrastructure . It supports deploying not just your application code, but also adjacent services like databases, Redis instances, and other components that Laravel applications typically require.

big-data-visualization-securityPin
Laravel PHP application on Coolify

One of Coolify's most powerful features is its support for multiple deployment methods. You can deploy directly from your Git repository using buildpacks (specifically Nixpacks), use a Dockerfile, or even deploy pre-built Docker images . This flexibility means you can adapt Coolify to your existing development workflow rather than having to change your process to fit the platform.

Coolify vs. The Competition

When evaluating deployment platforms, it's helpful to understand how Coolify compares to other popular options. Here's a comparative analysis based on my experience with these platforms:

FeatureCoolifyHerokuNetlifyVercel
Hosting ModelSelf-hostedSaaSSaaSSaaS
Cost StructureFree (infrastructure cost only)Expensive at scaleFreemiumFreemium
CustomizationHighModerateLowLow
Laravel SupportExcellentGoodLimitedLimited
Database IntegrationBuilt-inAdd-onsExternal onlyExternal only
Learning CurveModerateLowLowLow
Infrastructure ControlCompleteLimitedLimitedLimited

This comparison reveals Coolify's unique position: it offers the developer experience of platform-as-a-service solutions while maintaining the control and cost-effectiveness of self-hosted infrastructure . For Laravel applications specifically, Coolify stands out because it can host your entire application ecosystem – including databases and queues – in one place without relying on external services .

Preparing for Deployment: What You'll Need

Before diving into the deployment process, you need to ensure you have the proper foundation. Based on my experience, here's what you'll need:

  • A server running Coolify: This can be a VPS from providers like DigitalOcean, Linode, or AWS. The server should have at least 2GB RAM and 2 CPU cores to comfortably run both Coolify and your Laravel application.
  • Your Laravel application code in a Git repository: Coolify supports GitHub, GitLab, and other Git repositories. Your repository should include the typical Laravel structure with proper .env configuration.
  • Basic understanding of Docker concepts: While Coolify abstracts away much of the Docker complexity, understanding concepts like containers, images, and volumes will help tremendously when troubleshooting.
  • Domain name pointed to your server (optional but recommended for production): You can deploy without a custom domain, but for production applications, you'll want a proper domain configured.

I strongly recommend testing the deployment process with a non-critical Laravel project first. This allows you to familiarize yourself with Coolify's interface and workflow without pressure.

How to Deploy Laravel Application on Coolify: Two Effective Methods

Through trial and error with various Laravel projects, I've identified two particularly effective deployment approaches. The Nixpacks method works well for standard Laravel applications, while the Docker approach gives you more control for complex applications.

Method 1: Install Laravel on Coolify Using Nixpacks (Recommended for Most Applications)

Nixpacks is Coolify's default build system that automatically detects your application type and configures the build process accordingly . For most Laravel applications, this is the simplest approach.

Application Configuration in Coolify

  1. In your Coolify dashboard, create a new project and add a resource
  2. Connect your Git repository and set the build pack to Nixpacks
  3. Set the Port Exposes to 80
  4. Configure the base directory if your Laravel application isn't in the repository root

Environment Variables Configuration

Environment variables are crucial for Laravel applications. In Coolify, navigate to the Environment Variables section and add at minimum:

APP_NAME="Your Laravel App"
APP_ENV=production
APP_KEY=base64:your_generated_key
APP_DEBUG=false
APP_URL=https://yourdomain.com

# Database configuration
DB_CONNECTION=mysql
DB_HOST=your_database_host
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_username
DB_PASSWORD=your_password

# Additional Laravel settings
LOG_CHANNEL=stack
CACHE_DRIVER=redis
QUEUE_CONNECTION=database
SESSION_DRIVER=file

Remember to generate your application key using php artisan key:generate locally and add it to the Coolify environment variables before deployment.

Advanced Process Management with Nixpacks

For Laravel applications, you typically need to run multiple processes: the web server, queue worker, and scheduler. Coolify supports this through a nixpacks.toml configuration file that uses Supervisor to manage multiple processes .

Create a nixpacks.toml file in your repository root with this configuration:

[phases.setup]
nixPkgs = ["...", "python311Packages.supervisor"]

[phases.build]
cmds = [
    "mkdir -p /etc/supervisor/conf.d/",
    "cp /assets/worker-*.conf /etc/supervisor/conf.d/",
    "cp /assets/supervisord.conf /etc/supervisord.conf",
    "chmod +x /assets/start.sh",
    "..."
]

[start]
cmd = '/assets/start.sh'

This configuration ensures that your web server, PHP-FPM, and Laravel queue workers all run simultaneously within the same container .

Method 2: Using Docker for More Control

For more complex Laravel applications or when you need specific customizations, the Docker approach gives you complete control over the environment.

Creating an Optimized Dockerfile

Based on my experience, the ServersideUp PHP images work exceptionally well for Laravel applications. Create a Dockerfile in your project root:

FROM serversideup/php:8.3-fpm-nginx

ENV PHP_OPCACHE_ENABLE=1

USER root

RUN curl -sL https://deb.nodesource.com/setup_20.x | bash -
RUN apt-get install -y nodejs

COPY --chown=www-data:www-data . /var/www/html

USER www-data

RUN npm install
RUN npm run build

RUN composer install --no-interaction --optimize-autoloader --no-dev

This Dockerfile provides an optimized production environment with PHP 8.3, Nginx, Node.js for frontend assets, and Composer for PHP dependencies .

Docker Compose Configuration for Multi-Container Setup

For Laravel applications that require additional services like queues and schedulers, Coolify supports Docker Compose configurations:

services:
  app:
    image: 'yourusername/your-laravel-app:latest'
    volumes:
      - './storage:/var/www/html/storage'
  scheduler:
    image: 'yourusername/your-laravel-app:latest'
    command: [ "php", "/var/www/html/artisan", "schedule:work" ]
    volumes:
      - './storage:/var/www/html/storage'
    environment:
      PHP_FPM_POOL_NAME: app_scheduler
  horizon:
    image: 'yourusername/your-laravel-app:latest'
    command: [ "php", "/var/www/html/artisan", "horizon" ]
    volumes:
      - ./storage:/var/www/html/storage
    environment:
      PHP_FPM_POOL_NAME: "app_horizon"

This approach allows you to run specialized containers for different parts of your Laravel application while sharing the same codebase .

Advanced Configuration and Troubleshooting

Adding a Database to Your Laravel Application

One of Coolify's strengths is its built-in database support . To add a database to your Laravel application:

  1. In your Coolify project, click “+ New Resource”
  2. Select your preferred database (MySQL, PostgreSQL, or Redis)
  3. Choose the same server and destination as your Laravel application
  4. Coolify will auto-generate database credentials

Update your Laravel application's environment variables in Coolify with the generated database credentials. For Docker Compose deployments, ensure “Connect To Predefined Network” is enabled so your application container can communicate with the database container .

Handling Storage Permissions

A common issue when deploying Laravel with Coolify is storage permissions. The Laravel storage directory needs proper write permissions. If you encounter permission errors:

  1. In Coolify, navigate to “Storages” and copy your storage volume path
  2. Go to “Command Center” and select your server
  3. Execute these commands with your actual storage path:
mkdir -p /path/to/your/storage/framework/{sessions,views,cache}
chmod -R 775 /path/to/your/storage/framework

This ensures the correct directory structure exists with proper permissions for Laravel to write cache, session, and view files .

Domain Configuration and SSL

To connect your custom domain:

  1. In your domain registrar, create an A record pointing to your Coolify server IP
  2. In Coolify, go to your application's settings and find the “Domains” section
  3. Add your domain in the format: https://yourdomain.com:port
  4. For ServersideUp images, the internal port is typically 8080

Coolify automatically provisions SSL certificates through Let's Encrypt, enabling HTTPS for your domain without additional configuration.

Coolify Review: Pros, Cons, and Performance Insights

After deploying multiple Laravel applications with Coolify, I've developed a nuanced perspective on its strengths and weaknesses.

how-to-deploy-laravel-php-application-on-coolifyPin
How to Deploy Laravel PHP application on Coolify: A Complete Tutorial

Advantages of Using Coolify

  • Complete Infrastructure Control: Unlike platform-as-a-service solutions where you're limited to their environment, Coolify gives you full control over server configuration, PHP versions, and extensions
  • Significant Cost Savings: After the initial server setup, you can deploy unlimited applications without per-app hosting fees, making it exceptionally cost-effective for multiple projects
  • Excellent Laravel Integration: With built-in support for queues, schedulers, and databases, Coolify understands Laravel's architecture and provides appropriate tooling
  • Open Source Transparency: As open-source software, you can inspect the code, contribute improvements, and ensure there are no unwanted tracking mechanisms
  • Flexible Deployment Options: Support for multiple build methods (Nixpacks, Dockerfile, Docker Compose) means you can choose the approach that best fits your application's complexity

Limitations and Considerations

  • Initial Setup Complexity: While Coolify simplifies deployment, you're still responsible for server maintenance, security updates, and backups
  • Self-Hosting Responsibility: Unlike managed platforms, you troubleshoot issues yourself when they arise, which requires stronger system administration skills
  • Resource Management: Since you're managing your own server, you need to monitor resource usage and scale appropriately as your application grows
  • Learning Curve: While more accessible than raw Docker management, Coolify still has a steeper learning curve than fully managed platforms like Heroku

Performance Observations

In my testing, Laravel applications deployed through Coolify perform comparably to those on traditional VPS hosting, with the containerization providing good isolation between applications. The automatic SSL provisioning and Traefik routing add minimal overhead while significantly simplifying production deployment.

Frequently Asked Questions

Can Coolify handle Laravel queues and task scheduling?

Yes, Coolify can efficiently manage Laravel queues and schedulers. Through the Supervisor configuration in Nixpacks or by using multiple containers in Docker Compose, you can run queue workers and the scheduler alongside your web application . For Docker Compose deployments, you can create dedicated containers for these processes with specific Artisan commands .

How do I set up a database with my Laravel application in Coolify?

Coolify makes database setup straightforward. Add a new database resource to your project, and Coolify will automatically generate credentials . You then add these credentials to your application's environment variables. For Docker Compose deployments, ensure network connectivity is enabled between your application and database containers.

What's the difference between Nixpacks and Docker deployment in Coolify?

Nixpacks is Coolify's automated build system that detects your application type and creates an appropriate environment, ideal for standard Laravel applications . Docker deployment gives you more control over the environment, allowing custom configurations and multi-service setups, which is better for complex applications with specific requirements .

How do I manage environment variables for my Laravel app in Coolify?

Coolify provides an Environment Variables section in each resource's configuration. You can add all your Laravel environment variables here, including app keys, database credentials, and service API keys . For sensitive information, Coolify securely stores these values and makes them available to your application at runtime.

Can I deploy other PHP frameworks besides Laravel with Coolify?

Absolutely. While this guide focuses on Laravel, Coolify supports any PHP application, including Symfony, CodeIgniter, and custom PHP projects . The configuration would be similar, adjusting for framework-specific requirements like document roots and entry points.

Conclusion: Is Coolify the Right Choice for Your Laravel Applications?

Having deployed numerous Laravel applications with Coolify across different scenarios, I can confidently recommend it for developers seeking more control over their deployment infrastructure without reverting to completely manual server management.

Coolify strikes a remarkable balance between the convenience of platform-as-a-service and the flexibility of self-hosting. For Laravel developers specifically, its understanding of the framework's needs – queues, schedulers, databases, and storage – makes it exceptionally well-suited compared to generic deployment tools.

The initial investment in setting up Coolify and learning its workflow pays significant dividends through reduced hosting costs, eliminated platform lock-in, and complete architectural control. While it requires more upfront technical knowledge than managed platforms, the long-term benefits of mastering this tool make it worthwhile for serious Laravel developers.

As you begin your Coolify journey, start with a non-critical project to familiarize yourself with the deployment process. Once comfortable, you'll find that deploying Laravel applications becomes faster, more predictable, and considerably more cost-effective. The open-source nature of Coolify means you're investing in a skill set that transcends the tool itself, giving you deeper insight into modern application deployment patterns that will serve you well regardless of how the platform evolves.

Share This Post, Help Others!

Other Popular Articles ...

One Comment

Leave a Reply

Back to top button
Sharing is caring

Ad Blocker Detected :(

Please consider supporting us by disabling your ad blocker.

من فضلك قم بتعطيل أداة مانع الإعلانات أدبلوك من المتصفح للدخول للموقع أو إستخدم متصفح آخر
شكرا لتفهمك وزيارتك