X-Powered-By: PHP/8.2.16
You must add the APP_KEY
from your .env
file into the vercel.json
configuration.
To do this, you need to set the APP_KEY
in the env
section of the
vercel.json
file.
First, generate your APP_KEY
using the command php artisan key:generate
and then copy
the generated key into the vercel.json
file like this:
{ "version": 2, "framework": null, "functions": { "api/index.php": { "runtime": "vercel-php@0.6.0" } }, "routes": [ { "src": "/(.*)", "dest": "/api/index.php" }, { "src": "/(.*)", "dest": "public/$1" } ], "env": { "APP_ENV": "production", "APP_DEBUG": "true", "APP_URL": "https://yourprojectdomain.com", // Add your APP_KEY here "APP_KEY": "", // Add your APP_KEY here "APP_CONFIG_CACHE": "/tmp/config.php", "APP_EVENTS_CACHE": "/tmp/events.php", "APP_PACKAGES_CACHE": "/tmp/packages.php", "APP_ROUTES_CACHE": "/tmp/routes.php", "APP_SERVICES_CACHE": "/tmp/services.php", "VIEW_COMPILED_PATH": "/tmp", "CACHE_DRIVER": "array", "LOG_CHANNEL": "stderr", "SESSION_DRIVER": "cookie" } }
Additionally, to set up the build and output settings in Vercel, make sure to:
dist
folder in the root directory of your Laravel project. This folder will be
used to
store any build files or assets that will be served by Vercel.public
to ensure that the built files are served from the correct directory.
To test your newly created REST API, you can visit the /api/api/message
route on Vercel.
If you configured the route as shown earlier, visiting
https://laravel-vercel-preview.vercel.app/api/api/message
will return a JSON response like this:
{ "X-Powered-By": "'PHP/' . phpversion()" }
However, when running the application locally, you only need to visit /api/message
(without the
extra /api
prefix).
This is because Vercel uses serverless functions with specific routing, whereas Laravel's local development
server handles routes directly.