php7 compile and install PDO ﹣ msql module

Keywords: Programming PHP PDO MySQL Linux

Compiling and installing PDO MySQL extension of php7

  1. Note the execution path of all the following codes. If your file is not in the path of the sample code, please execute it in the corresponding path of your own file
  2. The premise is that php7 is already installed using source code. Otherwise, you need to download the source code of PDO MySQL extension by yourself ####Enter the extended source location of PDO MySQL
[root@localhost ~]# cd /usr/src/php7.1.6/php-src-php-7.1.6/ext/pdo_mysql/
[root@localhost pdo_mysql]# pwd
[root@localhost pdo_mysql]#

Build config file to start compilation

[root@localhost pdo_mysql]# /usr/local/php7.1/bin/phpize 
Configuring for:
PHP Api Version:         20160303
Zend Module Api No:      20160303
Zend Extension Api No:   320160303
[root@localhost pdo_mysql]# ll
total 1868
-rw-r--r-- 1 root root  82506 Nov  6 20:32 acinclude.m4
-rw-r--r-- 1 root root 312883 Nov  6 20:32 aclocal.m4
drwxr-xr-x 2 root root     51 Nov  6 20:32 autom4te.cache
drwxr-xr-x 2 root root    110 Nov  6 20:32 build
-rwxr-xr-x 1 root root  42938 Nov  6 20:32 config.guess
-rw-r--r-- 1 root root   1790 Nov  6 20:32
-rwxrwxr-x 1 root root   5962 Jun  7  2017 config.m4
-rwxr-xr-x 1 root root  35987 Nov  6 20:32 config.sub
-rwxr-xr-x 1 root root 463384 Nov  6 20:32 configure
-rw-r--r-- 1 root root   4698 Nov  6 20:32
-rw-rw-r-- 1 root root    796 Jun  7  2017 config.w32
-rwxrwxr-x 1 root root     93 Jun  7  2017 CREDITS
-rw-rw-r-- 1 root root    643 Jun  7  2017 get_error_codes.php
-rw-r--r-- 1 root root      0 Nov  6 20:32 install-sh
-rw-r--r-- 1 root root 199728 Nov  6 20:32
-rw-r--r-- 1 root root   7236 Nov  6 20:32
-rw-r--r-- 1 root root      0 Nov  6 20:32 missing
-rw-r--r-- 1 root root      0 Nov  6 20:32 mkinstalldirs
-rw-rw-r-- 1 root root  22876 Jun  7  2017 mysql_driver.c
-rw-r--r-- 1 root root    341 Nov  5 11:52 mysql_driver.lo
-rw-r--r-- 1 root root 191912 Nov  5 11:52 mysql_driver.o
-rw-rw-r-- 1 root root  25454 Jun  7  2017 mysql_statement.c
-rw-r--r-- 1 root root    350 Nov  5 11:52 mysql_statement.lo
-rw-r--r-- 1 root root 165016 Nov  5 11:52 mysql_statement.o
-rw-rw-r-- 1 root root   3159 Jun  7  2017 package2.xml
-rw-rw-r-- 1 root root   8105 Jun  7  2017 pdo_mysql.c
-rw-r--r-- 1 root root    825 Nov  5 11:52
-rw-r--r-- 1 root root    332 Nov  5 11:52 pdo_mysql.lo
-rw-r--r-- 1 root root 140552 Nov  5 11:52 pdo_mysql.o
-rw-rw-r-- 1 root root   1674 Jun  7  2017 php_pdo_mysql.h
-rw-rw-r-- 1 root root   6292 Jun  7  2017 php_pdo_mysql_int.h
-rw-rw-r-- 1 root root  21629 Jun  7  2017 php_pdo_mysql_sqlstate.h
-rw-r--r-- 1 root root  82234 Nov  6 20:32 run-tests.php
drwxrwxr-x 2 root root   8192 Nov  5 12:04 tests

Initialize compilation parameters

[root@localhost pdo_mysql]# ./configure --with-php-config=/usr/local/php7.1/bin/php-config 
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr/local/php7.1
checking for PHP includes... -I/usr/local/php7.1/include/php -I/usr/local/php7.1/include/php/main -I/usr/local/php7.1/include/php/TSRM -I/usr/local/php7.1/include/php/Zend -I/usr/local/php7.1/include/php/ext -I/usr/local/php7.1/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/php7.1/lib/php/extensions/no-debug-non-zts-20160303
checking for PHP installed headers prefix... /usr/local/php7.1/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... re2c
checking for re2c version... 0.14.3 (ok)
checking for gawk... gawk
checking for MySQL support for PDO... yes, shared
checking for the location of libz... no
checking for MySQL UNIX socket location... 
checking for PDO includes... checking for PDO includes... /usr/local/php7.1/include/php/ext
checking for ld used by cc... /bin/ld
checking if the linker (/bin/ld) is GNU ld... yes
checking for /bin/ld option to reload object files... -r
checking for BSD-compatible nm... /bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 1572864
checking command to parse /bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... no
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h

Compile PDO file

[root@localhost pdo_mysql]# make && make install
/bin/sh /usr/src/php7.1.6/php-src-php-7.1.6/ext/pdo_mysql/libtool --mode=install cp ./ /usr/src/php7.1.6/php-src-php-7.1.6/ext/pdo_mysql/modules
cp ./.libs/ /usr/src/php7.1.6/php-src-php-7.1.6/ext/pdo_mysql/modules/
cp ./.libs/pdo_mysql.lai /usr/src/php7.1.6/php-src-php-7.1.6/ext/pdo_mysql/modules/
cp ./.libs/pdo_mysql.a /usr/src/php7.1.6/php-src-php-7.1.6/ext/pdo_mysql/modules/pdo_mysql.a
chmod 644 /usr/src/php7.1.6/php-src-php-7.1.6/ext/pdo_mysql/modules/pdo_mysql.a
ranlib /usr/src/php7.1.6/php-src-php-7.1.6/ext/pdo_mysql/modules/pdo_mysql.a
libtool: install: warning: remember to run `libtool --finish /usr/src/php7.1.6/php-src-php-7.1.6/modules'

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/local/php7.1/lib/php/extensions/no-debug-non-zts-20160303/

Modify php.ini and add PDO ﹣ MySQL extension

[root@localhost no-debug-non-zts-20160303]# vim /etc/php7.1.6/php.ini
> About line 909

Restart PHP FPM

[root@localhost no-debug-non-zts-20160303]# service php7.1-fpm restart

Check whether the extension is installed successfully, as shown below. If there is PDO [msql], the installation is successful

[root@localhost no-debug-non-zts-20160303]# php7.1 -m
[PHP Modules]

[Zend Modules]

Posted by vornn on Wed, 13 Nov 2019 09:52:47 -0800