How to Build and Install a PHP Extension from Scratch

This guide walks you through creating a PHP extension, covering environment setup, using phpize, configuring, compiling with make, installing the shared test.so module, adding it to php.ini, and verifying its functionality with command‑line tests, preparing you for production deployment.

360 Zhihui Cloud Developer
360 Zhihui Cloud Developer
360 Zhihui Cloud Developer
How to Build and Install a PHP Extension from Scratch

Today we share a series of articles on writing PHP extensions, covering environment setup to extension development, introducing relevant PHP core data structures and APIs.

The extension framework can be compiled without any modifications. The first phpize command is part of the PHP build created in step one (it should already be in your PATH).

$ phpize
$ ./configure
$ make
$ make install

These commands build the shared extension test.so and copy it to the PHP installation directory. To load it, add a line to a custom php.ini file. $ vi ~/php-bin/DEBUG/etc/php.ini Add the following line: extension=test.so Verify that the extension is loaded and working; the php -m command lists loaded extensions:

$ php -m | grep test
test

You can also run functions defined in the test extension:

$ php -r 'test_test1();'
The extension test is loaded and working!
$ php -r 'echo test_test2("world
");'
Hello world

This completes the build and installation of the extension; the next step will prepare it for a production environment.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendCompilationLinuxPHPExtension Development
360 Zhihui Cloud Developer
Written by

360 Zhihui Cloud Developer

360 Zhihui Cloud is an enterprise open service platform that aims to "aggregate data value and empower an intelligent future," leveraging 360's extensive product and technology resources to deliver platform services to customers.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.