π 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:
- Fork the repo: https://github.com/render-examples/php-laravel-docker
- Add my
/api/me
route directly inroutes/api.php
- Update
AppServiceProvider
to force HTTPS in production:
public function boot(UrlGenerator $url)
{
if (env('APP_ENV') === 'production') {
$url->forceScheme('https');
}
}
- Generate an
APP_KEY
locally:
php artisan key:generate --show
- Push changes to GitHub and connect the repo to Render
- Add environment variables (
APP_KEY
,APP_ENV=production
,APP_DEBUG=false
) - 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:
- Create a Dockerfile for PHP + Nginx
- Configure
.dockerignore
to skip unnecessary files - Add a startup script to run:
composer install --no-dev
php artisan config:cache
php artisan route:cache
php artisan migrate --force
- Connect your GitHub repo to Render with Docker runtime
- Add environment variables as needed
- 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
- Live API Example: https://hng-13-stage0.onrender.com/api/me
- GitHub Repo: https://github.com/samthatcode/php-laravel-docker
- Render Documentation
- Cat Facts API
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)