Enjoyable & powerful
Made with
Let's picture you want to deploy your awesome microproject written in PHP and you don't know where. You have found Vercel it's awesome, but for static sites. Not anymore! I would like to introduce you your new best friend vercel-php
, PHP runtime for Vercel platform.
Most simple example project is this one, using following project structure.
project
├── api
│ └── index.php
└── vercel.json
First file api/index.php
is entrypoint of our application. It should be placed in api folder, it's very standard location for Vercel.
<?php
phpinfo();
Second file vercel.json
is pure gold here. Setup your project with configuration like this and voila. That's all.
{
"functions": {
"api/*.php": {
"runtime": "vercel-php@0.4.0"
}
}
}
Last thing you have to do is call vercel
. If you are more interested take a look at features and usage.
# Install it globally
npm i -g vercel
# Log in
vercel login
# Let's fly
vercel
Are you ready to deploy your first PHP project to Vercel? Click & Go!
List of all installable extensions is on this page https://blog.remirepo.net/pages/PECL-extensions-RPM-status.
Before you can start using this runtime, you should learn about Vercel and how runtimes works. Take a look at blogpost about Serverless Functions
.
You should define functions
property in vercel.json
and list PHP files directly or using wildcard (*).If you need to route everything to index, use routes
property.
{
"functions": {
"api/*.php": {
"runtime": "vercel-php@0.4.0"
}
},
"routes": [
{ "src": "/(.*)", "dest": "/api/index.php" }
]
}
Do you have more questions (
vercel dev
For running vercel dev
properly, you need to have PHP installed on your computer, learn more.But it's PHP and as you know PHP has built-in development server. It works out of box.
php -S localhost:8000 api/index.php
Browse more examples.
Next
Done
vercel dev
Help wanted
project
├── api
│ ├── index.php
│ ├── users.php
│ └── books.php
└── vercel.json
{
"functions": {
"api/*.php": {
"runtime": "vercel-php@0.4.0"
},
// Can be list also directly
"api/index.php": {
"runtime": "vercel-php@0.4.0"
},
"api/users.php": {
"runtime": "vercel-php@0.4.0"
},
"api/books.php": {
"runtime": "vercel-php@0.4.0"
}
}
}
{
"functions": {
"api/index.php": {
"runtime": "vercel-php@0.4.0"
}
},
"routes": [
{ "src": "/(.*)", "dest": "/api/index.php" }
]
}
Additional function properties are memory
, maxDuration
. Learn more about functions.
{
"functions": {
"api/*.php": {
"runtime": "vercel-php@0.4.0",
"memory": 3008,
"maxDuration": 60
}
}
}
Yes, Composer is fully supported.
project
├── api
│ └── index.php
├── composer.json
└── vercel.json
{
"functions": {
"api/*.php": {
"runtime": "vercel-php@0.4.0"
}
}
}
{
"require": {
"php": "^7.4",
"tracy/tracy": "^2.0"
}
}
It's also good thing to create .vercelignore
file and put /vendor
folder to this file. It will not upload/vendor
folder to Vercel platform.
Yes, you can override php configuration. Take a look at default configuration at first.Create a new file api/php.ini
and place there your configuration. Don't worry, this particulary file will beremoved during building phase on Vercel.
project
├── api
│ ├── index.php
│ └── php.ini
└── vercel.json
{
"functions": {
"api/*.php": {
"runtime": "vercel-php@0.4.0"
}
}
}
# Disable some functions
disable_functions = "exec, system"
# Update memory limit
memory_limit=1024M
Runtimes support excluding some files or folders, take a look at doc.
{
"functions": {
"api/**/*.php": {
"runtime": "vercel-php@0.4.0",
"excludeFiles": "{foo/**,bar/config/*.yaml}",
}
}
If you want to exclude files before uploading them to Vercel, use .vercelignore
file.
Calling composer scripts during build phase on Vercel is supported via script named vercel
. You can easilly call php, npm or node.
{
"require": { ... },
"require-dev": { ... },
"scripts": {
"vercel": [
"@php -v",
"npm -v"
]
}
}
Files created during composer run vercel
script can be used (require/include) in your PHP lambdas, but can't be accessed from browser (like assets). If you still want to access them, create fake assets.php
lambda and require them. Example of PHP satis.
If you are looking for config.includeFiles
in runtime, unfortunately you can't include extra files.All files in root folder are uploaded to Vercel, use .vercelignore
to exclude them before upload.
I think the best way at this moment is use PHP Development Server.
php -S localhost:8000 api/index.php
Show me CHANGELOG
git clone git@github.com:juicyfx/vercel-php.git
make install
make build
make test
Vercel Develop. Preview. Ship. Usage Vercel is a platform for static sites and frontend frameworks, built to integrate with your headless content, commerce, or database. We provide a frictionless deve
我试图在Vercel上部署我的NextJS应用程序,但构建总是失败,错误为,即使NextJS应用程序已成功构建。我已经联系了Vercel支持部门,但他们只能在我公开我的存储库时帮助我,不幸的是,这不是一个选项。我已经向他们提供了整个项目的ZIP文件,但他们没有接受。 我在这里发布这篇文章,希望有人知道是什么导致了这个错误。任何想法都非常感谢。 编辑:这里有一个重现错误的回购:https://git
我开始使用nextjs和Vercel部署构建一个API。安装非常简单,只需在下创建文件即可。例如,创建endpoint,,我有: 这很好,但我希望API的版本如下:,,等等。 如果我能基于git提交标签创建一个新版本就更好了。也就是说,当我合并到分支时,Vercel要么部署到当前的生产环境(例如v1 env),要么如果有新的git标记,它部署到新的生产环境(例如v2 env)。部署后,两个生产环境
在部署到vercel后,我的一个页面上出现了这个错误,在开发模式下一切正常。 我认为问题可能是我的fetch/API之一,因为它使用第一个fetch请求中的数据作为第二个fetch请求的URL。。。 我的所有其他页面都有不同的API/获取请求,可以正常工作。。。
我有一个没有集成api的NextJS应用程序,我想部署到Vercel。当我在本地运行它时,它工作得很好。,而且我也可以在没有任何错误的情况下构建它。。然而,当我在Vercel部署它时,我收到一个。 以下是我的文件夹结构: 我正在使用NextJs 10.0.3。 以下是已部署应用的链接。 我没有nextjs配置文件。我的假设是,错误是由动态路径引起的,但我找不到我的错误。此外,部署应用程序时没有页面
来自Ruby on Rails,我发现在NextJS上很难理解环境变量的概念,特别是在Vercell平台上。我遵循了NextJS留档,它建议Vercell留档在项目设置中设置环境变量,即使是开发环境。所以我做了,并用vercel env拉他们。env.local。但是当我运行开发服务器时,process.env变量总是未定义的。到目前为止,我发现了很多关于这方面的问题,但运气不佳。 我使用的示例代