Environment:os and apache and php and mariadb version.
uname -a
Linux MiWiFi-R3-srv 4.9.0-11-amd64 #1 SMP Debian 4.9.189-3+deb9u2 (2019-11-11) x86_64 GNU/Linux
sudo apachectl -v
Server version: Apache/2.4.25 (Debian)
Server built: 2019-10-13T15:43:54
php -v
PHP 7.0.33-0+deb9u6 (cli) (built: Oct 24 2019 18:50:20) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.33-0+deb9u6, Copyright (c) 1999-2017, by Zend Technologies
Login mariadb with password and input status
:
Server: MariaDB
Server version: 10.1.41-MariaDB-0+deb9u1 Debian 9.9
Check php-mysql:
sudo dpkg -l php-mysql
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-============-============-=================================
ii php-mysql 1:7.0+49 all MySQL module for PHP [default]
Get the mysql.so library:
sudo find / -name "*mysql.so"
/usr/lib/php/20151012/pdo_mysql.so
Chekc all modules which contain mysql:
php -m |grep mysql
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/php_pdo_mysql.so' - /usr/lib/php/20151012/php_pdo_mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0
mysqli
mysqlnd
pdo_mysql
sudo vim /etc/php/7.0/fpm/php.ini
Rewrite
; ... or under UNIX:
;
;extension=mysql.so
as
extension=mysqli.so
or
extension=mysqlnd.so
or
extension=pdo_mysql.so
Restart apache2 and mariadb database,the issue remains ,none of the three format can work,how to fix then?
6
Answers
Remove php and related packages.
Check.
Install.
At last my issue solved.
pdo_mysql
is not the same asmysql.so
. The oldmysql
extension was removed in PHP 7.0. The supported extension is now onlymysqli
.From there on it depends on what the software is expecting to find – if it needs the old
mysql
library, then you’re going to have to use a shim or an older PHP version (i.e. anything before PHP 7, such as PHP 5.6).You can use the
php7-mysql-shim
library or themysql-shim
library (be aware, this might incur a small performance penalty) to make a transparent mapping available that dispatches any calls to the oldmysql
library to the still supportedmysqli
library. As long as you’ve installedphp7-mysql-shim
through composer and your project uses composer, it should be loaded automagically.A third option is to run the original code through the
mysql-to-mysqli
rector configuration, but if this is not your own code, that will be hard to maintain in the future.The
.so
file that can’t be loaded might be because of permission issue. Make sure tols -al
that file and correct any ownership or permission issues (chmod og+r <filename>
, probably).MatsLindh is right, mysql is deprecated from php 7, it seems that you have deployed old php5 code on the server that is why you received this error, now you can do two things
Rector Tool for upgrading php legacy code
We were down the same path in previous months and and we updated mysql code to mysqli and also updated the classes declarations and added the necessary checking, fixed the error handling and we were able to run the legacy app on the php 7 successfully.
Sometime due to complicated development, it is not possible to upgrade in an instant and it is also not possible to start from the scratch either because of the business logic introduced over the years so changes can only be introduced with baby steps, I can say this because we handle our high traffic ecommerce site.
As others have stated, though without a source, the mysql extension (ext/mysql) was deprecated in 5.5 (per RFC: ext/mysql deprecation) and removed in 7.0 (per RFC: Remove deprecated functionality in PHP 7).
(This is the git commit that actually removed ext/mysql from PHP, as linked to from the removal RFC – this link was added by the RFC author [nikic])
This is also mentioned all throughout the ext/mysql manual on php.net, though it doesn’t link to any other notes concerning the deprecation and subsequent removal.
If you view the backwards-incompatible changes page for 7.0 then it further mentions that all mysql extension functions were removed, and provides a link to help in choosing a new MySQL API. This provides the support and path necessary for moving on from ext/mysql.
Avoid using a quick fix that will make your application support the old
php-mysql
driver. There is a reason that it was removed fromphp
.You can use the successor of
php-mysql
which is theMySQLi
driver, the nameMySQLi
actually meansMySQL-improved
and as you can understand is an improved version of theMySQL
driver that gives the developer more benefits.You may also use the PHP Data Objects (PDO), an extension that defines a lightweight, consistent interface for accessing databases (MySQL is one of them) in
PHP
.This would mean that you would have to re-write pieces of code related with database handled information. If you wrote a class for it then you only need to re-write that class only. If all the
MySQL
related functions are written in all your application then you have a lot of work.Do some further reading of your own to judge for yourself what would be the best practice for this situation, MySQLi Wiki, Introduction to PDO, MySQLi Overview.
The First thing that you need to check for this issue is PHP version compatibility with the existing CMS Version.
In most of the cases the error due to that only.
If you are using the domain hosting and have a various site in that, you can also switch the PHP version in one sub domain only by this Htaccess file.
Like this – FcgidWrapper "/home/httpd/cgi-bin/php53-fcgi-starter.fcgi" .php
Thnak you!