Turso libSQL Installer
Tags: webdev, database, php, laravel
Published: 2024-06-22 20:10:03

Hello Punk! Yes I am, in this journal I want to share with you how to install [libSQL](turso.tech/libsql) in your PHP Environment without worry to configure `php.ini` file in your current PHP Version.

Install the libSQL extension for PHP it's like install a composer package:

```bash
composer require vendor/package
```

to install libSQL extension for PHP

```bash
turso-php-installer install
```

---

![Turso PHP Installer](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nifadv8ox1kkpo7yu211.png)

Anyway... I want you to know how the punk'in single file installer script work and setup it for you.

## `help` command

You already see in the image above. That's the `help` command does.

## `install` command

The `install` command will do some necessary checks before installing the libSQL Extension for PHP, what a questions will ask for? (checking in the background)

**Are You Using Windows?**

Even though [Turso Client PHP](https://github.com/tursodatabase/turso-client-php) has an extension built for Windows MSVC 2022. However, the installation process using this installer script will not work for Windows. WSL will work or you can use [Turso Docker PHP](https://github.com/darkterminal/turso-docker-php)!

If you're using Windows then you will get this message:

```bash
> turso-php-installer install # In Windows
Sorry, Turso PHP Installer is only support for Linux and MacOS.

You are using Windows, you can try our alternative using Dev Containers
visit: https://github.com/darkterminal/turso-docker-php

Thank you!
```

**Are You Using Laravel Herd?**

Dang yeah... the installer is not support yet for Laravel Herd. But I will support soon, and you can follow up this discussion on [Herd Community GitHub Disccussion](https://github.com/beyondcode/herd-community/discussions/804).

```bash
$ turso-php-installer install
You are using Laravel Herd
Sorry, Laravel Herd is not supported yet.
You can try our alternative using Dev Containers
visit: https://github.com/darkterminal/turso-docker-php

Thank you!
```

**Is Already Installed**

Sometimes I forgot when it's already installed.

```bash
$ turso-php-installer install
Turso Client PHP is already installed and configured!
```

**Which PHP Version?**

Turso Client PHP / libSQL Extension for PHP need minimal PHP 8.0 and later. You see it at [Turso Client PHP - Release page](https://github.com/tursodatabase/turso-client-php/releases)

If you have PHP below the minimum requirement, then it will failed

```bash
$ turso-php-installer install
Oops! Your PHP version environment does not meet the requirements.
Need a minimal PHP 8.0 installed on your environment.
```

**Check `php.ini`**

The installer script need to lookup

```bash
$ turso-php-installer install
You don't have PHP install globaly in your environment
Turso Client PHP lookup php.ini file and it's not found
```

**Check The Functions Requiered**

The installer script also need a `shell_exec` and `curl` function

```bash
$ turso-php-installer install
It looks like the 'shell_exec' and 'curl_version' functions are disabled in your PHP environment. These functions are essential for this script to work properly.
To enable them, follow these steps:
1. Open your 'php.ini' file. You can find the location of your 'php.ini' file by running the command 'php --ini' in your terminal or command prompt.
2. Search for 'disable_functions' directive. It might look something like this:
disable_functions = shell_exec, curl_version
3. Remove 'shell_exec' and 'curl_version' from this list. It should look like:
disable_functions =
4. Save the 'php.ini' file.
5. Restart your web server for the changes to take effect. If you are using Apache, you can restart it with:
sudo service apache2 restart
or for Nginx:
sudo service nginx restart
If you are using a web hosting service, you might need to contact your hosting provider to enable these functions for you.
For more information on 'shell_exec', visit: https://www.php.net/manual/en/function.shell-exec.php
For more information on 'curl_version', visit: https://www.php.net/manual/en/function.curl-version.php
Thank you!
```

**Asking Permission**

The installer need to run with **sudo** role, because the installer will need to write `php.ini` file in your environment.

```bash
$ turso-php-installer install
Turso need to install the client extension in your PHP environment.
This script will ask your sudo password to modify your php.ini file:
Are you ok? [y/N]: 
```

**Download and Extract**

After all requirements is meet, then installer will download and extract the libSQL Extension for PHP based on Current PHP version that used in your environment and store it at `$HOME/.turso-client-php`

---

The extension is required before you used [Turso Driver Laravel](https://github.com/tursodatabase/turso-driver-laravel) and [Turso Doctrine DBAL](https://github.com/tursodatabase/turso-doctrine-dbal)