DEV Community

Cover image for How to Deploy a Laravel API Easily Using Render
Samuel Osho
Samuel Osho

Posted on

How to Deploy a Laravel API Easily Using Render

πŸš€ How to Deploy a Laravel API Easily Using Render

Hey fellow developers πŸ‘‹

I recently completed Stage 0 of the HNG i13 Backend Track, where I built a dynamic Laravel API endpoint that returns my profile info along with a random cat fact. During this process, I explored different ways to deploy Laravel apps on Render, and I wanted to share my experience so others can learn and experiment.

πŸ’‘ The Goal

Create a simple API endpoint:

/api/me

That returns:

  • Email, name, and backend stack
  • Current UTC timestamp (ISO 8601)
  • A dynamic cat fact fetched from Cat Facts API

βš™οΈ Tools & Technologies

  • Laravel 11
  • PHP HTTP Client
  • Carbon for timestamps
  • Render.com for hosting (Docker support)

πŸ› οΈ Two Ways to Deploy Laravel on Render

During my deployment process, I learned there are two main approaches:

1️⃣ Fork Render’s Example Laravel Docker Repo (Recommended for beginners)

Render provides a ready-made Laravel + Docker example repo.

Steps I followed:

  1. Fork the repo: https://github.com/render-examples/php-laravel-docker
  2. Add my /api/me route directly in routes/api.php
  3. Update AppServiceProvider to force HTTPS in production:
public function boot(UrlGenerator $url)
{
    if (env('APP_ENV') === 'production') {
        $url->forceScheme('https');
    }
}
Enter fullscreen mode Exit fullscreen mode
  1. Generate an APP_KEY locally:
php artisan key:generate --show
Enter fullscreen mode Exit fullscreen mode
  1. Push changes to GitHub and connect the repo to Render
  2. Add environment variables (APP_KEY, APP_ENV=production, APP_DEBUG=false)
  3. Render builds and deploys automatically πŸš€

βœ… Pros: Quick, minimal setup, ideal for small projects or testing APIs
❌ Cons: Less control over Docker customization

2️⃣ Deploy Your Own Laravel App Using Docker From Scratch

For developers comfortable with Docker:

  1. Create a Dockerfile for PHP + Nginx
  2. Configure .dockerignore to skip unnecessary files
  3. Add a startup script to run:
composer install --no-dev
php artisan config:cache
php artisan route:cache
php artisan migrate --force
Enter fullscreen mode Exit fullscreen mode
  1. Connect your GitHub repo to Render with Docker runtime
  2. Add environment variables as needed
  3. Render builds and deploys

βœ… Pros: Full control, production-ready setup, scalable
❌ Cons: Slightly more setup, more technical knowledge needed

πŸ“ Key Takeaways

  • Even small API tasks teach good practices: structured JSON, dynamic responses, error handling.
  • Render makes deployment easy for both beginners and experienced devs.
  • Using existing examples can save time and reduce friction.
  • Experimenting with both approaches helps you understand Dockerized vs. pre-configured hosting.

πŸ”— References & Resources

Sharing this to help other Laravel devs deploy quickly, experiment, and learn. Even small, fun APIs are a great way to practice dynamic data handling and deployment skills.

#Laravel #PHP #WebDevelopment #API #HNGi13 #Docker #Render #DevTips #LearningByDoing

Top comments (0)