I cannot find instructions about installing MySQLi on a Mac. Just to be clear, MySQL is up to date and I am running PHP 5. How do I install it? Where do I even get it from? Thanks for your help. I'll be giving an up vote and a check mark to whoever answers this!
16 Answers
Use php-mysqlnd
instead of php-mysql
. On Linux, to install with apt-get
type:
apt-get install php-mysqlnd

- 13,965
- 5
- 32
- 51

- 635
- 5
- 4
-
This helped a lot. I had php5-mysql and the page returned empty response whenever I tried to connect by mysqli. Even phpinfo was showing mysqli as loaded still there was an empty response message in Chrome and connection reset in Firefox. – Zeeshan Feb 02 '16 at 07:43
-
4When you use Docker with an outdated version of PHP, it turns out that apt-get is not the right way to install libraries for PHP modules: it gets new versions, no matter what version of PHP you're using. Luckily, there's a great utility called docker-php-ext-install - it allows to easily add required module libraries to your PHP installation. Hope this would help someone. – Konstantin Feb 18 '16 at 12:32
-
you present for php 5, for newer version should be `apt-get install php-mysqlnd` – João Pimentel Ferreira Dec 09 '17 at 12:50
-
5Why though? what's the difference between mysqlnd and mysqli? – Andreas Hartmann Apr 08 '18 at 12:45
-
1@AndreasHartmann This appears to be one of those "I used this obscure version because they optimized line XX" answers, but `Package 'php-mysqlnd' has no installation candidate` with a standard configuration, so I recommend using https://stackoverflow.com/a/37910795/461982 – Abandoned Cart Apr 08 '18 at 18:03
MySQLi is part of PHP. There should be a php-mysqli type package available, or you can take the PHP source and recompile that mysqli enabled. You may already have it installed, but it's done as a module and is disabled. Check your php.ini for extension=mysqli.so
or similar. it may be commented out, or the .so file is present in your extensions directory but not linked to PHP via that extension= directive.

- 356,200
- 43
- 426
- 500
-
3The name of the package that you need to download to make it work is _php5-mysql_. Normally, it will activate automatically the module after its installation, so you won't really need to modify the _php.ini_ file. – devrique Aug 18 '14 at 15:12
-
1i simply `yum install php-mysqli` then restarted apache (on centos 6.8 `service httpd restart`) and it worked. this was after overcoming the "mbstring" error which was similarly resolved with `yum install php-mbstring` – aequalsb Feb 11 '17 at 08:23
This is how I installed it on my Debian based machine (ubuntu):
php 7:
sudo apt-get install php7.0-mysqli
php 5:
sudo apt-get install php5-mysqli

- 18,551
- 8
- 57
- 87
-
2On an alpine docker image it is `apk add --update php-mysqli` if you need to manually install it. – luckydonald Mar 27 '17 at 09:31
-
-
@Shambhu [The answer below](https://stackoverflow.com/a/28463525/2873538) doesn't help? – Ajeet Shah Apr 20 '18 at 08:13
This article is clearly explained, how to install MySqli with EachApache. This works for me too.
To install mysqli using EachApache:
Login to WHM as 'root' user.
Either search for "EasyApache" or go to Software > EasyApache
Scroll down and select a build option (Previously Saved Config)
Click Start "Start customizing based on profile"
Select the version of Apache and click "Next Step".
Select the version of PHP and click "Next Step".
Chose additional options within the "Short Options List"
Select "Exhaustive Options List" and look for "MySQL Improved extension"
Click "Save and Build"

- 2,088
- 1
- 19
- 18
-
2Excellent answer for those who are using WHM, exactly what I needed. Thank you for posting! – rog Dec 20 '14 at 09:27
-
I can't see the Software > EasyApache on my dashboard. Where do I find it? – jofftiquez Jan 18 '16 at 06:46
-
-
-
Possible source: https://www.linuxquestions.org/questions/linux-newbie-8/install-mysqli-4175583372/ – Cadoiz May 20 '20 at 16:28
You are supposed to edit two lines in your php.ini file (i'm using windows for this example):
-The first one is regarding the extensions directory location. See below:
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "C:/php/ext"
-The second one is regarding the extension itself:
extension=php_mysqli.dll
Only modifying (uncommenting) the extension line was not enough for me. Hope it helps

- 329
- 5
- 8
-
4
-
1I'm on Windows and this is helpful, so I guess we can call that collateral help, thanks. Oh and thanks PHP for sensible default parameters, boy what a crap language. – Overdrivr Mar 28 '17 at 08:24
-
I've uncommented both the lines. Even then I'm getting error as `Call to undefined function mysqli_connect() ` what else I've to do here. pls help – Shambhu Apr 20 '18 at 08:11
Here is the link for installation details: http://php.net/manual/en/mysqli.installation.php
If you are using Windows or Linux:
- The MySQLi extension is automatically installed in most cases, when PHP & MySQL package is installed.

- 228
- 2
- 10
For Windows: 3 steps
Step1:
Just need to give the ext
folder path in php.ini
Here
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "C:\php7\ext"
Step 2: Remove the comment from
extension=php_mysqli.dll
Step 3: restart the Apache server.
Since you are using a Mac, open a terminal, and
- cd /etc
Find the php.ini, and sudo open it, for example, using the nano editor
- nano php.ini
Find use control+w to search for "mysqli.default_socket", and change the line to
- mysqli.default_socket = /tmp/mysql.sock
Use control+x and then hit "y" and "return" to save the file. Restart Aapche if necessary.
Now you should be able to run mysqli.

- 360
- 2
- 8
I recently ditched Xampp in favor of the native Apache on Mac Sierra because a new php requirement of a project. Sierra comes with php 5.6.25, but it doesn't run mysql_* out of the box, after a lot of googling, I found this site really help - https://php-osx.liip.ch. As it turns out php 5.6.25 does support mysql_* but wasn't enabled. Choose your version of php and download it, it generates a proper php.ini for your php, then you are good to go

- 121
- 1
- 2
- 7
sudo apt-get -y -f install php7.0-mysql

- 1,515
- 21
- 29
-
it worked! but I am very confusion that I want to install **mysqli** extension and so I search *mysqli.so* all day. I have never think that this problem will be solved through install *php7.0-mysql*. So what the relation between mysqli and php7.0-mysql and why you have this idea that install *php7.0-mysql*. – nail fei Jul 25 '18 at 16:22
if you use ubuntu 16.04 (maybe and above) just do this
sudo phpenmod mysqli
sudo service php7.0-fpm restart

- 4,444
- 5
- 44
- 57
Since many of these answers are old here is how to install mysqli for Easyapache 4.
If you try and search for mysqli under your PHP extensions in WHM you are not going to find it. The way to know which extension you need to install mysqli you will need to run this command in terminal
repoquery -q --whatprovides 'ea-php70-php-mysqli' | sort -V | tail -1
Should return something like
ea-php70-php-mysqlnd-0:7.0.33-1.1.4.cpanel.x86_64
All you really need from this is mysqlnd copy it
To install mysqli using EachApache4:
- Login to WHM.
- Search for "EasyApache4"
- At the top look for "Currently Installed Packages" and click on the button "Customize"
- On the left panel click "PHP Extensions"
- Search for mysqlnd
- You should see something like "php70-php-mysqlnd"
- Toggle the switch to enable it
- On the left panel click on review
- At the bottom click "Provision"
- You're Done

- 30,962
- 25
- 85
- 135

- 4,754
- 9
- 39
- 81
I had the same issue, I went to EasyApache4 from the WHM clicked on customize button then PHP Extension tab.. I selected and installed the extension php72-php-mysqlnd
and my was solved

- 7,969
- 2
- 11
- 21
For mysqli on Docker's official php containers:
Tagged php versions that support mysqli may still not come with mysqli configured out of the box, You can install it with the docker-php-ext-install
utility (see comment by Konstantin). This is built-in, but also available from the docker-php-extension-installer project.
They can be used to add mysqli either in a Dockerfile, for example:
FROM php:5.6.5-apache
COPY ./php.ini /usr/local/etc/php/
RUN docker-php-ext-install mysqli
or in a compose file that uses a generic php container and then injects mysqli installation as a setup step into command
:
web:
image: php:5.6.5-apache
volumes:
- app:/var/www/html/
ports:
- "80:80"
command: >
sh -c "docker-php-ext-install mysqli &&
apache2-foreground"

- 1,361
- 2
- 18
- 31
On php 5.3.0 and later version you dont need to specially install mysqli on windows. Rather follow simple steps as shown below.
Locate php.ini file [ if not there it means you have not copied php.ini-development or php.ini-production file as php.ini to make your configurations ]
There are 2 things to be done 1. Uncomment and set right path to extension_dir = "ext" Basically set the path where you find ext folder in php even if its in same folder from where you are running php-cgi.ex
- uncomment mysqli library extention extension=mysqli
Note: uncommenting in this php.ini file is by removing starting ; from the line.

- 80
- 1
- 8
-
1Do not post the same answer for different questions. Answer once and vote to close all other questions as duplicates. – Your Common Sense Mar 22 '20 at 10:37
-
1Also, you are supposed to check if the answer you are about to post has been posted already. – Your Common Sense Mar 22 '20 at 10:38
to solve this issue you should Run
sudo apt-get install php7.4-mysqli

- 31
- 3
-
Illuminate\Database\QueryException could not find driver (SQL: select * from information_schema.tables where table_schema = Cplus and table_name = migrations and table_type = 'BASE TABLE') at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671 667▕ // If an exception occurs when attempting to run a query, we'll format the error 668▕ // message to include the bindings with SQL, which will make this exception a – James Mark Saphani Nov 24 '20 at 07:48