Skip to content

Instantly share code, notes, and snippets.

@masakielastic
Last active February 21, 2026 21:38
Show Gist options
  • Select an option

  • Save masakielastic/4e2ddaa83999b1e5dc1893922ec6da5a to your computer and use it in GitHub Desktop.

Select an option

Save masakielastic/4e2ddaa83999b1e5dc1893922ec6da5a to your computer and use it in GitHub Desktop.
PIE (PHP Installer for Extensions) で PHP 拡張モジュールをビルドする

PIE (PHP Installer for Extensions) で PHP 拡張モジュールをビルドする

php-ext-hello という拡張モジュールがローカルにあることを前提とします。

composer.json

PHP 拡張モジュールのフォルダーに composer.json を設置します。

composer.json

{
  "name": "masakielastic/php-ext-hello",
  "description": "Hello World extension",
  "version": "0.1",
  "type": "php-ext",
  "license": "BSD-3-Clause",
  "require": {
    "php": ">=8.1"
  },
  "php-ext": {
    "extension-name": "hello"
  }
}

リポジトリにはタグが設定されていることを前提とします。

git tag 0.1

ローカルのリポジトリを登録します。

pie repository:add path /home/masakielastic/php-ext-hello

登録されたかどうかを確認します。

pie repository:list

ビルドとインストール

ビルドしてみます。

pie build masakielastic/php-ext-hello

結果は次のようになります。

🥧 PHP Installer for Extensions (PIE) 1.3.8, from The PHP Foundation
You are running PHP 8.5.3
Target PHP installation: 8.5.3 nts, on Linux/OSX/etc x86_64 (from /usr/bin/php8.5)
Found package: masakielastic/php-ext-hello:0.1 which provides ext-hello
Extracted masakielastic/php-ext-hello:0.1 source to: /home/masakielastic/.config/pie/php8.5_6196662ea494e76a7aab6ead04c3b45b/vendor/masakielastic/php-ext-hello
phpize complete.
Configure complete with options: --with-php-config=/usr/bin/php-config
Build complete: /home/masakielastic/.config/pie/php8.5_6196662ea494e76a7aab6ead04c3b45b/vendor/masakielastic/php-ext-hello/modules/hello.so

インストールしてみます。

masakielastic@penguin:~/test$ pie install masakielastic/php-ext-hello

結果は次のとおりです。

🥧 PHP Installer for Extensions (PIE) 1.3.8, from The PHP Foundation
This command may need elevated privileges, and may prompt you for your password.
You are running PHP 8.5.3
Target PHP installation: 8.5.3 nts, on Linux/OSX/etc x86_64 (from /usr/bin/php8.5)
Found package: masakielastic/php-ext-hello:0.1 which provides ext-hello
Extracted masakielastic/php-ext-hello:0.1 source to: /home/masakielastic/.config/pie/php8.5_6196662ea494e76a7aab6ead04c3b45b/vendor/masakielastic/php-ext-hello
Build files cleaned up.
phpize complete.
Configure complete with options: --with-php-config=/usr/bin/php-config
Build complete: /home/masakielastic/.config/pie/php8.5_6196662ea494e76a7aab6ead04c3b45b/vendor/masakielastic/php-ext-hello/modules/hello.so
Cannot write to /usr/lib/php/20250925, so using sudo to elevate privileges.
Install complete: /usr/lib/php/20250925/hello.so
✅ Extension is enabled and loaded in /usr/bin/php8.5

PHP がモジュールをロードしているか確認します。

masakielastic@penguin:~/test$ pie install masakielastic/php-ext-hello
🥧 PHP Installer for Extensions (PIE) 1.3.8, from The PHP Foundation
This command may need elevated privileges, and may prompt you for your password.
You are running PHP 8.5.3
Target PHP installation: 8.5.3 nts, on Linux/OSX/etc x86_64 (from /usr/bin/php8.5)
Found package: masakielastic/php-ext-hello:0.1 which provides ext-hello
Extracted masakielastic/php-ext-hello:0.1 source to: /home/masakielastic/.config/pie/php8.5_6196662ea494e76a7aab6ead04c3b45b/vendor/masakielastic/php-ext-hello
Build files cleaned up.
phpize complete.
Configure complete with options: --with-php-config=/usr/bin/php-config
Build complete: /home/masakielastic/.config/pie/php8.5_6196662ea494e76a7aab6ead04c3b45b/vendor/masakielastic/php-ext-hello/modules/hello.so
Cannot write to /usr/lib/php/20250925, so using sudo to elevate privileges.
Install complete: /usr/lib/php/20250925/hello.so
✅ Extension is enabled and loaded in /usr/bin/php8.5

PHP CLI ツールで hello モジュールがロードされているかチェックします。

php -m | grep hello
hello

Github リポジトリの登録

Github リポジトリを登録して利用するには次のコマンドを実行します。

pie repository:add vcs https://github.com/masakielastic/php-ext-hello

登録されたかどうか確認します。

pie repository:list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment