簡體   English   中英

linux 上 msqli 和 mssql 的問題以及損壞的 php7.2

[英]Problems with msqli and mssql and broken php7.2 on linux

我有一個 laravel 5.5 的本地應用程序,在我的 ubuntu18.04.1 上使用 mysql 數據庫。 它托管在使用 php7.2 的服務器上,我的系統中有相同版本的 php。 一切正常。 昨天,我嘗試將我的應用程序與 SQL 服務器連接以從數據庫中獲取數據,我的噩夢開始了。

我在我的 laravel 應用程序中添加了數據庫連接信息到數據庫中。

 '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激活它,但沒有找到,於是開始調查,發現必須從microsoft安裝網頁。 我嘗試了各種方式來添加正確的.so,我安裝和卸載了 php7.2,我也不知道 php7.4 文件夾和模塊在我的系統上是如何的。 我跟着這個站點(西班牙語)安裝了一個 docker 並試圖防止將來出現這種情況。 I followed it till the $ sudo docker-compose up -d nginx mysql phpmyadmin part, then I tried to run my app and it works, it connects properly, but I cannot access to phpmyadmin via http://localhost:3030/ , I have 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 驅動程序,以便能夠將我的 laravel 應用程序連接到 ZAC5C74B64B4AFFBB832AZEF2FAC18 服務器數據庫。

當我運行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 存儲庫被鎖定,我剛剛解鎖它們並再次嘗試添加存儲庫,它現在可以工作了。 我已經重新安裝了 apache2 和 php7.2 運行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'解決了第二個問題 sudo lsof -i -n -P | grep ':80' and I discovering that nginx process was using it, so I used sudo kill [the nginx PID] to kill the nginx processes and retried to start apache2 and now it worked. I was able to access to my database in phpmyadmin but now I had another problem, when I execute php artisan serve in my laravel project, I got a PDOConnection.php error because there was a missing driver, and after execute php -m I realized那是 mysql 驅動程序,所以我運行了sudo apt-get install php7.2-common php7.2-mysql php7.2-cli ,最后我的 apache2 和我的 php7.2 修復了! 最后感謝大家對我的幫助!

但是現在我遇到了與這一切開始時相同的問題,我需要以正確的方式安裝 sqlsrv.so 驅動程序,以便能夠將我的 laravel 應用程序與 SQL 服務器數據庫連接起來。 我試圖從 microsoft 頁面下載.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.tgz下載了軟件包和wget 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 服務器上再次運行與我的數據庫的連接,它工作正常。

謝謝您的幫助!

我更新了我的帖子,解決了我自己的問題,在我帖子評論中的 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.tgz下載了軟件包和wget 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 服務器上再次運行與我的數據庫的連接,它工作正常。

謝謝大家的幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM