Simple PHP+DB calorie tracker
- PHP 100%
| .gitignore | ||
| api.php | ||
| example.png | ||
| index.php | ||
| LICENSE | ||
| README.md | ||
calories
Minimal self-hosted calorie tracker: a single-page PHP UI (index.php) with a tiny JSON API (api.php) backed by a local SQLite database.
What it does
- Add calorie entries for today (kcal + optional description)
- Delete entries (only works for today. You must edit the db directly to delete older entries)
- Configure daily goal and maintenance targets
- Show today’s total/remaining and a simple 30-day bar graph
Fasting
Empty days will be counted as the 'Maintenance' number so if you wish to have a fasting day you need to enter a 0-calorie item for that day.
Requirements
- PHP 8.x recommended, did work on PHP 7.4 previously
- PHP extension:
pdo_sqlite(PDO + SQLite) - A writable directory for the SQLite file (
calories.dbis created automatically)
Project layout
index.php: main UI entrypoint (renders HTML/CSS/JS)api.php: JSON API endpoint for add/delete/update actionscalories.db: SQLite database file (local/runtime data; not committed)
Install
No dependencies to install, just deploy the PHP files.
How to run
Serve this directory with your web server
- Point your web root at this directory (or otherwise ensure
index.phpis reachable). - Ensure PHP has
pdo_sqliteenabled. - Ensure the directory is writable by the PHP user so SQLite can create/write
calories.db.
Configuration
- Database path: hardcoded as
calories.dbin bothindex.phpandapi.php. - Daily goal / maintenance: stored in the
configtable; editable in the UI.
