loading...
NetrixOne

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.

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

File index.html contains static frontend.

<html>
<head></head>
<body>

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

</body>
</html>

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

<?php

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.

Posted on Jul 7 '19 by:

f3l1x profile

Milan Felix Šulc

@f3l1x

Developer Advocate @ OpenSource 🎇 PHP / JS+TS / Java / Go / Rust engineer. ✌️ @nettefw evangelist. 💻

NetrixOne

NetrixOne is a group of independent IT professionals spanning multiple areas of expertise. We focus on software development that is tailored to fit even the most complex and sometimes very niche demands of our customers.

Discussion

markdown guide