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.
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 installThese 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
testYou 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 worldThis completes the build and installation of the extension; the next step will prepare it for a production environment.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
