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.
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.
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.
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.
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.
8. How to include some files of folders?
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.
vercel-community/php
PHP Runtime for Vercel
Enjoyable & powerful🐘 PHP Runtime (php.vercel.app) for Vercel platform.
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.
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.Last thing you have to do is call
vercel
. If you are more interested take a look at features and usage.Are you ready to deploy your first PHP project to Vercel? Click & Go!
[email protected]
- PHP 8.1.x[email protected]
- PHP 8.0.x[email protected]
- PHP 7.4.xBefore 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 invercel.json
and list PHP files directly or using wildcard (*). If you need to route everything to index, useroutes
property.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.Browse more examples.👀
See roadmap issue. Help wanted.
1. How to use more then one endpoint (index.php)?
2. How to route everything to index?
3. How to update memory limit?
Additional function properties are
memory
,maxDuration
. Learn more about functions.4. How to use it with Composer?
Yes, Composer is fully supported.
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.5. How to override php.ini / php configuration ?
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.6. How to exclude some files or folders ?
Runtimes support excluding some files or folders, take a look at doc.
If you want to exclude files before uploading them to Vercel, use
.vercelignore
file.7. How to call composer script(s) ?
Calling composer scripts during build phase on Vercel is supported via script named
vercel
. You can easilly call php, npm or node.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 fakeassets.php
lambda and require them. Example of PHP satis.8. How to include some files of folders?
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.9. How to develop locally?
I think the best way at this moment is use PHP Development Server.
👨🏻💻CHANGELOG
Show me CHANGELOG
git clone [email protected]:juicyfx/vercel-php.git
make install
make build
make test
Copyright © 2019 f3l1x. This project is MIT licensed.