PHP Runtime for ▲ Vercel Serverless Functions (support 7.4-8.3)
Enjoyable & powerful 🐘 PHP Runtime (php.vercel.app) for Vercel platform.
🏋️♀️ It works with these frameworks and tools. Discover more at examples.
Made with ❤️ by @f3l1x (f3l1x.io) • 🐦 @xf3l1x
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.jsonFirst 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.7.4"
}
}
}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!
- Architecture: PHP development server (🚀 fast enough)
- PHP version: 8.3 (https://example-php-8-3.vercel.app)
- Extensions: apcu, bcmath, brotli, bz2, calendar, Core, ctype, curl, date, dom, ds, exif, fileinfo, filter, ftp, geoip, gettext, hash, iconv, igbinary, imap, intl, json, libxml, lua, mbstring, mongodb, msgpack, mysqli, mysqlnd, openssl, pcntl, pcre, PDO, pdo_mysql, pdo_pgsql, pdo_sqlite, pgsql, phalcon, Phar, protobuf, readline, redis, Reflection, runkit7, session, SimpleXML, soap, sockets, sodium, SPL, sqlite3, standard, swoole, timecop, tokenizer, uuid, xml, xmlreader, xmlrpc, xmlwriter, xsl, Zend OPcache, zlib, zip
- Speed: cold ~250ms / warm ~5ms
- Memory: ~90mb
- Frameworks: Nette, Symfony, Lumen, Slim, Phalcon
- Node.js: 22.x
List of all installable extensions is on this page https://blog.remirepo.net/pages/PECL-extensions-RPM-status.
vercel-php@0.7.4- Node autodetect / PHP 8.3.x (https://example-php-8-3.vercel.app)vercel-php@0.6.2- Node autodetect / PHP 8.2.x (https://example-php-8-2.vercel.app)vercel-php@0.5.5- Node autodetect / PHP 8.1.x (https://example-php-8-1.vercel.app)vercel-php@0.4.5- Node autodetect / PHP 8.0.x (https://example-php-8-0.vercel.app)vercel-php@0.3.6- Node autodetect / PHP 7.4.x (https://example-php-7-4.vercel.app)
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.7.4"
}
},
"routes": [
{ "src": "/(.*)", "dest": "/api/index.php" }
]
}Do you have more questions (❓)? Let's move to FAQ.
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
- official - https://php.vercel.app/
- phpinfo - https://phpshow.vercel.app/
- extensions - https://phpshow.vercel.app/ext/
- ini - https://phpshow.vercel.app/ini/
- JSON API - https://phpshow.vercel.app/api/users.php
- test - https://phpshow.vercel.app/test.php
- PHP - fast & simple
- Composer - install dependencies
- Framework - Laravel
- Framework - Lumen
- Framework - Nette
- Framework - Phalcon
- Framework - Slim
- Framework - Symfony - Microservice
Browse more examples. 👀
- 2019/10/23 - Code Examples
- 2019/10/19 - ZEIT - Deploy Serverless Microservices Right Now
- 2019/08/23 - Code Examples
- 2019/07/07 - Bleeding Edge PHP on ZEIT Now
- 2019/06/06 - Code Examples
- 2019/06/05 - ZEIT - Deploy Serverless Microservices Right Now (VIDEO)
See roadmap issue. Help wanted.
project
├── api
│ ├── index.php
│ ├── users.php
│ └── books.php
└── vercel.json{
"functions": {
"api/*.php": {
"runtime": "vercel-php@0.7.4"
},
// Can be list also directly
"api/index.php": {
"runtime": "vercel-php@0.7.4"
},
"api/users.php": {
"runtime": "vercel-php@0.7.4"
},
"api/books.php": {
"runtime": "vercel-php@0.7.4"
}
}
}
project
├── api
│ ├── index.php
│ ├── users.php
│ └── books.php
└── vercel.json{
"functions": {
"api/*.php": {
"runtime": "vercel-php@0.7.4"
},
// Can be list also directly
"api/index.php": {
"runtime": "vercel-php@0.7.4"
},
"api/users.php": {
"runtime": "vercel-php@0.7.4"
},
"api/books.php": {
"runtime": "vercel-php@0.7.4"
}
}
}
1. How to use more then one endpoint (index.php)?
project
├── api
│ ├── index.php
│ ├── users.php
│ └── books.php
└── vercel.json{
"functions": {
"api/*.php": {
"runtime": "vercel-php@0.7.4"
},
// Can be list also directly
"api/index.php": {
"runtime": "vercel-php@0.7.4"
},
"api/users.php": {
"runtime": "vercel-php@0.7.4"
},
"api/books.php": {
"runtime": "vercel-php@0.7.4"
}
}
}
2. How to route everything to index?
{
"functions": {
"api/index.php": {
"runtime": "vercel-php@0.7.4"
}
},
"routes": [
{ "src": "/(.*)", "dest": "/api/index.php" }
]
}2. How to route everything to index?
{
"functions": {
"api/index.php": {
"runtime": "vercel-php@0.7.4"
}
},
"routes": [
{ "src": "/(.*)", "dest": "/api/index.php" }
]
}3. How to update memory limit?
Additional function properties are memory, maxDuration. Learn more about functions.
{
"functions": {
"api/*.php": {
"runtime": "vercel-php@0.7.4",
"memory": 3008,
"maxDuration": 60
}
}
}3. How to update memory limit?
Additional function properties are memory, maxDuration. Learn more about functions.
{
"functions": {
"api/*.php": {
"runtime": "vercel-php@0.7.4",
"memory": 3008,
"maxDuration": 60
}
}
}4. How to use it with Composer?
Yes, Composer is fully supported.
project
├── api
│ └── index.php
├── composer.json
└── vercel.json{
"functions": {
"api/*.php": {
"runtime": "vercel-php@0.7.4"
}
}
}{
"require": {
"php": "^8.1",
"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, Composer is fully supported.
project
├── api
│ └── index.php
├── composer.json
└── vercel.json{
"functions": {
"api/*.php": {
"runtime": "vercel-php@0.7.4"
}
}
}{
"require": {
"php": "^8.1",
"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, Composer is fully supported.
project
├── api
│ └── index.php
├── composer.json
└── vercel.json{
"functions": {
"api/*.php": {
"runtime": "vercel-php@0.7.4"
}
}
}{
"require": {
"php": "^8.1",
"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.
4. How to use it with Composer?
Yes, Composer is fully supported.
project
├── api
│ └── index.php
├── composer.json
└── vercel.json{
"functions": {
"api/*.php": {
"runtime": "vercel-php@0.7.4"
}
}
}{
"require": {
"php": "^8.1",
"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.
6. How to exclude some files or folders ?
Runtimes support excluding some files or folders, take a look at doc.
{
"functions": {
"api/**/*.php": {
"runtime": "vercel-php@0.7.4",
"excludeFiles": "{foo/**,bar/config/*.yaml}",
}
}If you want to exclude files before uploading them to Vercel, use .vercelignore file.
6. How to exclude some files or folders ?
Runtimes support excluding some files or folders, take a look at doc.
{
"functions": {
"api/**/*.php": {
"runtime": "vercel-php@0.7.4",
"excludeFiles": "{foo/**,bar/config/*.yaml}",
}
}If you want to exclude files before uploading them to Vercel, use .vercelignore file.
10. What Node.js runtime is supported?
Show me CHANGELOG
- Clone this repository.
git clone git@github.com:juicyfx/vercel-php.git
- Install NPM dependencies
make install
- Make your changes
- Run TypeScript compiler
make build
- Run tests
make test
- Create a PR
from https://github.com/vercel-community/php





No comments:
Post a Comment