A demo repo for deploying a Laravel PHP application on Render using Docker. You can follow the getting started tutorial here.
-
Create a new PostgreSQL database on Render and copy the internal DB URL to use below.
-
Fork this repo to your own GitHub account.
-
Create a new Web Service on Render, and give Render's GitHub app permission to access your new repo.
-
Select
Dockerfor the environment, and add the following environment variable under the Advanced section:Key Value APP_KEYCopy the output of php artisan key:generate --showDATABASE_URLThe internal database url for the database you created above. DB_CONNECTIONpgsql
Certainly! Here's a comprehensive README tailored for your Laravel-based API project hosted on Render:
Welcome to my submission for HNG i13 Stage 0! This project showcases a simple Laravel-based API endpoint that returns my profile information along with a dynamic cat fact fetched from an external API.
You can access the live API endpoint here:
👉 https://hng-13-stage0.onrender.com/api/me
- Backend Framework: Laravel 11
- Containerization: Docker
- Hosting Platform: Render
- External API: Cat Facts API (https://catfact.ninja/fact)
- Programming Language: PHP
{
"status": "success",
"user": {
"email": "youremail@example.com",
"name": "Your Full Name",
"stack": "Laravel/PHP"
},
"timestamp": "2025-10-18T12:45:32.567Z",
"fact": "Cats sleep for 70% of their lives."
}-
status: Always
"success". -
user: Object containing:
- email: Your personal email address.
- name: Your full name.
- stack: Your backend technology stack (e.g., "Laravel/PHP").
-
timestamp: Current UTC time in ISO 8601 format.
-
fact: A random cat fact fetched from the Cat Facts API.
Start by forking the official Render example repository:
👉 https://github.com/render-examples/php-laravel-docker
Clone your forked repository to your local machine:
git clone https://github.com/yourusername/php-laravel-docker.git
cd php-laravel-dockerEdit the routes/api.php file to include the following route:
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Carbon;
Route::get('/me', function () {
try {
$response = Http::timeout(5)->get('https://catfact.ninja/fact');
$catFact = $response->successful()
? $response->json('fact')
: 'Could not fetch cat fact at the moment.';
} catch (\Exception $e) {
$catFact = 'Error fetching cat fact: ' . $e->getMessage();
}
return response()->json([
'status' => 'success',
'user' => [
'email' => 'youremail@example.com',
'name' => 'Your Full Name',
'stack' => 'Laravel/PHP',
],
'timestamp' => Carbon::now('UTC')->toISOString(),
'fact' => $catFact,
]);
});To ensure all URLs use HTTPS in the production environment, update the AppServiceProvider:
namespace App\Providers;
use Illuminate\Routing\UrlGenerator;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function boot(UrlGenerator $url)
{
if (env('APP_ENV') === 'production') {
$url->forceScheme('https');
}
}
}Run the following command to generate the application key:
php artisan key:generate --showCopy the generated key for use in the next step.
-
Go to Render and create a new Web Service.
-
Connect your GitHub account and select the forked repository.
-
Choose Docker as the runtime.
-
Under "Environment Variables", add the following:
APP_KEY: The key generated in the previous step.APP_ENV:productionAPP_DEBUG:false
-
Click "Create Web Service" to deploy your application.
Render will automatically build and deploy your Laravel application.
- Live Endpoint: https://hng-13-stage0.onrender.com/api/me
- GitHub Repository: https://github.com/samthatcode/php-laravel-docker
- Full Name: Your Full Name
- Email: youremail@example.com
- Stack: Laravel/PHP
This project enhanced my understanding of:
- Building RESTful APIs with Laravel.
- Integrating external APIs to fetch dynamic data.
- Deploying PHP applications using Docker.
- Hosting applications on Render.
Check out my detailed post on this project:
Feel free to reach out for collaborations or discussions!
Let me know if you need further assistance or modifications to this README!
That's it! Your Laravel 11 app will be live on your Render URL as soon as the build finishes. You can test it out by registering and logging in.
