Amazon.co.uk Widgets

Log in

X
Running Homebrew MySQL/MariaDB on macOS Tahoe

How to Add MySQL or MariaDB to Homebrew Apache + PHP (macOS)

This guide shows how to install and configure MySQL or MariaDB with your Homebrew Apache and PHP setup on macOS. It covers installation, starting the service, and basic connection tests.

Prerequisites

  • macOS with Homebrew installed 
  • Homebrew httpd and PHP already working 
  • Terminal access with admin privileges

Steps

  1. Install MySQL or MariaDB:
    You can choose one:
    brew install mysql
    # or
    brew install mariadb
  2. Start the database service:
    Use Homebrew services to keep it running in the background:
    brew services start mysql
    # or
    brew services start mariadb
  3. Secure the installation:
    Run the included script to set a root password and remove insecure defaults:
    mysql_secure_installation
  4. Test the database connection:
    Log into the server:
    mysql -u root -p
    Enter your root password to confirm it works.
  5. Verify PHP can connect:
    Ensure you have the MySQL extension for PHP (usually included in Homebrew PHP builds). Create a file dbtest.php in your Apache document root:
    <?php
    $mysqli = new mysqli("localhost", "root", "yourpassword");
    if ($mysqli->connect_error) {
      die("Connection failed: " . $mysqli->connect_error);
    }
    echo "Connected successfully to MySQL/MariaDB!";
    ?>
    Visit http://localhost:8080/dbtest.php (or your configured port).

Verification

If configured correctly, you’ll see a success message in your browser. At this point, your Homebrew Apache stack supports PHP and MySQL/MariaDB, ready for Joomla or other PHP applications.

See Running Homebrew Apache with Let's Encrypt SSL on macOS Tahoe and Running Homebrew PHP on Apache on macOS Tahoe.

Homebrew Logo: Vítor Galvão (creator); MikeMcQuaid, Synoli (committers), BSD, via Wikimedia Commons