- https://github.com/vercel-community/php?tab=readme-ov-file find Vercel Deploy button to auto create git branch and Vercel project. Example project name: test-vercel
- git clone the repository
- cd to test-vercel then `composer create project laravel/laravel ./example-app
- copy all files in
example-app to test-vercel
- update the api/index.php to
<?php
/**
* Here is the serverless function entry
* for deployment with Vercel.
*/
require __DIR__.'/../public/index.php';
- Update vercel.json
{
"builds": [
{ "src": "/api/index.php", "use": "[email protected]" },
{ "src": "/public/**", "use": "@vercel/static" }
],
"routes": [
{
"src": "/(css|js)/(.*)",
"dest": "public/$1/$2"
},
{
"src": "/(.*)",
"dest": "/api/index.php"
}
]
}
# Remove "functions" : {...} block
- Vercel project > Settings > Output Directory = public
- Copy laravel .env into vercel’s Environment Variable.
- Configure to connect Postgres DB Xata.
- Encounter error not able to generate laravel.log. No solution.
- If getting deployment error
php: error while loading shared libraries: libssl.so.10: cannot open shared object file: No such file or directory just “Redeploy” without Build cache in Vercel.
- Vercel’s Laravel API route has to be /api/api/your-api-name/etc example: https://test-vercel-git-main-kl-game-centers-projects.vercel.app/api/api/admin/test?v=1. Due to vercel.json route defined to initial route in
api/index.php which only then routes to laravel’s api.php containing api prefix.