How to Install PHP Extensions Easily with PIE

Installing PHP extensions traditionally involved challenges like finding precompiled binaries, using OS package managers, or manually compiling from source. These methods could be inconsistent across platforms and required different commands, making the process complex and prone to errors.

PECL, while helpful, feels antiquated. It’s not as easy to put your extension in PHP as it is with Composer. PIE is an initiative from the PHP Foundation to solve this by treating extensions as Composer packages. It simplifies the process, offers better cross-platform consistency, and ensures easier updates and management for PHP extensions.

Prerequisites

Before we begin, ensure you have PHP 8.1 or newer to run PIE. However, PIE can install extensions for any installed PHP version. To check the PHP version on your computer, you can run: php -v

Checking PHP version using php -v command

Installation

To install the PHP Installer for Extensions (PIE), you can follow these steps:

1. Download the PHAR package

First, you need to download the pie.phar file from the official repository or website. This is the primary file needed to use PIE.

2. PHAR installation

Move pie.phar into your computer’s PATH, such as /usr/local/bin/, so you can run it from anywhere. You can rename it for convenience, for example:

mv pie.phar /usr/local/bin/pie

On Windows, you can move it to C:\Program Files or any other directory in your PATH. However, I recommend using Composer and its CLI with the Windows Subsystem for Linux (WSL) for a better experience.

3. Make it executable

On non-Windows machines, you need to change the permissions to make it executable.

chmod +x /usr/local/bin/pie

That’s it. You can try running pie in your terminal to see if it’s installed correctly.

Checking PIE version after installation

We can now use PIE to install PHP extensions with ease using the pie command.

pie install <vendor>/<package>

For example, let’s say you want to install the xdebug extension to perform debugging in your PHP application. You can run:

pie install xdebug/xdebug

This command will pull the xdebug extension from Packagist, build it, and install it in your PHP installation. PIE will also add the extension to your php.ini file, so you don’t have to do it manually.

You can find all extensions that you can install through PIE in Packagist.

Note for Windows

PIE currently does not support building extensions on Windows. It relies on the extension author to provide the pre-built DLL file for their extension, so there are probably some extensions that you can’t install on Windows.

Wrapping Up

PIE is a great initiative to simplify the installation of PHP extensions. I like how it treats extensions as Composer packages, making it easier to manage and update them. I think it’s a step in the right direction to modernize the PHP ecosystem and make it more developer-friendly.

WebsiteFacebookTwitterInstagramPinterestLinkedInGoogle+YoutubeRedditDribbbleBehanceGithubCodePenWhatsappEmail