When building a web server environment, PHP is one of the indispensable software, and various extensions of PHP can meet developers with different needs. Some extensions need to be compiled and installed manually under Windows. This article will introduce how to compile and install PHP extensions on Windows.
Compiling PHP extensions on Windows requires the use of some compilation tools, including the C compiler, the make tool and the pkg-config tool. You can obtain these tools by installing MSYS2. The specific method is as follows:
1.1 Download the MSYS2 installer
You can download the corresponding version on the MSYS2 official website (https://www.msys2.org/) The installer, here takes the 64-bit system as an example to download msys2-x86\_64-20210725.exe.
1.2 Install MSYS2
Double-click msys2-x86\_64-20210725.exe to perform the installation and follow the prompts. You can choose a custom installation path, just select the default path here.
1.3 Configure MSYS2
After the installation is complete, open msys2.exe in the MSYS2 installation path and execute the following command to update MSYS2:
pacman -Syu
After the update is completed, restart MSYS2 and execute The following command installs the compilation tool:
pacman -S --needed base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-pkg-config
Before compiling and installing the PHP extension, you need to download the corresponding source code. You can find the source code corresponding to the extension on PECL or GitHub.
After downloading the source code, unzip it to a directory, then open the MSYS2 terminal and enter the directory:
cd /path/to/ext
Execute Compile with the following commands:
phpize ./configure make
Among them, the phpize command will automatically generate configure scripts and makefile files according to the environment. The configure command is used to check the environment and generate Makefile files, and the make command is used to compile extensions.
After compilation is completed, execute the following command to install the PHP extension:
make install
At this time, the extended dll file will be installed into PHP In the extension directory, you can add the extension's configuration in the php.ini file.
After installing the extension, you can check whether the extension was successfully installed through the phpinfo function. Enter the following command on the command line:
php -r "phpinfo();"
Just look for the relevant information about the extension in the output information.
Summary
This article briefly introduces the steps to compile and install PHP extensions on Windows. Before starting compilation, you need to install the compilation tool corresponding to the PHP version, then download the extension source code and compile and install it. To facilitate debugging, it is best to enable debug mode during compilation and add extended configuration to the php.ini file.
The above is the detailed content of windows php extension compilation and installation. For more information, please follow other related articles on the PHP Chinese website!