Deploy Laravel with Postgres
This guide deploys a Laravel app to Naijacloud with a managed Postgres database. At the end you’ll have Laravel serving its welcome page over HTTPS at your own naijacloud.app address, with sessions, cache and the job queue stored in Postgres and migrations run every time the app starts. The stack is Laravel 13 on PHP 8.4 and FrankenPHP, with Postgres 18, built from a Dockerfile in your GitHub repository.
laravelpostgresLaravel’s welcome page on your own naijacloud.app address. Every visit writes a session row to Postgres, and /up answers 200 when the app is healthy.
Before you start
- A Laravel app in a GitHub repository, with
composer.lockcommitted. Starting fresh? Runcomposer create-project laravel/laravel shopand push it. - PHP and Composer on your machine, to generate an app key.
- A Naijacloud account. The free tier covers this guide: one web service and one database.
Why this guide uses a Dockerfile
Naijacloud can build PHP apps without a Dockerfile, but for Laravel today you want one. Two reasons, both found on the run this guide is based on:
- A new Laravel app ships a
package.jsonwith Vite in it, so the detector reads the repo as a Vite static site rather than a PHP server. - The automatic PHP build uses PHP 8.3, and a current Laravel lock file needs PHP 8.4.
With a Dockerfile at the root of the repo, Naijacloud builds and runs that instead, and the build log says Building from your Dockerfile.
Add the Dockerfile
This one uses the FrankenPHP image, a production PHP server, adds the Postgres driver and Composer, installs your dependencies, checks the app's health on Laravel's /up route, and on start runs migrations before serving on the port Naijacloud gives it:
Keep your local dependencies and secrets out of the image:
Trust the proxy
Naijacloud terminates HTTPS in front of the app. Tell Laravel to trust the forwarded headers so it generates https:// URLs. In bootstrap/app.php:
Create the database
In the dashboard, open your project and choose New service → Database. Name it shop-db, pick Postgres, choose the Free size and click Create database. On the shop-db is ready. screen, click Reveal secrets and copy the Internal URL. The password is shown once on this page.
Create the web service
Choose New service → Web service, name it shop and pick your repository and branch on the GitHub tab. Then:
- Under Run it as, choose Server. The detector suggests Static site because of Vite.
- Open Advanced and set Port to
8000, the port the Dockerfile listens on when Naijacloud setsPORT.
The build and start commands in the form don’t run for this service: the Dockerfile’s RUN and CMD do.
Set the variables
Generate an app key on your machine:
Under Environment variables, click Paste .env and paste these, with your own values, then Add variables:
base64:productionfalsehttps://shop.naijacloud.apppgsqlstderr, so Laravel’s logs appear under LogsDeploy and open it
Leave the size on Free and click Create web service. Free apps may sleep when nobody visits for a while and wake on the next request; paid apps never sleep. When the deploy goes live, the runtime log shows the migrations:
Open https://shop.naijacloud.app. Laravel’s welcome page loads, and the visit has written your first row to the sessions table in Postgres. https://shop.naijacloud.app/up is Laravel’s health route; set it as the Health check path under Advanced if you want each deploy to wait for it.