Home  >  Article  >  Database  >  How to compile and install the PHP-PDO-MYSQL extension using source code

How to compile and install the PHP-PDO-MYSQL extension using source code

WBOY
WBOYforward
2023-05-27 09:10:301005browse

Step 1: Download the source code

First, you need to download the PHP source code from the PHP official website. You can choose the latest stable version or an older version. On the download page, you can see options for different versions. Select the version for your operating system and download the source code archive. After unzipping the file, go to the unzipped directory.

Step 2: Install compilation tools and dependencies

Before you start compiling and installing PHP extensions, you must first install certain key compilation tools and dependencies. In Ubuntu, these dependencies can be installed using the following command:

sudo apt-get install build-essential
sudo apt-get install libxml2-dev libssl-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libpng-dev libfreetype6-dev libmcrypt-dev libreadline-dev

In other Linux distributions, install these packages using the corresponding package manager.

Step 3: Compile PHP

Enter the source code directory and use the following command to compile PHP:

./configure --prefix=/usr/local/php --with-pdo-mysql

The above command specifies the installation directory of PHP and compile option --with-pdo-mysql to support MySQL database connections. After executing the above command, the Makefile will be generated. Run the following command to compile PHP:

make

This process may take a few minutes or longer, depending on the performance of your system. If there are no errors, you can execute the following command to install PHP:

sudo make install

Step 4: Open the php.ini file

Enabling the PDO-MYSQL extension requires editing php.ini file, this needs to be done after installing PHP. In Ubuntu, this file can be found at:

/etc/php/7.2/apache2/php.ini

In other Linux distributions, the location may vary, but it can usually be found in the "/etc/php" directory. Add the following code to the php.ini file, which can be achieved by searching for the keyword "extension=":

extension=pdo_mysql.so

This code will enable the PDO-MYSQL database extension. Save the file and exit the editor.

Step 5: Restart the web server

Finally, you need to restart the web server for the changes to take effect. In Ubuntu, use the following command to restart the Apache server:

sudo service apache2 restart

In other Linux distributions, use the corresponding system prompts to restart the web server.

The above is the detailed content of How to compile and install the PHP-PDO-MYSQL extension using source code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete