How to Compile PHP Modules
When developing PHP with ServBay, you may need to compile and install additional PHP modules to extend PHP's functionality. This article will explain how to compile PHP modules in the ServBay environment, specifically including the compilation of the imagick
and sqlsrv
modules.
Prerequisites
Before starting to compile PHP modules, ensure that you have completed the initialization of the build environment. For detailed steps on how to initialize the build environment, please refer to the documentation Secondary Compilation with ServBay.
Importance of Specifying PHP Version
ServBay comes with multiple PHP versions. When using tools like phpize
, php-config
, and others for compilation, you must specify the PHP version you are using. Different PHP versions may have different configurations and dependencies. Choosing the correct version can avoid compilation errors and runtime issues.
This example uses PHP 8.3
.
Compiling the PHP imagick Module
The imagick
module is a PHP extension for image manipulation. Here are the steps to compile the imagick
module:
Step 1: Download the Source Code
First, download the source package of the imagick
module from PECL.
wget https://pecl.php.net/get/imagick-3.7.0.tgz
Step 2: Extract the Source Package
Extract the downloaded source package.
tar zxvf imagick-3.7.0.tgz
cd imagick-3.7.0
2
Step 3: Generate Configuration Files
Use phpize
to generate the configuration files. During this process, be sure to specify the PHP version you are using. For example, if you are using PHP 8.3, run the following command:
${SERVBAY_PACKAGE_FULL_PATH}/php/8.3/current/bin/phpize
Step 4: Configure Build Options
Configure the build options and specify the PHP configuration path.
./configure --with-php-config=${SERVBAY_PACKAGE_FULL_PATH}/php/8.3/current/bin/php-config
Step 5: Compile and Install
Compile and install the imagick
module.
make -j ${CPU_NUMBER}
make install
2
Step 6: Enable the Module
Create an imagick.ini
file in PHP's conf.d
directory to enable the imagick
module. For example:
echo "extension=imagick.so" > /Applications/ServBay/package/etc/php/8.3/conf.d/imagick.ini
Step 7: Verify Module Loading
Restart the PHP service through the ServBay management panel, and then verify whether the module is successfully loaded via the command line:
php-8.3 -m | grep imagick
If the module is successfully loaded, you should see imagick
in the output.
Compiling the PHP sqlsrv Module
The sqlsrv
module is a PHP extension for interacting with Microsoft SQL Server. Here are the steps to compile the sqlsrv
module:
Step 1: Download the Source Code
First, download the source package of the sqlsrv
module from PECL.
wget https://pecl.php.net/get/sqlsrv-5.12.0.tgz
Step 2: Extract the Source Package
Extract the downloaded source package.
tar zxvf sqlsrv-5.12.0.tgz
cd sqlsrv-5.12.0
2
Step 3: Generate Configuration Files
Use phpize
to generate the configuration files. During this process, be sure to specify the PHP version you are using. For example, if you are using PHP 8.3, run the following command:
${SERVBAY_PACKAGE_FULL_PATH}/php/8.3/current/bin/phpize
Step 4: Configure Build Options
Configure the build options and specify the PHP configuration path.
./configure --with-php-config=${SERVBAY_PACKAGE_FULL_PATH}/php/8.3/current/bin/php-config
Step 5: Compile and Install
Compile and install the sqlsrv
module.
make -j ${CPU_NUMBER}
make install
2
Step 6: Enable the Module
Create a sqlsrv.ini
file in PHP's conf.d
directory to enable the sqlsrv
module. For example:
echo "extension=sqlsrv.so" > /Applications/ServBay/package/etc/php/8.3/conf.d/sqlsrv.ini
Step 7: Verify Module Loading
Restart the PHP service through the ServBay management panel, and then verify whether the module is successfully loaded via the command line:
php-8.3 -m | grep sqlsrv
If the module is successfully loaded, you should see sqlsrv
in the output.
Summary
By following the steps above, you can compile and install the required PHP modules in the ServBay environment. During the compilation process, be sure to specify the correct PHP version to ensure the module is compatible with your PHP environment. I hope this article helps you successfully compile and enable PHP modules.