How to Compile PHP Modules
When developing PHP on 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 imagick
and sqlsrv
modules.
Prerequisites
Before you start compiling PHP modules, ensure that you have completed the initialization of the compilation environment. For detailed steps on how to initialize the compilation environment, refer to the documentation Re-Compiling with ServBay.
Importance of Specifying PHP Version
ServBay comes with multiple PHP versions. When using tools like phpize
, php-config
, and others, it is crucial to specify the PHP version you are using. This is because different PHP versions may have different configurations and dependencies. Choosing the correct version can prevent compilation errors and runtime issues.
This example uses PHP 8.3
.
Compile the PHP imagick module
The imagick
module is a PHP extension used for image processing. Below are the steps to compile the imagick
module:
Step 1: Download 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: Unzip the Source Package
Unzip the downloaded source package.
tar zxvf imagick-3.7.0.tgz
cd imagick-3.7.0
2
Step 3: Generate Configuration Files
Generate configuration files using phpize
. In this process, make sure to specify the PHP version you are using. For instance, if you are using PHP 8.3, run the following command:
${SERVBAY_PACKAGE_FULL_PATH}/php/8.3/current/bin/phpize
Step 4: Configure Compilation Options
Configure the compilation options, specifying 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, then verify whether the module has been successfully loaded through the command line:
php-8.3 -m | grep imagick
If the module is successfully loaded, you should see imagick
appearing in the output.
Compile the PHP sqlsrv module
The sqlsrv
module is a PHP extension used for interacting with Microsoft SQL Server. Below are the steps to compile the sqlsrv
module:
Step 1: Download 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: Unzip the Source Package
Unzip the downloaded source package.
tar zxvf sqlsrv-5.12.0.tgz
cd sqlsrv-5.12.0
2
Step 3: Generate Configuration Files
Generate configuration files using phpize
. In this process, make sure to specify the PHP version you are using. For instance, if you are using PHP 8.3, run the following command:
${SERVBAY_PACKAGE_FULL_PATH}/php/8.3/current/bin/phpize
Step 4: Configure Compilation Options
Configure the compilation options, specifying 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 an 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, then verify whether the module has been successfully loaded through the command line:
php-8.3 -m | grep sqlsrv
If the module is successfully loaded, you should see sqlsrv
appearing in the output.
Conclusion
By following the above steps, you can compile and install the required PHP modules in the ServBay environment. During the compilation process, make sure to specify the correct PHP version to ensure compatibility of the modules with your PHP environment. We hope this article helps you successfully complete the compilation and enabling of PHP modules.