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

PHPz
Release: 2023-03-23 10:01:43
Original
1079 people have browsed it

PHP-PDO (PHP Data Objects) is a lightweight abstract database interface in PHP, used to connect and operate databases. MySQL is one of the most popular open source relational databases and is widely used in web development. This article will introduce how to compile and install the PHP-PDO-MYSQL extension from source code in order to connect PHP to a MySQL database.

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 compiling and installing the PHP extension, you need to ensure that some necessary compilation tools and dependencies have been installed. 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

After installing PHP, you need to edit php. ini file to enable the PDO-MYSQL extension. In Ubuntu, this file can be found at:

/etc/php/7.2/apache2/php.ini
Copy after login

The location in other Linux distributions may be different, but it is usually in the "/etc/php" directory. Open the php.ini file, search for the "extension=" keyword, and add the following code:

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.

Conclusion

Here we have seen how to compile and install the PHP-PDO-MYSQL extension from source. This is an important step in connecting PHP to a MySQL database, as this extension provides the basic functions and drivers needed to connect to a MySQL database. However, please note that this only applies to those users who need to install PHP manually, other users can install the PHP-PDO-MYSQL extension through other means such as Yum or Apt.

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

Related labels:
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