Deploy Static Frontend + PHP Files Using ZEIT Now

f3l1x profile image Milan Felix Šulc Updated on ・1 min read

I am quite a fan of ZEIT company and even more of their tool called Now.

I consider myself mainly as PHP developer, but I also like JavaScript. In these days static site generators are raising and I am totally into it.

So how to take advantage of static frontend but with dynamic backend written in PHP?

Since November 2019 it's simple as possible with ZEIT Now.

👀 https://imgur.com/V7CcInl

Minimal project structure looks like this, you gonna need only 3 files.

├── api/
│   ├── index.php
├── now.json
└── index.html

File index.html contains static frontend.


# Fetch data from /api/index.php using Fetch API


File api/index.php contains dynamic data or expose API endpoint.


header('conten-type: application/json');
echo json_encode(['tech' => 'ZEIT Now']);

File now.json setup deployment.

  "functions": {
    "api/index.php": {
      "runtime": "now-php@0.0.7"

Finally you can call now command and see what happened.

View this example on Github.


Editor guide