Remove sqlite3, the module installed by php7 compilation

Remove the modules installed by php7 compilation. Take sqlite3 as an example

SQLite3 extension has been enabled by default since PHP 5.3.0. Allow -- without SQLite3 disabled at compile time

background

When I develop a project, I need to use php to connect to the encrypted sqlite database, but the sqlite extension compiled by php by default does not support connecting to the encrypted sqlite database, so I must remove the compiled sqlite3 and install the expansion of the sqlite database that supports connecting to the encrypted sqlite database

premise

Suppose that you have compiled and installed php7, and you do not display the prohibition -- without SQLite3 when compiling and installing php7, which results in the module has been compiled and installed into PHP. On this premise, let's look at this article again If you don't know how to compile and install php7, refer to this article centos7 compiling and installing php7

In the process of viewing the article, you must pay attention to the operation paths of each command. You need to replace these paths with the paths in your own development environment. Remember The php7.1 command in this article is only a soft connection to the PHP command. If it is unclear, please read this article carefully centos7 compiling and installing php7

Check the modules installed in php

[root@localhost ~]# php7.1 -m
[PHP Modules]
bcmath
Core
ctype
curl
date
dom
fileinfo
filter
ftp
gd
gettext
hash
iconv
json
libxml
mbstring
mcrypt
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_dblib
pdo_mysql
pdo_sqlite
Phar
posix
rdkafka
redis
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
swoole
sysvsem
tokenizer
xdebug
xml
xmlreader
xmlrpc
xmlwriter
zip
zlib

[Zend Modules]
Xdebug

[root@localhost ~]#

It can be seen that sqlite3 has been installed, because it is enabled by PHP by default, so the php.ini In the file, you can't see that the extension has been shown and enabled, that is, code like this

extension=sqlite3.so

Recompile php

Enter the source file of PHP, that is, the file when you compiled and installed PHP. If you have deleted it, use php7.1-v to check the version of PHP, then go to the official website of PHP and download the source code again. For the way to get the source code, please refer to this article Of course, you can find it yourself

  1. Enter source file
[root@localhost php-src-php-7.1.6]# pwd
/usr/src/php7.1.6/php-src-php-7.1.6
[root@localhost php-src-php-7.1.6]#
  1. Clear historical compiled files
[root@localhost php-src-php-7.1.6]# make clean
find . -name \*.gcno -o -name \*.gcda | xargs rm -f
find . -name \*.lo -o -name \*.o | xargs rm -f
find . -name \*.la -o -name \*.a | xargs rm -f 
find . -name \*.so | xargs rm -f
find . -name .libs -a -type d|xargs rm -rf
rm -f libphp7.la sapi/cli/php sapi/cgi/php-cgi   sapi/fpm/php-fpm  modules/* libs/*
  1. Rebuild build configuration
[root@localhost php-src-php-7.1.6]# ./buildconf --force
Forcing buildconf
Removing configure caches
  1. View historical compilation configuration
[root@localhost php-src-php-7.1.6]# php7.1 -i | grep configure
Configure Command =>  './configure'  '--prefix=/usr/local/php7.1' '--exec-prefix=/usr/local/php7.1' '--bindir=/usr/local/php7.1/bin' '--sbindir=/usr/local/php7.1/sbin' '--includedir=/usr/local/php7.1/include' '--libdir=/usr/local/php7.1/lib/php' '--mandir=/usr/local/php7.1/php/man' '--with-config-file-path=/etc/php7.1.6' '--with-mysql-sock=/tmp/mysql.sock' '--with-mcrypt' '--with-mhash' '--with-openssl' '--with-mysqli=shared,mysqlnd' '--with-pdo-mysql=shared,mysqlnd' '--with-gd' '--with-iconv' '--with-zlib' '--enable-zip' '--enable-inline-optimization' '--disable-debug' '--disable-rpath' '--enable-shared' '--enable-xml' '--enable-bcmath' '--enable-shmop' '--enable-sysvsem' '--enable-mbregex' '--enable-mbstring' '--enable-ftp' '--enable-gd-native-ttf' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-soap' '--without-pear' '--with-gettext' '--enable-session' '--with-curl' '--with-jpeg-dir' '--with-freetype-dir' '--enable-opcache' '--enable-fpm' '--with-fpm-user=nginx' '--with-fpm-group=nginx' '--without-gdbm' '--enable-fast-install' '--disable-fileinfo'
  1. Modify the compilation configuration as follows
./configure --prefix=/usr/local/php7.1 --exec-prefix=/usr/local/php7.1 --bindir=/usr/local/php7.1/bin --sbindir=/usr/local/php7.1/sbin --includedir=/usr/local/php7.1/include --libdir=/usr/local/php7.1/lib/php --mandir=/usr/local/php7.1/php/man --with-config-file-path=/etc/php7.1.6 --with-mysql-sock=/tmp/mysql.sock --with-mcrypt --with-mhash --with-openssl --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-iconv --with-zlib --enable-zip --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --without-gdbm --enable-fast-install --disable-fileinfo --without-sqlite3 --without-pdo_sqlite

Pay attention to changing the file path to your local one. The main compiling parameter is to add -- without sqlite3 -- without PDO at the end of the historical compiling parameter_ SQLite, which is used to remove the sqlite3 module originally installed by default compilation, while without PDO_ SQLite is also removed because it depends on sqlite3. If it is not removed, an error will be reported

  1. Run build configuration
[root@localhost php-src-php-7.1.6]# ./configure --prefix=/usr/local/php7.1  --exec-prefix=/usr/local/php7.1  --bindir=/usr/local/php7.1/bin  --sbindir=/usr/local/php7.1/sbin  --includedir=/usr/local/php7.1/include  --libdir=/usr/local/php7.1/lib/php  --mandir=/usr/local/php7.1/php/man  --with-config-file-path=/etc/php7.1.6  --with-mysql-sock=/tmp/mysql.sock  --with-mcrypt  --with-mhash  --with-openssl   --with-mysqli=mysqlnd  --with-pdo-mysql=mysqlnd  --with-gd  --with-iconv  --with-zlib  --enable-zip  --enable-inline-optimization  --disable-debug  --disable-rpath  --enable-shared  --enable-xml  --enable-bcmath  --enable-shmop  --enable-sysvsem  --enable-mbregex  --enable-mbstring  --enable-ftp  --enable-gd-native-ttf  --enable-pcntl  --enable-sockets  --with-xmlrpc  --enable-soap  --without-pear  --with-gettext  --enable-session  --with-curl  --with-jpeg-dir  --with-freetype-dir  --enable-opcache  --enable-fpm  --with-fpm-user=nginx  --with-fpm-group=nginx  --without-gdbm  --enable-fast-install  --disable-fileinfo --without-sqlite3 --without-pdo_sqlite

# Omit part of the output. If the following prompt appears at the end, there is no error. You can make the next step


Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

config.status: creating php7.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/www.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
[root@localhost php-src-php-7.1.6]#
  1. make

Add - j 8 to speed up compilation

[root@localhost php-src-php-7.1.6]# make -j 8

The following prompt indicates that make is successful

Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
clicommand.inc
directorygraphiterator.inc
directorytreeiterator.inc
invertedregexiterator.inc
pharcommand.inc
phar.inc

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

  1. install
[root@localhost php-src-php-7.1.6]# make install
Installing shared extensions:     /usr/local/php7.1/lib/php/extensions/no-debug-non-zts-20160303/
Installing PHP CLI binary:        /usr/local/php7.1/bin/
Installing PHP CLI man page:      /usr/local/php7.1/php/man/man1/
Installing PHP FPM binary:        /usr/local/php7.1/sbin/
Installing PHP FPM defconfig:     skipping
Installing PHP FPM man page:      /usr/local/php7.1/php/man/man8/
Installing PHP FPM status page:   /usr/local/php7.1/php/php/fpm/
Installing phpdbg binary:         /usr/local/php7.1/bin/
Installing phpdbg man page:       /usr/local/php7.1/php/man/man1/
Installing PHP CGI binary:        /usr/local/php7.1/bin/
Installing PHP CGI man page:      /usr/local/php7.1/php/man/man1/
Installing build environment:     /usr/local/php7.1/lib/php/build/
Installing header files:          /usr/local/php7.1/include/php/
Installing helper programs:       /usr/local/php7.1/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php7.1/php/man/man1/
  page: phpize.1
  page: php-config.1
/usr/src/php7.1.6/php-src-php-7.1.6/build/shtool install -c ext/phar/phar.phar /usr/local/php7.1/bin
ln -s -f phar.phar /usr/local/php7.1/bin/phar
Installing PDO headers:           /usr/local/php7.1/include/php/ext/pdo/
  1. It is very important to replace the original php7.1-fpm. If you do not replace php7.1-fpm, an error will be reported when you restart php7.1-fpm

If you don't know how php7.1-fpm came from, please read this carefully article

[root@localhost php-src-php-7.1.6]# cp -f sapi/fpm/init.d.php-fpm /etc/init.d/php7.1-fpm
cp: overwrite '/etc/init.d/php7.1-fpm'? y
[root@localhost php-src-php-7.1.6]#
  1. Restart php7.1-fpm
[root@localhost php-src-php-7.1.6]# service php7.1-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm [18-Jun-2020 15:02:39] NOTICE: PHP message: PHP Warning:  Module 'pdo_mysql' already loaded in Unknown on line 0
[18-Jun-2020 15:02:39] NOTICE: PHP message: PHP Warning:  Module 'mysqli' already loaded in Unknown on line 0
 done
[root@localhost php-src-php-7.1.6]#

You'll report a mistake like the one above, so go php.ini Note that the comments here will not affect the actual use of these modules

  1. Note the corresponding module, PDO in this case_ MySQL and mysqli
[root@localhost php-src-php-7.1.6]# vim /etc/php7.1.6/php.ini

;extension=pdo_mysql.so
;extension=mysqli.so
  1. Restart php7.1-fpm, as shown below, it is successful
[root@localhost php-src-php-7.1.6]# service php7.1-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done
  1. If you look at the php module, you will find that sqlite3 module has been removed, while other modules still exist. So far, the module has been removed successfully. If you don't need to install sqlite3 module through extension, you don't need to look down
[PHP Modules]
bcmath
Core
ctype
curl
date
dom
fileinfo
filter
ftp
gd
gettext
hash
iconv
json
libxml
mbstring
mcrypt
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_dblib
pdo_mysql
Phar
posix
rdkafka
redis
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
standard
swoole
sysvsem
tokenizer
xdebug
xml
xmlreader
xmlrpc
xmlwriter
zip
zlib

[Zend Modules]
Xdebug

[root@localhost sqlite3]#

Enter sqlite3 source code of php, recompile and install sqlite3 extension

  1. Enter sqlite3 source code of php and recompile the extension
[root@localhost php-src-php-7.1.6]# cd ext/sqlite3/
[root@localhost sqlite3]# pwd
/usr/src/php7.1.6/php-src-php-7.1.6/ext/sqlite3
[root@localhost sqlite3]#  /usr/local/php7.1/bin/phpize
Configuring for:
PHP Api Version:         20160303
Zend Module Api No:      20160303
Zend Extension Api No:   320160303
[root@localhost sqlite3]# ./configure --with-php-config=/usr/local/php7.1/bin/php-config
-bash: ./configure: No such file or directory

An error will be reported. / configure: No such file or directory. The solution is as follows

[root@localhost sqlite3]# cp config0.m4 config.m4
[root@localhost sqlite3]# ./configure --with-php-config=/usr/local/php7.1/bin/php-config
  1. make and install
[root@localhost sqlite3]# make && make install
#Omit process
Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/local/php7.1/lib/php/extensions/no-debug-non-zts-20160303/
Installing header files:          /usr/local/php7.1/include/php/
[root@localhost sqlite3]# 

  1. Enter the extended directory, use the sqlite3.so file provided by me to replace the sqlite3.so file in the directory, and modify the file permission to 755. The replaced sqlite3.so file will be provided at the end of the article
[root@localhost sqlite3]# cd /usr/local/php7.1/lib/php/extensions/no-debug-non-zts-20160303/
[root@localhost no-debug-non-zts-20160303]# ll
total 30820
-rwxr-xr-x 1 root root  3618150 Nov 26  2018 fileinfo.so
-rwxr-xr-x 1 root root  1375702 May 12  2019 mysqli.a
-rwxr-xr-x 1 root root   649400 May 12  2019 mysqli.so
-rwxr-xr-x 1 root root  3419404 Jun 18 14:59 opcache.a
-rwxr-xr-x 1 root root  1635776 Jun 18 14:59 opcache.so
-rwxr-xr-x 1 root root   124455 Nov 20  2018 pdo_dblib.so
-rwxr-xr-x 1 root root   497966 Nov  6  2018 pdo_mysql.a
-rwxr-xr-x 1 root root   229814 Nov  6  2018 pdo_mysql.so
-rwxr-xr-x 1 root root   348013 Nov 19  2018 pdo_sqlsrv.so
-rwxr-xr-x 1 root root   466649 Jun 13  2019 rdkafka.so
-rwxr-xr-x 1 root root  2379481 May 13  2019 redis.so
-rwxr-xr-x 1 root root  4718648 Jun 18 15:22 sqlite3.so
-rwxr-xr-x 1 root root 10758700 May 10  2019 swoole.so
-rwxr-xr-x 1 root root  1311591 Nov 20  2018 xdebug.so
[root@localhost no-debug-non-zts-20160303]# pwd
/usr/local/php7.1/lib/php/extensions/no-debug-non-zts-20160303
[root@localhost no-debug-non-zts-20160303]# rm -rf sqlite3.so

# After deletion, remember to upload the sqlite3.so file provided by me

[root@localhost no-debug-non-zts-20160303]# chmod 755 sqlite3.so 
[root@localhost no-debug-non-zts-20160303]# ll
total 27044
-rwxr-xr-x 1 root root  3618150 Nov 26  2018 fileinfo.so
-rwxr-xr-x 1 root root  1375702 May 12  2019 mysqli.a
-rwxr-xr-x 1 root root   649400 May 12  2019 mysqli.so
-rwxr-xr-x 1 root root  3419404 Jun 18 14:59 opcache.a
-rwxr-xr-x 1 root root  1635776 Jun 18 14:59 opcache.so
-rwxr-xr-x 1 root root   124455 Nov 20  2018 pdo_dblib.so
-rwxr-xr-x 1 root root   497966 Nov  6  2018 pdo_mysql.a
-rwxr-xr-x 1 root root   229814 Nov  6  2018 pdo_mysql.so
-rwxr-xr-x 1 root root   348013 Nov 19  2018 pdo_sqlsrv.so
-rwxr-xr-x 1 root root   466649 Jun 13  2019 rdkafka.so
-rwxr-xr-x 1 root root  2379481 May 13  2019 redis.so
-rwxr-xr-x 1 root root   855199 Sep 17  2019 sqlite3.so
-rwxr-xr-x 1 root root 10758700 May 10  2019 swoole.so
-rwxr-xr-x 1 root root  1311591 Nov 20  2018 xdebug.so
[root@localhost no-debug-non-zts-20160303]# 

  1. modify php.ini Open sqlite3.so extension
[root@localhost no-debug-non-zts-20160303]# vim /etc/php7.1.6/php.ini
extension=sqlite3.so
  1. Restart php7.1-fpm
[root@localhost no-debug-non-zts-20160303]# service php7.1-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done

So far, you can write code to connect the encrypted sqlite library

sqlite.so File address

Link: https://pan.baidu.com/s/1zE3i_Dh2Z2ew_IaptSfjBg 
Extraction code: wbxt

If you have any questions, you can ask questions in the comment area, see the reply, reprint please indicate the source

Tags: Programming PHP MySQL SQLite PDO

Posted on Thu, 18 Jun 2020 05:05:33 -0400 by Pigmaster