Home  >  Article  >  Backend Development  >  How to compile and install PHP OpenSSL extension on Linux

How to compile and install PHP OpenSSL extension on Linux

PHPz
PHPzOriginal
2023-04-04 17:28:061066browse

When using PHP to perform operations such as encryption and decryption, we usually need to call the OpenSSL function library. In many cases, PHP does not support the OpenSSL extension by default, so the OpenSSL extension needs to be compiled and installed manually. This article will introduce in detail how to compile and install the PHP OpenSSL extension on a Linux system.

Step 1: Install OpenSSL

First you need to install OpenSSL, execute the following command:

sudo apt-get update
sudo apt-get install openssl

After the installation is complete, run the following command to check the OpenSSL installation status:

openssl version

If the installation is successful, OpenSSL version information will be displayed.

Step 2: Download the PHP source code package

Before installing the OpenSSL extension, you need to download the PHP source code package. It can be downloaded from the PHP official website. Here we take PHP 7.3.9 version as an example:

wget https://www.php.net/distributions/php-7.3.9.tar.gz

After the download is completed, execute the following command to decompress:

tar -zxvf php-7.3.9.tar.gz

After decompression, enter the directory of the PHP source code package:

cd php-7.3.9

Step 3: Configure PHP

Before compiling PHP, you need to configure it. The configuration command is as follows:

./configure --with-openssl=/usr/bin/openssl --with-php-config=/usr/bin/php-config

Among them, --with-openssl specifies the installation of OpenSSL Path, --with-php-config specifies the PHP configuration file path.

After executing the configuration command, execute the following command to compile:

make

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

sudo make install

After the installation is completed, enter the PHP extension directory , execute the following command to check whether it has been compiled and installed successfully:

cd /usr/lib/php/20180731/
ls -l | grep openssl

If openssl.so is displayed, it means that the openssl extension has been successfully installed.

Step 4: Configure the php.ini file

The last step is to configure the openssl extension in the php.ini file. Find the php.ini file and open it, add the following content:

extension=openssl.so

Save and close the file.

At this point, we have successfully compiled and installed the PHP OpenSSL extension. We can call the OpenSSL function library in the PHP code to perform operations such as encryption and decryption.

The above is the detailed content of How to compile and install PHP OpenSSL extension on Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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