Before starting the source compilation, you need to verify your system environment and dependencies to ensure a smooth installation process. First, check if PHP, MySQL, and related libraries, such as libmysqlclient, are installed. Use the following commands to check:
php -v mysql -V
If the dependencies are not installed, you can install them using your package manager. For example, on Ubuntu:
sudo apt-get install libmysqlclient-dev
After verifying the environment, download the PHP source package for compilation. You can download the latest version from the official PHP website or use wget:
wget https://www.php.net/distributions/php-7.x.x.tar.gz
Once downloaded, extract the source package and enter the directory:
tar -zxvf php-7.x.x.tar.gz cd php-7.x.x
During configuration and compilation, enable PDO and MySQL extensions, specifying the MySQL path:
./configure --with-pdo-mysql --with-mysqli=/path/to/mysql_config
After configuration, compile and install:
make sudo make install
After installation, verify PHP:
php -v
After installation, configure php.ini to enable PDO and MySQL extensions. Edit the php.ini file:
sudo vi /etc/php/php.ini
Uncomment the following lines:
extension=pdo_mysql.so extension=mysqli.so
Save and exit, then restart the PHP service:
sudo service php-fpm restart
Create a PHP script to test the PDO MySQL connection:
<?php $db = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password'); $stmt = $db->query('SELECT * FROM mytable'); while ($row = $stmt->fetch()) { print_r($row); } ?>
Save as test.php and access it via a browser. If it outputs the database data correctly, the PDO MySQL connection is successful.
By following these steps, you can complete the PHP PDO MySQL source compilation installation and perform basic configuration and functionality testing. This guide aims to help you efficiently accomplish a custom PHP PDO MySQL setup.