19

I am having trouble enabling mysql in my php-config.

apt-get install php-mysql and apt-get install php7.0-mysql don't make a difference.

Also, the shared object is missing from the php extension directory.

Is there any way I could get the mysql.so?

troylatroy
  • 1,275
  • 1
  • 11
  • 21
  • if your using php7, the php7.0-mysql version should be used only. Remove the other and see if it improves. – George Udosen Dec 07 '16 at 20:38
  • In ubuntu 16.10 : /usr/lib/php/20151012/mysqli.so is provided by php7.0-mysql package. Check /etc/php/7.0/apache2/conf.d/20-mysqli.ini, you should have : extension=mysqli.so – f35 Dec 07 '16 at 21:50

6 Answers6

26

On Ubuntu, I fixed this error by running

sudo apt-get install php-mysql

And then restarting my server (caddy, apache, nginx).

source

ki9
  • 522
  • Couldn't get this to work on PHP7.1, Ubuntu 16.04 (mysql was still missing) – The Onin Aug 15 '17 at 00:11
  • 1
    The error I got, which this information helped me fix: "PHP is missing the MYSQL EXTENSION that WordPress needs". – givonz Nov 07 '17 at 17:20
  • On Ubuntu 16.04 I had to force it to use php7.0-mysql even though I'm actually using php 7.3 (Wordress version 5.2) – Dagmar May 19 '19 at 10:28
5

I'd assume you're talking about the (very) old style MySQL functions in PHP like mysql_connect() or mysql_query(). Those functions have been deprecated for years and years, and have finally been removed in PHP 7. Use the mysqli extension or one of vendor-independent abstraction layers like PDO instead.

2

I had this exact question but related to a very specific version of Ubuntu on a Docker image. The trick was to update and install in the same RUN command.

RUN apt-get update && apt-get install php7.0-mysql
Kevin Bowen
  • 19,615
  • 55
  • 79
  • 83
0

mysql extension was removed in PHP 7.

You should use mysqli or pdo_mysql instead.

If you still need to use mysql functions (eg. for legacy code support), you may compile the mysql extension manually.

Here's the procedure: https://ckon.wordpress.com/2015/08/06/put-mysql-functions-back-into-php-7/

takeshin
  • 2,852
0

mysqli.so is indeed flagged missing and seemingly NOT installed in 18.04. It appears to me the packages are broken because there is a php-mysqli and it is not installed while php-mysql is.

I was not able to install the php-mysqli package otherwise and it throws no errors in apt when I try, it just doesn't install anything.

However, I found mysqli.so in /var/lib/php/modules/7.2/cgi/enabled_by_admin/.

Add extension=/path/here/to/mysqli.so under your extension=mysqli in php.ini and you should stop throwing the mysqli.so missing error.

IMHO these packages are borked and it isn't entirely clear what provides mysqli.so, and won't work out of the box unless you enable the extension and set your path for the extension once you find it (you can use dpkg-query -L to see if mysqli.so is part of the package contents, and where it gets installed)

-3

If I understand correctly, installing LAMP stack should fix your issue. Try this guide

https://www.unixmen.com/how-to-install-lamp-stack-on-ubuntu-16-04/

user227495
  • 4,089
  • 17
  • 56
  • 101