msqli和mssql的问题以及linux上损坏的php7.2



我在ubuntu18.04.1上使用了一个带有laravel 5.5的本地应用程序。它托管在一台使用php7.2的服务器上,我的系统中也有相同版本的php。一切都很顺利。昨天,我试图将我的应用程序与SQL Server连接,以从数据库中获取数据,我的噩梦开始了。

我按照以下格式将数据库连接信息添加到我的laravel应用程序中的database.php文件中

'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
],

一切似乎都很好,但当我试图检索数据时,我遇到了一个连接异常,laravel告诉我没有找到sqlsrv驱动程序。我想,也许sqlsrv扩展没有启用,所以我去php.ini激活它,但我没有找到它,所以我开始调查,我发现我必须从微软网页安装它。我尝试了各种方法来添加正确的.所以,我安装并卸载了php7.2,我也不知道php7.4文件夹和模块在我的系统上是如何的。我关注这个网站(西班牙语)安装了一个docker,并试图防止将来出现这种情况。我一直遵循它,直到$ sudo docker-compose up -d nginx mysql phpmyadmin部分,然后我尝试运行我的应用程序,它正常工作,它正确连接,但我无法通过http://localhost:3030/访问phpmyadmin,我有phpmyadmin错误,因为它找不到mysqli扩展。

然后我厌倦了像以前一样运行php -S,当我试图连接到phpMyAdmin时,我得到了这个

$ php -S localhost:3030
[Thu Dec 10 13:17:50 2020] PHP Warning:  PHP Startup: Unable to load dynamic library 'mysqli' (tried: /usr/lib/php/20170718/mysqli (/usr/lib/php/20170718/mysqli: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/mysqli.so (/usr/lib/php/20170718/mysqli.so: undefined symbol: mysqlnd_global_stats)) in Unknown on line 0
[Thu Dec 10 13:17:50 2020] PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: /usr/lib/php/20170718/pdo_mysql (/usr/lib/php/20170718/pdo_mysql: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pdo_mysql.so (/usr/lib/php/20170718/pdo_mysql.so: undefined symbol: mysqlnd_allocator)) in Unknown on line 0
[Thu Dec 10 13:17:50 2020] PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_sqlite' (tried: /usr/lib/php/20170718/pdo_sqlite (/usr/lib/php/20170718/pdo_sqlite: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pdo_sqlite.so (/usr/lib/php/20170718/pdo_sqlite.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[Thu Dec 10 13:17:50 2020] PHP Warning:  PHP Startup: Unable to load dynamic library 'pgsql' (tried: /usr/lib/php/20170718/pgsql (/usr/lib/php/20170718/pgsql: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pgsql.so (/usr/lib/php/20170718/pgsql.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[Thu Dec 10 13:17:50 2020] Failed to listen on localhost:3030 (reason: Address already in use)

我运行了php --ini来查找配置文件的位置,并编辑了mysqli的扩展名以启用它,现在当我再次运行php --ini时,我收到了警告

$ php --ini
PHP Warning:  PHP Startup: Unable to load dynamic library 'mysqli' (tried: /usr/lib/php/20170718/mysqli (/usr/lib/php/20170718/mysqli: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/mysqli.so (/usr/lib/php/20170718/mysqli.so: undefined symbol: mysqlnd_global_stats)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: /usr/lib/php/20170718/pdo_mysql (/usr/lib/php/20170718/pdo_mysql: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pdo_mysql.so (/usr/lib/php/20170718/pdo_mysql.so: undefined symbol: mysqlnd_allocator)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_sqlite' (tried: /usr/lib/php/20170718/pdo_sqlite (/usr/lib/php/20170718/pdo_sqlite: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pdo_sqlite.so (/usr/lib/php/20170718/pdo_sqlite.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pgsql' (tried: /usr/lib/php/20170718/pgsql (/usr/lib/php/20170718/pgsql: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pgsql.so (/usr/lib/php/20170718/pgsql.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Configuration File (php.ini) Path: /etc/php/7.2/cli
Loaded Configuration File:         /etc/php/7.2/cli/php.ini
Scan for additional .ini files in: /etc/php/7.2/cli/conf.d
Additional .ini files parsed:      /etc/php/7.2/cli/conf.d/10-mysqlnd.ini,
/etc/php/7.2/cli/conf.d/10-opcache.ini,
/etc/php/7.2/cli/conf.d/10-pdo.ini,
/etc/php/7.2/cli/conf.d/20-calendar.ini,
/etc/php/7.2/cli/conf.d/20-ctype.ini,
/etc/php/7.2/cli/conf.d/20-exif.ini,
/etc/php/7.2/cli/conf.d/20-fileinfo.ini,
/etc/php/7.2/cli/conf.d/20-ftp.ini,
/etc/php/7.2/cli/conf.d/20-gettext.ini,
/etc/php/7.2/cli/conf.d/20-iconv.ini,
/etc/php/7.2/cli/conf.d/20-json.ini,
/etc/php/7.2/cli/conf.d/20-mysqli.ini,
/etc/php/7.2/cli/conf.d/20-pdo_mysql.ini,
/etc/php/7.2/cli/conf.d/20-phar.ini,
/etc/php/7.2/cli/conf.d/20-posix.ini,
/etc/php/7.2/cli/conf.d/20-readline.ini,
/etc/php/7.2/cli/conf.d/20-shmop.ini,
/etc/php/7.2/cli/conf.d/20-sockets.ini,
/etc/php/7.2/cli/conf.d/20-sysvmsg.ini,
/etc/php/7.2/cli/conf.d/20-sysvsem.ini,
/etc/php/7.2/cli/conf.d/20-sysvshm.ini,
/etc/php/7.2/cli/conf.d/20-tokenizer.ini

我仍然无法访问phpMyAdmin。当我运行php --version时,我得到了这个

$ php --version
PHP Warning:  PHP Startup: Unable to load dynamic library 'mysqli' (tried: /usr/lib/php/20170718/mysqli (/usr/lib/php/20170718/mysqli: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/mysqli.so (/usr/lib/php/20170718/mysqli.so: undefined symbol: mysqlnd_global_stats)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: /usr/lib/php/20170718/pdo_mysql (/usr/lib/php/20170718/pdo_mysql: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pdo_mysql.so (/usr/lib/php/20170718/pdo_mysql.so: undefined symbol: mysqlnd_allocator)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_sqlite' (tried: /usr/lib/php/20170718/pdo_sqlite (/usr/lib/php/20170718/pdo_sqlite: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pdo_sqlite.so (/usr/lib/php/20170718/pdo_sqlite.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pgsql' (tried: /usr/lib/php/20170718/pgsql (/usr/lib/php/20170718/pgsql: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pgsql.so (/usr/lib/php/20170718/pgsql.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP 7.2.34-8+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Oct 31 2020 16:57:15) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.34-8+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

我需要尽快修复这个问题,以便继续处理我的laravel应用程序。完成后,我需要一种正确的方式来安装正确的sqlsrv驱动程序,以便能够将我的laravil应用程序连接到sql server数据库。

当我运行php -m时,我得到了这个

$ php -m
PHP Warning:  PHP Startup: Unable to load dynamic library 'mysqli' (tried: /usr/lib/php/20170718/mysqli (/usr/lib/php/20170718/mysqli: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/mysqli.so (/usr/lib/php/20170718/mysqli.so: undefined symbol: mysqlnd_global_stats)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: /usr/lib/php/20170718/pdo_mysql (/usr/lib/php/20170718/pdo_mysql: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pdo_mysql.so (/usr/lib/php/20170718/pdo_mysql.so: undefined symbol: mysqlnd_allocator)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_sqlite' (tried: /usr/lib/php/20170718/pdo_sqlite (/usr/lib/php/20170718/pdo_sqlite: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pdo_sqlite.so (/usr/lib/php/20170718/pdo_sqlite.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pgsql' (tried: /usr/lib/php/20170718/pgsql (/usr/lib/php/20170718/pgsql: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pgsql.so (/usr/lib/php/20170718/pgsql.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[PHP Modules]
calendar
Core
ctype
date
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
libxml
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
Phar
posix
readline
Reflection
session
shmop
sockets
sodium
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
Zend OPcache
zlib
[Zend Modules]
Zend OPcache

这就是我现在用php、nginx和sql安装的

$ dpkg --get-selections | grep php
libapache2-mod-php7.2                           install
php-common                                      install
php-mysql                                       install
php7.2                                          install
php7.2-cli                                      install
php7.2-common                                   install
php7.2-fpm                                      install
php7.2-json                                     install
php7.2-mysql                                    install
php7.2-opcache                                  install
php7.2-readline                                 install
php7.4-common                                   install
php7.4-mysql   
$ dpkg --get-selections | grep nginx
libnginx-mod-http-geoip                         install
libnginx-mod-http-image-filter                  install
libnginx-mod-http-xslt-filter                   install
libnginx-mod-mail                               install
libnginx-mod-stream                             install
nginx                                           install
nginx-common                                    install
nginx-core                                      install
$ dpkg --get-selections | grep sql
akonadi-backend-mysql                           install
libaprutil1-dbd-sqlite3:amd64                   install
libmono-sqlite4.0-cil                           install
libmysqlclient20:amd64                          install
libmysqlcppconn7v5:amd64                        install
libqt4-sql:amd64                                install
libqt4-sql-mysql:amd64                          install
libqt5sql5:amd64                                install
libqt5sql5-mysql:amd64                          install
libqt5sql5-sqlite:amd64                         install
libsqlite3-0:amd64                              install
libvsqlitepp3v5:amd64                           install
msodbcsql17                                     install
mssql-server                                    install
mssql-tools                                     install
mysql-client                                    install
mysql-client-5.7                                install
mysql-client-core-5.7                           install
mysql-common                                    install
mysql-server                                    install
mysql-server-5.7                                install
mysql-server-core-5.7                           install
mysql-utilities                                 install
mysql-workbench                                 install
mysql-workbench-data                            install
php-mysql                                       install
php7.2-mysql                                    install
php7.4-mysql                                    install
postgresql                                      install
postgresql-10                                   install
postgresql-client-10                            install
postgresql-client-common                        install
postgresql-common                               install
postgresql-contrib                              install
python-mysql.connector                          install
python-pysqlite2                                install

有人知道我能做什么吗?

如果你需要更多信息,请在评论中告诉我,我会更新问题。

谢谢!

更新1:还没有任何工作

我试图按照这个线程卸载所有的php和php7文件,并试图重新安装php7.2,但当我执行add-apt-repository ppa:ondrej/php时,我无法添加存储库,因为终端向我抛出了这个

Obj:1 https://download.docker.com/linux/ubuntu bionic InRelease
Ign:2 http://ppa.launchpad.net/langdalepl/gvfs-mtp/ubuntu bionic InRelease                                                                                                           
Obj:3 https://linux.teamviewer.com/deb stable InRelease                                                                                                                              
Obj:4 http://ppa.launchpad.net/ondrej/php/ubuntu bionic InRelease                                                                                                                    
Obj:5 http://dl.google.com/linux/chrome/deb stable InRelease                                                                                                                         
Obj:6 http://ppa.launchpad.net/wireshark-dev/stable/ubuntu bionic InRelease                                                                                                          
Obj:7 http://es.archive.ubuntu.com/ubuntu bionic InRelease                                                                                                                           
Des:8 http://security.ubuntu.com/ubuntu bionic-security InRelease [88,7 kB]                                                                                                          
Des:9 http://archive.neon.kde.org/user bionic InRelease [131 kB]                                                                                                                     
Obj:10 https://packages.microsoft.com/ubuntu/18.04/mssql-server-2019 bionic InRelease                                                                                                
Err:11 http://ppa.launchpad.net/langdalepl/gvfs-mtp/ubuntu bionic Release                                                                                                            
404  Not Found [IP: 91.189.95.83 80]
Ign:12 https://storage.googleapis.com/download.dartlang.org/linux/debian stable InRelease                                                                                   
Obj:13 https://packages.microsoft.com/ubuntu/18.04/prod bionic InRelease                                                                                                    
Des:14 http://es.archive.ubuntu.com/ubuntu bionic-updates InRelease [88,7 kB]                                                                                                
Obj:15 https://packages.microsoft.com/ubuntu/16.04/prod xenial InRelease                                                                                                             
Obj:16 https://storage.googleapis.com/download.dartlang.org/linux/debian stable Release                                                                                              
Des:17 http://es.archive.ubuntu.com/ubuntu bionic-backports InRelease [74,6 kB]
E: The repository 'http://ppa.launchpad.net/gnome-shell-extensions/ppa/ubuntu bionic Release' does not have a Release file. 
N: Updating from such a repository can't be done securely, and is therefore disabled by default. 
N: See apt-secure(8) manpage for repository creation and user configuration details.

我搜索了我的错误并找到了这个,但它对我不起作用。

我试着按照线程安装php7.2,一切都很顺利,但当我执行sudo service apache2 restart时,我得到了这个

Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.

所以我执行了systemctl status apache2.service,它抛出了这个

apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: failed (Result: exit-code) since Fri 2020-12-11 10:34:22 CET; 1min 31s ago
Process: 4671 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
dic 11 10:34:22 Dev-PC apachectl[4671]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directiv
dic 11 10:34:22 Dev-PC apachectl[4671]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
dic 11 10:34:22 Dev-PC apachectl[4671]: (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
dic 11 10:34:22 Dev-PC apachectl[4671]: no listening sockets available, shutting down
dic 11 10:34:22 Dev-PC apachectl[4671]: AH00015: Unable to open logs
dic 11 10:34:22 Dev-PC apachectl[4671]: Action 'start' failed.
dic 11 10:34:22 Dev-PC apachectl[4671]: The Apache error log may have more information.
dic 11 10:34:22 Dev-PC systemd[1]: apache2.service: Control process exited, code=exited status=1
dic 11 10:34:22 Dev-PC systemd[1]: apache2.service: Failed with result 'exit-code'.
dic 11 10:34:22 Dev-PC systemd[1]: Failed to start The Apache HTTP Server.

我现在能做什么?我无法启动apache服务,也不知道这里出了什么问题。。。

更新2:我的应用程序和apache2现在正在工作

我更新了我的下载管理器,以查找可用的存储库和宾果游戏,ondrej存储库被锁定,我只是解锁了它们,并再次尝试添加存储库,现在它起作用了。我已经使用和php7.2重新安装了apache2,运行sudo apt-get install apache2并遵循线程答案。但我也遇到了同样的问题,所以我意识到这个错误显示了两个问题,第一个问题是缺少服务器名称,第二个问题是端口80正在使用,这就是为什么apache2在尝试启动时一直失败的原因。为了解决第一个问题,我运行了sudo gedit /etc/apache2/apache2.conf并添加了Server Name 127.0.0.1,保存后,第一个问题解决了,我解决了运行sudo lsof -i -n -P | grep ':80'的第二个问题,发现nginx进程正在使用它,所以我用sudo kill [the nginx PID]杀死了nginx过程,并重试启动apache2,现在它工作了。我可以在phpmyadmin中访问我的数据库,但现在我遇到了另一个问题,当我在laravel项目中执行php artisan serve时,我得到了一个PDOConnection.php错误,因为缺少一个驱动程序,在执行php -m后,我意识到那是mysql驱动程序,所以我运行了sudo apt-get install php7.2-common php7.2-mysql php7.2-cli,最后我修复了我的apache2和php7.2!最后感谢大家对我的帮助!

但现在我遇到了与这一切开始时相同的问题,我需要以正确的方式安装sqlsrv.so驱动程序,以便能够将我的laravel应用程序与SQL Server数据库连接起来。我试图从微软页面下载.so文件,但这让我陷入了噩梦,所以有人知道我如何继续正确安装sqlsrv驱动程序吗?

更新3:终于解决了

为了寻找解决方案,我再次查看了微软的网页,以找出我需要哪些sqlsrv驱动程序来运行php7.2的sql查询,我再次尝试运行sudo pecl install sqlsrvsudo pecl install pdo_sqlsrv,但对我来说不起作用。然后我找到了另一种方法来安装没有pecl的驱动程序,我运行了sudo apt-get install php7.2-dev,并下载了带有wget http://pecl.php.net/get/sqlsrv-5.3.0.tgzwget http://pecl.php.net/get/pdo_sqlsrv-5.3.0.tgz的包(5.3.0是我的php7.2 sqlsrv版本),在此之后,我安装了pear install pdo_sqlsrv-5.3.0.tgzpear install sqlsrv-5.3.0.tgz。这一次它对我有效(第一次它向我抛出一个错误,告诉我有一个安装的pdo_sqlsrv版本,但我运行了sudo pear uninstall pecl/pdo_sqlsrv并再次运行了安装顺序,然后它对我有用)。然后,我再次尝试运行sudo pecl install sqlsrvsudo pecl install pdo_sqlsrv,这次成功了!之后,我运行了sudo phpenmod -v 7.2 sqlsrv pdo_sqlsrv,最终在我的ubuntu中完成了php7.2 sqlsrv驱动程序的安装!我尝试再次在sql server上运行与数据库的连接,结果成功了。

谢谢你的帮助!

我用解决自己问题的进度更新了我的帖子,在帖子评论中的bhucho的帮助下,我修复了我的php7.2。

为了寻找为我的php版本安装正确的sqlsrv驱动程序的解决方案,我再次查看了微软网页,以找出我需要哪些sqlsrv驱动器来使用php7.2运行sql查询,我再次尝试运行sudo pecl install sqlsrvsudo pecl install pdo_sqlsrv,但对我来说不起作用。然后我找到了另一种方法来安装没有pecl的驱动程序,我运行了sudo apt-get install php7.2-dev并下载了带有wget http://pecl.php.net/get/sqlsrv-5.3.0.tgzwget http://pecl.php.net/get/pdo_sqlsrv-5.3.0.tgz的包(5.3.0是我的php7.2的sqlsrv版本),之后我安装了pear install pdo_sqlsrv-5.3.0.tgzpear install sqlsrv-5.3.0.tgz。这一次它对我有效(第一次它向我抛出一个错误,告诉我有一个安装的pdo_sqlsrv版本,但我运行了sudo pear uninstall pecl/pdo_sqlsrv并再次运行了安装顺序,然后它对我有用)。然后,我再次尝试运行sudo pecl install sqlsrvsudo pecl install pdo_sqlsrv,这次成功了!之后,我运行了sudo phpenmod -v 7.2 sqlsrv pdo_sqlsrv,最后在我的ubuntu中完成了php7.2 sqlsrv驱动程序的安装!我尝试再次在sql server上运行与数据库的连接,结果成功了。

谢谢大家的帮助!

最新更新