Home > Backend Development > PHP Problem > windows php extension compilation and installation

windows php extension compilation and installation

WBOY
Release: 2023-05-06 10:05:07
Original
1278 people have browsed it

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.

  1. Install compilation tools

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
Copy after login

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
Copy after login
  1. Download the PHP extension source code

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.

  1. Compile PHP extension

After downloading the source code, unzip it to a directory, then open the MSYS2 terminal and enter the directory:

cd /path/to/ext
Copy after login

Execute Compile with the following commands:

phpize
./configure
make
Copy after login

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.

  1. Install PHP extension

After compilation is completed, execute the following command to install the PHP extension:

make install
Copy after login

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.

  1. Test PHP extension

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();"
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template