Skip to content

Commit

Permalink
Refactoring: now-php -> vercel-php
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Jun 22, 2020
1 parent e926480 commit 797fe5d
Show file tree
Hide file tree
Showing 24 changed files with 279 additions and 166 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
/node_modules
/packages/**/package-lock.json

# ZEIT
.now
# Vercel
.vercel
158 changes: 103 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<h1 align=center>ZEIT Now PHP</h1>
<h1 align=center>PHP Runtime for <a href="https://vercel.com">Vercel</h1>

<p align=center>
Enjoyable & powerful 🐘 PHP Runtime (<a href="https://php.now.sh">php.now.sh</a>) for ZEIT Now.
Enjoyable & powerful 🐘 PHP Runtime (<a href="https://php.vercel.app">php.vercel.app</a>) for Vercel platform.
<a href="https://vercel.com/new/project?template=https://github.com/juicyfx/vercel-examples/tree/master/php"><img src="https://vercel.com/button"></a>
</p>

<p align=center>
🕹 <a href="https://f3l1x.io">f3l1x.io</a> | 💻 <a href="https://github.com/f3l1x">f3l1x</a> | 🐦 <a href="https://twitter.com/xf3l1x">@xf3l1x</a>
</p>

<p align=center>
<a href="https://www.npmjs.com/package/now-php"><img alt="npm" src="https://img.shields.io/npm/dt/now-php?style=flat-square"></a>
<a href="https://www.npmjs.com/package/now-php"><img alt="npm (latest)" src="https://img.shields.io/npm/v/now-php/latest?style=flat-square"></a>
<a href="https://www.npmjs.com/package/vercel-php"><img src="https://badgen.net/npm/v/vercel-php"></a>
<a href="https://www.npmjs.com/package/vercel-php"><img src="https://badgen.net/npm/dt/vercel-php"></a>
<a href="https://www.npmjs.com/package/vercel-php"><img src="https://badgen.net/github/status/juicyfx/vercel-php/master"></a>
</p>

<p align=center>
Expand All @@ -21,24 +19,63 @@ Enjoyable & powerful 🐘 PHP Runtime (<a href="https://php.now.sh">php.now.sh</
<a href="https://github.com/phalcon"><img src="https://github.com/phalcon.png" width="128"></a>
</p>

<p align=center><strong>🏋️‍♀️ It works with these frameworks and tools. Discover more at <a href="https://github.com/juicyfx/now-examples">examples</strong>.</p>
<p align=center><strong>🏋️‍♀️ It works with these frameworks and tools. Discover more at <a href="https://github.com/juicyfx/vercel-examples">examples</strong>.</p>

-----

<p align=center>
Made with ❤️ by <a href="https://github.com/f3l1x">@f3l1x</a> 🕹 <a href="https://f3l1x.io">f3l1x.io</a> 🐦 <a href="https://twitter.com/xf3l1x">@xf3l1x</a>
</p>

-----

## 🐣 Versions
Let's picture you want to deploy your awesome microproject written in PHP and you don't know where. You have found [Vercel](https://vercel.com) 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.

```sh
project
├── api
│ └── index.php
└── now.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
<?php
phpinfo();
```

Second file `now.json` is pure gold here. Setup your project with configuration like this and voila. That's all.

```json
{
"functions": {
"api/*.php": {
"runtime": "[email protected]"
}
}
}
```

Last thing you have to do is call `now`. If you are more interested take a look at features and usage.

| | Pkg | Tag | Stability | Info |
|----|---------|--------------|-------------|--------------------------|
|| now-php | latest | production | Rock-solid stable. |
| 🔥 | now-php | canary | testing | For early-adopters. |
| ⚠️ | now-php | experimental | development | Testing and high danger. |
```
# Install it globally
npm i -g now
> Need to know how things are changing? Here is [changelog](./CHANGELOG.md).
# Log in
now login
# Let's fly
now
```

## 🤗 Features

- **Architecture**: PHP development server (🚀 fast enough)
- **PHP version**: 7.4.4
- **PHP version**: 7.4.7
- **Extensions**: apcu, bcmath, brotli, bz2, calendar, Core, ctype, curl, date, dom, ds, exif, fileinfo, filter, ftp, gettext, hash, iconv, igbinary, imap, intl, json, libxml, lua, mbstring, msgpack, mysqli, mysqlnd, openssl, pcntl, pcre, PDO, pdo_mysql, pdo_pgsql, pdo_sqlite, pgsql, phalcon, Phar, protobuf, psr, readline, redis, Reflection, runkit7, session, SimpleXML, soap, sockets, sodium, SPL, sqlite3, standard, swoole, timecop, tokenizer, uuid, xml, xmlreader, xmlrpc, xmlwriter, xsl, Zend OPcache, zlib
- **Speed**: cold ~250ms / warm ~5ms
- **Memory**: ~90mb
Expand All @@ -48,15 +85,24 @@ Enjoyable & powerful 🐘 PHP Runtime (<a href="https://php.now.sh">php.now.sh</
## ⚙️ Usage

Take a look at [ZEIT's](https://zeit.co) blogpost about [`Serverless Functions`](https://zeit.co/blog/customizing-serverless-functions).
Take a look at [Vercel's](https://vercel.com) blogpost about [`Serverless Functions`](https://vercel.com/blog/customizing-serverless-functions).

You should define `functions` property in `now.json` and list PHP files directly or using wildcard (*).

```json
{
"functions": {
"api/*.php": {
"runtime": "[email protected]"
"runtime": "[email protected]"
},

// Can be list directly also

"api/one.php": {
"runtime": "[email protected]"
},
"api/two.php": {
"runtime": "[email protected]"
}
}
}
Expand All @@ -68,7 +114,7 @@ If you need to show index page define `routes` properly.
{
"functions": {
"api/index.php": {
"runtime": "now-php@0.0.10"
"runtime": "vercel-php@0.1.0"
}
},
"routes": [
Expand All @@ -77,50 +123,51 @@ If you need to show index page define `routes` properly.
}
```

Additional function properties are `memory`, `maxDuration`.
Additional function properties are `memory`, `maxDuration`. Learn more about [functions](https://vercel.com/docs/configuration#project/functions).

```json
{
"functions": {
"api/*.php": {
"runtime": "now-php@0.0.10",
"runtime": "vercel-php@0.1.0",
"memory": 3008,
"maxDuration": 500
}
}
}
```

**Click & Go**

[![Deploy with ZEIT Now](https://zeit.co/button)](https://zeit.co/new/project?template=https://github.com/juicyfx/now-examples/tree/master/php)

## 👨‍💻`now dev`

For running `now dev` properly, you need to have PHP installed on your computer, [learn more](errors/now-dev-no-local-php.md).
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

- official - https://php.now.sh/
- phpinfo - https://php.jfx.cz/
- extensions - https://php.jfx.cz/ext/
- ini - https://php.jfx.cz/ini/
- JSON API - https://php.jfx.cz/api/users.php
- test - https://php.jfx.cz/test.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

![](docs/phpinfo.png)

## 🎯Examples

- [PHP - fast & simple](https://github.com/juicyfx/now-examples/tree/master/php/)
- [Composer - install dependencies](https://github.com/juicyfx/now-examples/tree/master/php-composer/)
- [Framework - Lumen](https://github.com/juicyfx/now-examples/tree/master/php-framework-lumen/)
- [Framework - Nette](https://github.com/juicyfx/now-examples/tree/master/php-framework-nette/)
- [Framework - Slim](https://github.com/juicyfx/now-examples/tree/master/php-framework-slim/)
- [Framework - Symfony - Microservice](https://github.com/juicyfx/now-examples/tree/master/php-framework-symfony-microservice/)
- [Framework - Phalcon](https://github.com/juicyfx/now-examples/tree/master/php-framework-phalcon/)
- [PHP - fast & simple](https://github.com/juicyfx/vercel-examples/tree/master/php/)
- [Composer - install dependencies](https://github.com/juicyfx/vercel-examples/tree/master/php-composer/)
- [Framework - Lumen](https://github.com/juicyfx/vercel-examples/tree/master/php-framework-lumen/)
- [Framework - Nette](https://github.com/juicyfx/vercel-examples/tree/master/php-framework-nette/)
- [Framework - Slim](https://github.com/juicyfx/vercel-examples/tree/master/php-framework-slim/)
- [Framework - Symfony - Microservice](https://github.com/juicyfx/vercel-examples/tree/master/php-framework-symfony-microservice/)
- [Framework - Phalcon](https://github.com/juicyfx/vercel-examples/tree/master/php-framework-phalcon/)

Browse [more examples](https://github.com/juicyfx/now-examples). 👀
Browse [more examples](https://github.com/juicyfx/vercel-examples). 👀

## 📜 Resources

Expand All @@ -133,25 +180,26 @@ Browse [more examples](https://github.com/juicyfx/now-examples). 👀

## 🚧 Roadmap

- next-gen PHP runtime ✅
**WIP**

- customize php.ini
- composer.json scripts

**Done**

- next-gen PHP runtime
- Composer
- config.composer: true ✅
- composer.json detection ✅
- zero config ✅
- `now dev`
- rewrite to typescript ✅
- setup CI ✅
- configure php.ini 🚧
- using `builds.config`
- using `build.env` 🚧
- PHP versions
- 7.4 ✅ (used)
- 7.3 ✅
- 7.2 ✅
- config.composer: true
- composer.json detection
- zero config
- `now dev`
- typescript codebase
- github workflows (CI)
- PHP 7.4

**Help wanted**

- create many examples (majority frameworks and other use-cases)
- create examples using vercel-php

## 👨🏻‍💻CHANGELOG

Expand Down
24 changes: 16 additions & 8 deletions errors/now-dev-no-local-php.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# It looks like you don't have PHP on your machine.

#### Why This Error Occurred
**Why This Error Occurred**

You ran `now dev` on a machine where PHP is not installed.
For the time being, this runtime requires a local PHP installation to run the runtime locally.

#### Possible Ways to Fix It
**Possible Ways to Fix It**

##### Install PHP to your computer
1. Install PHP to your computer

**OSX**

```
brew install php@7.3
brew install php@7.4
```

**Ubuntu**
Expand All @@ -21,7 +22,7 @@ apt-get -y install apt-transport-https lsb-release ca-certificates
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
apt-get update
apt-get install php7.3-cli php7.3-cgi php7.3-json php7.3-curl php7.3-mbstring
apt-get install php7.4-cli php7.4-cgi php7.4-json php7.4-curl php7.4-mbstring
```

**Fedora**
Expand All @@ -30,10 +31,17 @@ apt-get install php7.3-cli php7.3-cgi php7.3-json php7.3-curl php7.3-mbstring
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install yum-utils
yum-config-manager --enable remi-php73
yum-config-manager --enable remi-php74
yum update
yum install php73-cli php73-cgi php73-json php73-curl php73-mbstring
yum install php74-cli php74-cgi php74-json php74-curl php74-mbstring
```

##### Check that php is in the path
2. Start PHP built-in Development Server

```sh
php -S localhost:8000 api/index.php
```

**Check that php is in the path**

If you do have installed PHP but still get this error, check that PHP executable is added to the PATH environment variable.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "now-php-monorepo",
"name": "vercel-php-monorepo",
"scripts": {
"test-unit": "jest --config unit.jest.config.js"
},
Expand Down
10 changes: 5 additions & 5 deletions packages/php/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# now-php
# vercel-php

1. Create `api/index.php`.

Expand All @@ -7,18 +7,18 @@
phpinfo();
```

1. Create `now.json`
2. Create `now.json`

```json
{
"functions": {
"api/index.php": {
"runtime": "now-php@0.0.9"
"runtime": "vercel-php@0.1.0"
}
}
}
```

3. Call `now` and see magic.
3. Call `vercel`, `vc` or `now` and see magic.

4. Discover more in documentation at [Github repository](https://github.com/juicyfx/now-php).
4. Discover more in documentation at [Github repository](https://github.com/juicyfx/vercel-php).
26 changes: 13 additions & 13 deletions packages/php/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"name": "now-php",
"description": "PHP ZEIT Now Runtime",
"version": "0.0.10",
"name": "vercel-php",
"description": "Vercel PHP runtime",
"version": "0.1.0",
"license": "MIT",
"main": "./dist/index.js",
"homepage": "https://github.com/juicyfx/now-php",
"homepage": "https://github.com/juicyfx/vercel-php",
"repository": {
"type": "git",
"url": "https://github.com/juicyfx/now-php.git"
"url": "https://github.com/juicyfx/vercel-php.git"
},
"keywords": [
"vercel",
"zeit",
"now",
"php",
Expand All @@ -24,17 +25,16 @@
"prepublishOnly": "tsc"
},
"files": [
"dist",
"lib"
"dist"
],
"dependencies": {
"@now-php/lib-74": "latest"
"@libphp/amazon-linux-2-v74": "^0.0.6"
},
"devDependencies": {
"@now/build-utils": "^0.9.4",
"@types/glob": "^7.1.1",
"@types/node": "^10.0.0",
"jest": "^24.8.0",
"typescript": "^3.5.3"
"@vercel/build-utils": "^2.4.0",
"@types/glob": "^7.1.2",
"@types/node": "^12.12.47",
"jest": "^26.0.1",
"typescript": "^3.9.5"
}
}
Loading

0 comments on commit 797fe5d

Please sign in to comment.