Linux 解决mysql函数无法连数据库的问题

==----------------------------------------------------------------------------------------------------------------------
-----== Linux 解决mysql函数无法连数据库的问题  参考:https://www.imooc.com/article/39504  【成功!!!!!】

1、进入源码包目录
cd /fitness/software/php-5.6.36/php-5.6.36/ext/mysql

[root@iZ8vb2uz59jd5pisp87ljjZ mysql]# pwd
/fitness/software/php-5.6.36/php-5.6.36/ext/mysql
[root@iZ8vb2uz59jd5pisp87ljjZ mysql]# ls
config.m4   CREDITS    mysql.mak        package.xml  php_mysql.h   php_mysql.o          tests
config.w32  mysql.dsp  mysql_mysqlnd.h  php_mysql.c  php_mysql.lo  php_mysql_structs.h


2、查看phpize是否存在
cd /fitness/serve/php/bin

[root@iZ8vb2uz59jd5pisp87ljjZ bin]# pwd
/fitness/serve/php/bin
[root@iZ8vb2uz59jd5pisp87ljjZ bin]# ls
pear  peardev  pecl  phar  phar.phar  php  php-cgi  php-config  phpize

3、在/fitness/software/php-5.6.36/php-5.6.36/ext/mysql运行phpize
即:
cd /fitness/software/php-5.6.36/php-5.6.36/ext/mysql
/fitness/serve/php/bin/phpize

结果:
[root@iZ8vb2uz59jd5pisp87ljjZ mysql]# /fitness/serve/php/bin/phpize
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

[root@iZ8vb2uz59jd5pisp87ljjZ mysql]# ls
acinclude.m4  config.m4     CREDITS          missing        mysql_mysqlnd.h  php_mysql.lo         tests
aclocal.m4    config.sub    install-sh       mkinstalldirs  package.xml      php_mysql.o
build         configure.in  ltmain.sh        mysql.dsp      php_mysql.c      php_mysql_structs.h
config.guess  config.w32    Makefile.global  mysql.mak      php_mysql.h      run-tests.php

我们发现没有configure这个文件,再看上,有个报错:
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

解决:
yum install autoconf

再次运行/fitness/serve/php/bin/phpize

[root@iZ8vb2uz59jd5pisp87ljjZ mysql]# /fitness/serve/php/bin/phpize
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226

没有报错了,查看
[root@iZ8vb2uz59jd5pisp87ljjZ mysql]# ls
acinclude.m4    config.guess  configure     install-sh       mkinstalldirs    package.xml   php_mysql.o
aclocal.m4      config.h.in   configure.in  ltmain.sh        mysql.dsp        php_mysql.c   php_mysql_structs.h
autom4te.cache  config.m4     config.w32    Makefile.global  mysql.mak        php_mysql.h   run-tests.php
build           config.sub    CREDITS       missing          mysql_mysqlnd.h  php_mysql.lo  tests

终于发现了configure文件!!!

4、运行configure,这时注意,要指明php-config文件的位置

[root@iZ8vb2uz59jd5pisp87ljjZ bin]# pwd
/fitness/serve/php/bin
[root@iZ8vb2uz59jd5pisp87ljjZ bin]# ls
pear  peardev  pecl  phar  phar.phar  php  php-cgi  php-config  phpize

./configure --with-php-config=/fitness/serve/php/bin/php-config --with-pdo-mysql=mysqlnd

结果:
[root@iZ8vb2uz59jd5pisp87ljjZ mysql]# ./configure --with-php-config=/fitness/serve/php/bin/php-config --with-pdo-mysql=mysqlnd
configure: WARNING: unrecognized options: --with-pdo-mysql
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/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... /fitness/serve/php
checking for PHP includes... -I/fitness/serve/php/include/php -I/fitness/serve/php/include/php/main -I/fitness/serve/php/include/php/TSRM -I/fitness/serve/php/include/php/Zend -I/fitness/serve/php/include/php/ext -I/fitness/serve/php/include/php/ext/date/lib
checking for PHP extension directory... /fitness/serve/php/lib/php/extensions/no-debug-non-zts-20131226
checking for PHP installed headers prefix... /fitness/serve/php/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking for MySQL support... yes, shared
checking for specified location of the MySQL UNIX socket... no
checking for the location of libz... no
checking for MySQL UNIX socket location... /tmp/mysql.sock
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/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 /usr/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 (/usr/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 ld.so
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
configure: WARNING: unrecognized options: --with-pdo-mysql

5、编译安装,生成mysql.so文件
make && make install

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
configure: WARNING: unrecognized options: --with-pdo-mysql
[root@iZ8vb2uz59jd5pisp87ljjZ mysql]# make && make install
/bin/sh /fitness/software/php-5.6.36/php-5.6.36/ext/mysql/libtool --mode=link cc -DPHP_ATOM_INC -I/fitness/software/php-5.6.36/php-5.6.36/ext/mysql/include -I/fitness/software/php-5.6.36/php-5.6.36/ext/mysql/main -I/fitness/software/php-5.6.36/php-5.6.36/ext/mysql -I/fitness/serve/php/include/php -I/fitness/serve/php/include/php/main -I/fitness/serve/php/include/php/TSRM -I/fitness/serve/php/include/php/Zend -I/fitness/serve/php/include/php/ext -I/fitness/serve/php/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -o mysql.la -export-dynamic -avoid-version -prefer-pic -module -rpath /fitness/software/php-5.6.36/php-5.6.36/ext/mysql/modules  php_mysql.lo
cc -shared  .libs/php_mysql.o   -Wl,-soname -Wl,mysql.so -o .libs/mysql.so
creating mysql.la
(cd .libs && rm -f mysql.la && ln -s ../mysql.la mysql.la)
/bin/sh /fitness/software/php-5.6.36/php-5.6.36/ext/mysql/libtool --mode=install cp ./mysql.la /fitness/software/php-5.6.36/php-5.6.36/ext/mysql/modules
cp ./.libs/mysql.so /fitness/software/php-5.6.36/php-5.6.36/ext/mysql/modules/mysql.so
cp ./.libs/mysql.lai /fitness/software/php-5.6.36/php-5.6.36/ext/mysql/modules/mysql.la
PATH="$PATH:/sbin" ldconfig -n /fitness/software/php-5.6.36/php-5.6.36/ext/mysql/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /fitness/software/php-5.6.36/php-5.6.36/ext/mysql/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

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

Installing shared extensions:     /fitness/serve/php/lib/php/extensions/no-debug-non-zts-20131226/


6、修改php.ini文件,添加mysql.so扩展配置

extension=mysql.so


7、重启php-fpm
[8vb2uz59jd5pisp87ljjZ lib]# service php-fpm start
Starting php-fpm [03-Jul-2019 11:52:30] NOTICE: PHP message: PHP Warning:  PHP Startup: Invalid library (maybe not a PHP library) 'mysql.so' in Unknown on line 0
[03-Jul-2019 11:52:30] ERROR: unable to bind listening socket for address '127.0.0.1:9000': Address already in use (98)
[03-Jul-2019 11:52:30] ERROR: FPM initialization failed

杀死所有php-fpm
killall php-fpm

再启动
service php-fpm start

就没有报错了!


8、连接mysql,测试成功!!!

----------------------------------------------------------------------------------------------------------------------==
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值