Documentation Index
Fetch the complete documentation index at: https://docs.turso.tech/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
Before you start, make sure you:
Download the latest build extension/driver binary you can see at Release page. It's available for:
Turso PHP Installer (Linux/macOS only)
Get the installer:curl --proto '=https' --tlsv1.2 -sSf "https://darkterminal.github.io/turso-php-installer/dist/turso-php-installer.phar"
./turso-php-installer.phar
Add as a global executable script:sudo mv turso-php-installer.phar /usr/local/bin/turso-php-installer
UsageInstall Turso Client PHP / libSQL Extension:turso-php-installer install
Check on your console/terminal$ php --m | grep libsql
liblibsql_php
Update Turso Client PHP / libSQL Extension:turso-php-installer update
Uninstall Turso Client PHP / libSQL Extension:turso-php-installer uninstall
- 📦 Extract the archive
- 🗃 Locate somewhere in your machine
- 💽 Copy a relative path that address that extension/driver
- 📂 Open
php.ini search ;extension if you using nano (ctrl+w) then searching for it
- 📝 add in the next-line
extension=liblibsql_php.so (in Linux) without ; at the begining
Check on your console/terminal$ php --m | grep libsql
liblibsql_php
Now, LibSQL class is available in your PHP environment! You can use it everywhere in your PHP project 🎉
Configure database credentials
Get the database URL:turso db show --url <database-name>
Get the database authentication token:turso db tokens create <database-name>
Assign credentials to the environment variables inside .env.TURSO_DATABASE_URL=
TURSO_AUTH_TOKEN=
Save this later when you need to connect to Remote and Embedded Replica
Create PHP Project
Create new directory:mkdir your-awesome-php-project
cd your-awesome-php-project
Install Turso Doctrine DBAL
composer require tursodatabase/turso-doctrine-dbal
Configure database connection
Setup the environment variable in your Laravel application, choose what the type connection you need.$params = [
"url" => ":memory:",
'driverClass' => \Turso\Doctrine\DBAL\Driver::class,
];
Other environment variables (Embedded Replica Only)Show Other environment variables (Embedded Replica Only)
Integer value representing synchronization interval in seconds (optional, default: 5).
Boolean value indicating whether to read your writes (optional, default: true).
String value for encryption purposes (optional, default: empty).
Project Structure Example
src/
├── helpers.php
└── Todo.php
vendor/
composer.json
composer.lock
todo # todo executable
Here you simple php todo cli + Doctrine BDAL#!/usr/bin/env php
<?php
use Turso\Todo\CLI\Todo;
require_once __DIR__ . '/vendor/autoload.php';
$header = 'TODO CLI + TURSO';
echo $header . PHP_EOL;
function main()
{
echo str_repeat('-', WIDTH - 18) . " Todo CLI - " . VERSION . PHP_EOL;
while (true) {
echo "[L] List | [A] Add | [E] Edit | [D] Delete | [X] Exit" . PHP_EOL;
echo "command: ";
$choice = trim(fgets(STDIN));
$app = new Todo();
switch (strtolower($choice)) {
case 'l':
$app->listTodos();
break;
case 'a':
$app->addTodo();
clearScreen();
break;
case 'e':
$app->editTodo();
clearScreen();
break;
case 'd':
$app->deleteTodo();
clearScreen();
break;
case 'x':
exit("Goodbye!" . PHP_EOL);
default:
echo "Invalid choice." . PHP_EOL;
clearScreen();
}
}
echo PHP_EOL;
}
main();
Your PHP Application Ready!
Examples
PHP Todo CLI + Doctrine DBAL
See the full source code
Symfony Rest API CRUD
See the full source code