Détail du package

vercel-php

juicyfx10.7kMIT0.7.3

Vercel PHP runtime

vercel, zeit, now, php

readme

PHP Runtime for Vercel

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


😎 Getting Started

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.7.3"
    }
  }
}

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!

🤗 Features

  • 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

List of all installable extensions is on this page https://blog.remirepo.net/pages/PECL-extensions-RPM-status.

💯 Versions

⚙️ Usage

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.3"
    }
  },
  "routes": [
    { "src": "/(.*)",  "dest": "/api/index.php" }
  ]
}

Do you have more questions (❓)? Let's move to FAQ.

👨‍💻 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

👀 Demo

PHP

🎯Examples

Browse more examples. 👀

📜 Resources

🚧 Roadmap

See roadmap issue. Help wanted.

⁉️ FAQ

<summary>1. How to use more then one endpoint (index.php)?</summary> sh project ├── api │ ├── index.php │ ├── users.php │ └── books.php └── vercel.json { "functions": { "api/*.php": { "runtime": "vercel-php@0.7.3" }, // Can be list also directly "api/index.php": { "runtime": "vercel-php@0.7.3" }, "api/users.php": { "runtime": "vercel-php@0.7.3" }, "api/books.php": { "runtime": "vercel-php@0.7.3" } } }
<summary>2. How to route everything to index?</summary> json { "functions": { "api/index.php": { "runtime": "vercel-php@0.7.3" } }, "routes": [ { "src": "/(.*)", "dest": "/api/index.php" } ] }
<summary>3. How to update memory limit?</summary> Additional function properties are memory, maxDuration. Learn more about functions. json { "functions": { "api/*.php": { "runtime": "vercel-php@0.7.3", "memory": 3008, "maxDuration": 60 } } }
<summary>4. How to use it with Composer?</summary> Yes, Composer is fully supported. sh project ├── api │ └── index.php ├── composer.json └── vercel.json json { "functions": { "api/*.php": { "runtime": "vercel-php@0.7.3" } } } json { "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.
<summary>5. How to override php.ini / php configuration ?</summary> 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 be removed during building phase on Vercel. sh project ├── api │ ├── index.php │ └── php.ini └── vercel.json json { "functions": { "api/*.php": { "runtime": "vercel-php@0.7.3" } } } json # Disable some functions disable_functions = "exec, system" # Update memory limit memory_limit=1024M
<summary>6. How to exclude some files or folders ?</summary> Runtimes support excluding some files or folders, take a look at doc. json { "functions": { "api/**/*.php": { "runtime": "vercel-php@0.7.3", "excludeFiles": "{foo/**,bar/config/*.yaml}", } } If you want to exclude files before uploading them to Vercel, use .vercelignore file.
<summary>7. How to call composer script(s) ?</summary> Calling composer scripts during build phase on Vercel is supported via script named vercel. You can easilly call php, npm or node. json { "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.
<summary>8. How to include some files of folders?</summary> 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.
<summary>9. How to develop locally?</summary> I think the best way at this moment is use PHP Development Server. php -S localhost:8000 api/index.php

👨🏻‍💻CHANGELOG

Show me CHANGELOG

🧙Contribution

  1. Clone this repository.
    • git clone git@github.com:juicyfx/vercel-php.git
  2. Install NPM dependencies
    • make install
  3. Make your changes
  4. Run TypeScript compiler
    • make build
  5. Run tests
    • make test
  6. Create a PR

📝 License

Copyright © 2019 f3l1x. This project is MIT licensed.

changelog

Changelog

[0.7.2] - 2024-09-30

  • Upgrade PHP 8.3 runtime

[0.7.1] - 2024-04-16

  • Fix autodetect runtime

[0.6.2] - 2024-04-16

  • Fix autodetect runtime

[0.5.5] - 2024-04-16

  • Fix autodetect runtime

[0.4.4] - 2024-04-16

  • Fix autodetect runtime

[0.3.6] - 2024-04-16

  • Fix autodetect runtime

[0.7.0] - 2024-02-22

  • PHP 8.3
  • Use @libphp/amazon-linux-2-v83: latest

[0.6.1] - 2024-01-24

  • Update LD_LIBRARY_PATH

[0.5.4] - 2024-01-24

  • Update LD_LIBRARY_PATH

[0.4.3] - 2024-01-24

  • Update LD_LIBRARY_PATH

[0.3.5] - 2024-01-24

  • Update LD_LIBRARY_PATH

[0.6.0] - 2023-03-27

  • PHP 8.2
  • Use @libphp/amazon-linux-2-v82: latest

[0.5.3] - 2023-03-27

  • Bump minimum node version from 14.x to 18.x
  • Upgrade dependencies

[0.5.2] - 2022-08-10

  • Bump minimum node version from 12.x to 14.x

[0.5.1] - 2022-05-05

  • Ignore .vercel folder during deployment

[0.5.0] - 2022-04-09

  • PHP 8.1
    • Added extensions: geoip, zlib, zip
    • Removed extensions: psr
  • Use @libphp/amazon-linux-2-v81: latest

[0.4.0] - 2021-01-02

  • PHP 8.0
  • Use @libphp/amazon-linux-2-v80: latest

[0.3.2] - 2021-01-02

  • Typos
  • More hints in FAQ
  • Fix excludeFiles option
  • Install PHP extensions mongodb
  • Use @libphp/amazon-linux-2-v74: latest

[0.3.1] - 2020-07-04

  • Install PHP extensions redis, msgpack, igbinary
  • Use @libphp/amazon-linux-2-v74: latest

[0.3.0] - 2020-06-29

  • Allow to execute composer script called vercel

    {
      "scripts": {
        "vercel": [
          "@php -v",
          "npm -v"
        ]
      }
    }
  • Drop support of config['php.ini'] use api/php.ini file instead

  • Support excludeFiles (default ['node_modules/**', 'now.json', '.nowignore'])

    {
      "functions": {
      "api/**/*.php": {
        "runtime": "vercel-php@0.3.0",
        "excludeFiles": ["node_modules", "somedir", "foo/bar"],
      }
    }
  • Restructure test folder (merge fixtures + my examples)

[0.2.0] - 2020-06-26

  • Allow to override php.ini

    project
    ├── api
    │   ├── index.php
    │   └── php.ini
    └── now.json
  • Extensive update of docs

  • Introduce FAQ questions
  • Move caddy package to juicyfx/juicy
  • Simplify repository structure

[0.1.0] - 2020-06-20

  • Rename repository from now-php to vercel-php
  • Rename NPM package from now-php to vercel-php
  • Upgrade PHP to 7.4.7 and recompile PHP extensions
  • Improve readme
  • Separate PHP libs to solo repository juicyfx/libphp (bigger plans)
  • Use php.vercel.app domain for official showtime
  • Use phpshow.vercel.app domain for runtime showcase

[0.0.9] - 2020-03-28

  • Use PHP 7.4 for installing Composer dependencies
  • Upgrade PHP 7.4 and recompile PHP extensions

[0.0.9] - 2020-01-16

  • Use PHP 7.3 for installing Composer dependencies
  • Separate examples to solo repository
  • Extensions
    • Disabled ssh2
    • Added psr
    • Rebuild phalcon, swoole

[0.0.8] - 2020-01-07

  • Runtime v3
  • Upgrade to PHP 7.4.x
  • Node 8.x reached EOL on AWS
  • Used Amazon Linux 2
  • CGI launcher inherits process.env [#38]
  • Drop Circle CI
  • Rebuild all PHP libs

[0.0.7] - 2019-11-08

  • Rename builder to runtime
  • Runtime v3

Migration

{
  "version": 2,
  "builds": [
    {
      "src": "index.php",
      "use": "now-php"
    }
  ]
}

➡️

{
  "functions": {
    "api/*.php": {
      "runtime": "now-php@0.0.7"
    }
  },
  // Optionally provide routes
  "routes": [
    { "src": "/(.*)",  "dest": "/api/index.php" }
  ]
}

[0.0.6] - 2019-11-07

  • Change builds to functions

[0.0.5] - 2019-09-30

  • Added Lumen example
  • Bugfix deploying PHP files in folders under different names then index.php

[0.0.4] - 2019-09-30

  • Implement intermediate caching (vendor, composer.lock, yarn.locak, package-lock.json, node_modules)
  • Rewrite PHP built-in server document root

[0.0.3] - 2019-09-04

  • Bugfix passing query parameters and accessing $_GET

[0.0.2] - 2019-08-23

  • Bump now-php@latest

[0.0.1-canary.39] - 2019-08-23

  • Allow overriding php.ini
  • Bugfix resolving PHP bin
  • Bugfix deploying php files in subfolders

[0.0.2-canary.2] - 2019-08-16

  • Compile PHP 7.3.8

[0.0.1-canary.5] - 2019-08-16

  • First working copy of caddy server

[0.0.1-canary.30] - 2019-08-16

  • New exported method getPhpLibFiles
  • Repair tests

[0.0.1-canary.18] - 2019-08-02

  • Bump now-php@latest

[0.0.1-canary.18] - 2019-08-02

  • Working on change response from string to Buffer
  • Updated homepage

[0.0.1-canary.17] - 2019-08-02

  • Working on change response from string to Buffer

[0.0.1-canary.15] - 2019-08-02

  • CGI: REQUEST_URI contains only path, not host + path
  • CGI: QUERY_STRING contains string without leading ?

[0.0.1-canary.14] - 2019-07-29

  • Tests: more tests

[0.0.1-canary.13] - 2019-07-29

  • Tests: take tests from official old builder

[0.0.1-canary.12] - 2019-07-28

  • Rewritten to TypeScript

[0.0.1-canary.11] - 2019-07-28

  • Working on now-dev

[0.0.1-canary.8] - 2019-07-27

  • First working now-php builder

[0.0.1-canary.7] - 2019-07-27

  • Working on now with now-php

[0.0.1-canary.0] - 2019-07-27

  • History begins