Building a PHP Extension
On this site, you find a step-by-step guide on how to build a PHP Extension for a specific PHP Version.
#
Building a PHP ExtensionMake a backup of your instance.
Install the dev package for the PHP Version.
apt update && apt -y install php8.1-dev
- Go to https://pecl.php.net/ and search for the extension like ssh2:

- Download the tgz via cURL:
curl -O https://pecl.php.net/get/ssh2-1.3.1.tgz
- Extract the tgz:
tar xf ssh2-1.3.1.tgz
- phpize the extension:
cd ssh2-1.3.1phpize8.1
- Compile and build the extension:
./configuremakemake install
- Register the extension for CLI and FPM in the php.ini:
CLI
nano /etc/php/8.1/cli/php.ini
Add the following line at the end:
extension=ssh2.so
FPM
nano /etc/php/8.1/fpm/php.ini
Add the following line at the end:
extension=ssh2.so
- Restart the PHP-FPM service:
systemctl restart php8.1-fpm
#
TestingAfter registering the PHP Extension, you can check if the extension is loaded for CLI and FPM correctly.
#
CLIYou can use grep to check if the extension is loaded:
php8.1 -m |grep 'ssh2'
If you don't get an output, then the extension is NOT loaded.
#
FPMTo check if the extension is loaded for FPM, you can check the phpinfo.
Create the file t.php in the root directory.
Put the following content in the file:
<?phpphpinfo();
- Open t.php in your browser and search for the extension.

If you don't find information about the extension, then it's NOT loaded.