How to Compile PHP Modules
When developing PHP with ServBay, you may need to compile and install additional PHP modules to extend its functionality. This article will guide you on how to compile PHP modules in the ServBay environment, specifically focusing on compiling the imagick
and sqlsrv
modules.
Prerequisites
Note
Please ensure that you initialize the compilation environment and set up system environment variables according to the guidelines below; otherwise, the following operations will fail!
Before you begin compiling PHP modules, make sure you have completed the initialization of the compilation environment. For detailed steps on how to initialize the compilation environment, please refer to the document Using ServBay for Secondary Compilation.
The Importance of Specifying PHP Version
ServBay comes with multiple PHP versions. When compiling with phpize
, php-config
, and other tools, it is essential to specify the PHP version you are using. This is because different PHP versions may have varying configurations and dependencies, and selecting the correct version can help avoid compilation errors and runtime issues.
In this example, we will use PHP 8.3
.
Compiling the PHP imagick Module
The imagick
module is a PHP extension used for handling image manipulation. Here are the steps to compile the imagick
module:
Step 1: Download the Source Code
First, download the source package for 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 the Configuration File
Use phpize
to generate the configuration file. During this process, make 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 Compilation Options
Configure the compilation 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 the PHP 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 the Module Load
Restart the PHP service through the ServBay management panel, then verify if the module was successfully loaded via the command line:
php-8.3 -m | grep imagick
If the module has been successfully loaded, you should see imagick
in the output.
Compiling the PHP sqlsrv Module
Note
Prerequisites: To compile sqlsrv on macOS, you first need to install Microsoft's ODBC driver msodbcsql18
and mssql-tools18
.
ServBay does not include MS ODBC; please use Homebrew for installation.
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
HOMEBREW_ACCEPT_EULA=Y brew install msodbcsql18 mssql-tools18
2
3
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 for 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 the Configuration File
Use phpize
to generate the configuration file. During this process, make 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 Compilation Options
Configure the compilation options and specify the PHP configuration path.
export LDFLAGS="-L/opt/homebrew/lib ${LDFLAGS}"
export CPPFLAGS="-I/opt/homebrew/opt/unixodbc/include ${CPPFLAGS}"
./configure --with-php-config=${SERVBAY_PACKAGE_FULL_PATH}/php/8.3/current/bin/php-config
2
3
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 the PHP 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 the Module Load
Restart the PHP service through the ServBay management panel, then verify if the module was successfully loaded via the command line:
php-8.3 -m | grep sqlsrv
If the module has been successfully loaded, you should see sqlsrv
in the output.
Conclusion
By following the steps above, you can compile and install the necessary PHP modules in the ServBay environment. It is crucial to specify the correct PHP version during the compilation process to ensure the modules are compatible with your PHP environment. We hope this article helps you successfully complete the compilation and enabling of the PHP modules.