Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2023-05-27 09:10:30
forward
1006 people have browsed it

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

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

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

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

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

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

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

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!

Related labels:
source:yisu.com
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