Problem
I am building a web application using a modern frontend stack (Vite, TailwindCSS, Flowbite, and SweetAlert2) powered by a PHP backend. Initially, this project was developed and tested successfully on my local machine using a Laragon/MySQL setup.
To deploy the application on Vercel, I decided to upgrade my database and migrate from MySQL to Supabase (PostgreSQL). While the application and the Supabase connection work perfectly on my local environment, the database connection completely fails after deploying to Vercel, despite the frontend loading successfully.
Current Behavior
- Frontend loads perfectly, but API calls to
/api/beneficiaries.phpreturn a500status. - My DB diagnostic endpoint confirms the following:
db_connection=pgsqluse_supabase=truehost/port/db/user/passwordare all set correctlydb_sslmode=requirepdo_pgsql_loaded=true
Despite this, it still fails with the error:
Error: Could not connect to database. Please check your configuration.
Expected Behavior
PHP API functions deployed on Vercel should successfully connect to the Supabase Postgres database and return data, exactly as they do on my local machine.
Steps to Reproduce
- Deploy project to Vercel with PHP functions (
vercel-php@0.7.4) and Vite-built frontend. - Set production environment variables:
DB_CONNECTION=pgsqlDB_HOSTDB_PORT=5432DB_DATABASEDB_USERNAMEDB_PASSWORDDB_SSLMODE=requireAPP_ENV=productionENV_KEY=production
- Open the diagnostic endpoint:
https://dole-system.vercel.app/api/auth.php?db_test=1 - The output returned is:
{ "success": false, "error": "Could not connect to database..." }
Project Information
- URL: https://dole-system.vercel.app
- Frontend: Vite, TailwindCSS, Flowbite, SweetAlert2
- Backend: PHP API on Vercel Serverless (
vercel-php@0.7.4) - Database: Supabase Postgres (Direct connection)
- Runtime config confirmed via script:
db_connection=pgsqluse_supabase=truedb_sslmode=requirepdo_pgsql_loaded=true
Main Question
What are the most likely causes when PHP on Vercel reports all DB variables as present and the pgsql extension as loaded, but the PDO connection still fails to reach Supabase Postgres?
Is there any Vercel-specific networking, SSL, or connection-string requirement for connecting to Supabase using PHP serverless functions?