A minimal, framework-free PHP REST API you can drop on any server and run. It gives you JWT login, refresh tokens, rate limiting, and CORS out of the box — no Composer, no Laravel, no Symfony. Just PHP 7.4+ and MySQL.

Download

Download from MEGA (PHP script + schema + config example)

What It Does

  • JWT authentication — Login with username/password and get an access token plus a refresh token. Use the access token in the Authorization header to call protected routes. When it expires, swap the refresh token for a new pair.
  • Rate limiting — Per-IP limits so one client can't hammer your API; login and refresh use a stricter limit to slow down brute force.
  • CORS — Headers are set so browsers can call the API from another origin (e.g. your frontend on a different domain).
  • JSON only — All requests and responses are JSON. Database access uses PDO with prepared statements to avoid SQL injection.

Included endpoints:

EndpointWhat it does
GET /API info and a short list of routes
POST /auth/loginLog in with username and password → returns tokens
POST /auth/refreshSend refresh_token → returns new access and refresh tokens
GET /api/meReturns the current user (requires Bearer token)
GET /api/usersReturns all users (requires Bearer token)

Use it as a starting point for a mobile app backend, a SPA, or a small internal API. Add your own routes in index.php by following the same pattern.

How to Install

1. Get the files
Download or clone the script so you have a folder with index.php, config.example.php, schema.sql, and the rest.

2. Create your config

cp config.example.php config.php

Open config.php and set:

  • Database — dsn, username, and password for your MySQL/MariaDB.
  • JWT secret — A long random string (at least 32 characters). This signs the tokens; keep it secret.

3. Create the database and table

mysql -u root -p -e "CREATE DATABASE IF NOT EXISTS rest_api;"
mysql -u root -p rest_api < schema.sql

This creates the users table and a default user.

4. Run it
From the script folder:

php -S 0.0.0.0:8080 -t .

Then open http://localhost:8080/ in a browser or call the API with curl.

Default login (from schema.sql): username admin, password password. Change it after first login.

Quick Test

# Login and get a token
curl -s -X POST http://localhost:8080/auth/login \
  -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"password"}'

# Call a protected route (replace YOUR_ACCESS_TOKEN with the token from the response)
curl -s http://localhost:8080/api/me \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Requirements

  • PHP 7.4+ (with PDO MySQL)
  • MySQL or MariaDB

No Composer or extra PHP packages. JWT is implemented in plain PHP.

Security Reminders

  • Don't commit config.php (it's in .gitignore by default).
  • Use HTTPS in production.
  • Set a strong, random JWT secret.
  • Change the default admin password and add real users as needed.

For more detail and options, see README.md in the same folder.