How to install MySQLi on MacOS

PhpMacosMysqli

Php Problem Overview


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!

Php Solutions


Solution 1 - Php

Use php-mysqlnd instead of php-mysql. On Linux, to install with apt-get type:

apt-get install php-mysqlnd

Solution 2 - Php

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.

Solution 3 - Php

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

Solution 4 - Php

This article is clearly explained, how to install MySqli with EachApache. This works for me too.

To install mysqli using EachApache:

  1. Login to WHM as 'root' user.

  2. Either search for "EasyApache" or go to Software > EasyApache

  3. Scroll down and select a build option (Previously Saved Config)

  4. Click Start "Start customizing based on profile"

  5. Select the version of Apache and click "Next Step".

  6. Select the version of PHP and click "Next Step".

  7. Chose additional options within the "Short Options List"

  8. Select "Exhaustive Options List" and look for "MySQL Improved extension"

  9. Click "Save and Build"

Solution 5 - Php

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

Solution 6 - Php

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.

Solution 7 - Php

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.

Solution 8 - Php

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.

Solution 9 - Php

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

Solution 10 - Php

sudo apt-get -y -f install php7.0-mysql

Solution 11 - Php

if you use ubuntu 16.04 (maybe and above) just do this

 sudo phpenmod mysqli
 sudo service php7.0-fpm restart

Solution 12 - Php

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

Solution 13 - Php

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

Solution 14 - Php

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"

Solution 15 - Php

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

  2. uncomment mysqli library extention extension=mysqli

Note: uncommenting in this php.ini file is by removing starting ; from the line.

Solution 16 - Php

to solve this issue you should Run

sudo apt-get install php7.4-mysqli

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJack HumphriesView Question on Stackoverflow
Solution 1 - PhpAldo Solis ZentenoView Answer on Stackoverflow
Solution 2 - PhpMarc BView Answer on Stackoverflow
Solution 3 - PhpAjeet ShahView Answer on Stackoverflow
Solution 4 - PhpDulitha KView Answer on Stackoverflow
Solution 5 - PhpmvsoaresView Answer on Stackoverflow
Solution 6 - PhpKleo ZaneView Answer on Stackoverflow
Solution 7 - PhpShambhuView Answer on Stackoverflow
Solution 8 - PhpJulian GongView Answer on Stackoverflow
Solution 9 - PhpRichView Answer on Stackoverflow
Solution 10 - PhpJuergenView Answer on Stackoverflow
Solution 11 - PhpYu JiaaoView Answer on Stackoverflow
Solution 12 - PhpCesar BielichView Answer on Stackoverflow
Solution 13 - PhpOgbonna VitalisView Answer on Stackoverflow
Solution 14 - PhpJeremyDouglassView Answer on Stackoverflow
Solution 15 - PhpMadhavarao KulkarniView Answer on Stackoverflow
Solution 16 - PhpJames Mark SaphaniView Answer on Stackoverflow