How to set up phpMyAdmin (Windows, Mac OS, Ubuntu)

Updated: January 25, 2024 By: Guest Contributor Post a comment

Introduction

phpMyAdmin is a free and open-source administration tool for MySQL and MariaDB. With a robust web interface, it allows users to interact with their database servers, providing a user-friendly environment for managing databases, tables, columns, relations, indexes, users, permissions, and much more. This tutorial guides you through the steps of setting up phpMyAdmin on Windows, Mac OS, and Ubuntu systems. We will start with the basics and move towards more advanced configurations, including security settings and custom configurations.

Prerequisites

Before we begin, ensure that you have:

  • A running web server (Apache/Nginx).
  • MySQL or MariaDB installed.
  • PHP installed with necessary extensions (mbstring, zip, and gd).

Installation on Windows

For Windows users, the easiest way to get phpMyAdmin up and running is through a software bundle like XAMPP:

  • 1. Download XAMPP from https://www.apachefriends.org/index.html
  • 2. Run the installer and select Apache, MySQL, PHP, and phpMyAdmin
  • 3. Follow the on-screen instructions to complete the installation
  • 4. Start Apache and MySQL from the XAMPP control panel

Once the servers are running, you can access phpMyAdmin at http://localhost/phpmyadmin.

Installation on Mac OS

Mac users can install phpMyAdmin with Homebrew:

1. Install Homebrew (if not installed):

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 

2. Update Homebrew:

brew update 

3. Install phpMyAdmin:

brew install phpmyadmin

Follow the prompts, and configure your webserver to use the phpMyAdmin install, which is usually in /usr/local/share/phpmyadmin. You’ll then be able to access it at http://localhost/phpmyadmin.

Installation on Ubuntu

Ubuntu users can install phpMyAdmin from the official package repositories:

1. Update your system package repository:

sudo apt update 

2. Install phpMyAdmin and its dependencies:

sudo apt install phpmyadmin php-mbstring php-zip php-gd

You’ll be asked to choose a web server; select Apache. When the installation is complete, enable the PHP extensions and restart your web server:

sudo phpenmod mbstring
sudo systemctl restart apache2

Access phpMyAdmin at http://your_server_ip/phpmyadmin to manage your databases.

Secure Your phpMyAdmin Instance

After installing phpMyAdmin, it’s crucial to secure your instance. Update the default configuration file to enhance security:

<Directory /usr/share/phpmyadmin>
    Options FollowSymLinks
    DirectoryIndex index.php
    <IfModule mod_php5.c>
        AddType application/x-httpd-php .php
        php_flag magic_quotes_gpc Off
        php_flag track_vars On
        php_flag register_globals Off
        php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
        php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/tmp/
    </IfModule>
</Directory>

# Secure phpMyAdmin using .htaccess
<Directory /usr/share/phpmyadmin>
    AllowOverride All
</Directory>
# Restrict by IP address (Change 'your_IP_address' with your actual IP)
Order Deny,Allow
Deny from All
Allow from your_IP_address

Remember, always use strong, unique passwords for your accounts, and consider setting up Two-Factor Authentication (2FA) for an extra layer of security.

Update and Upgrade phpMyAdmin

Keeping phpMyAdmin up-to-date is crucial for your database’s security. To update:

# For Ubuntu systems:
sudo apt update
sudo apt upgrade phpmyadmin

# For systems with Homebrew:
brew update
brew upgrade phpmyadmin

# For Windows (via XAMPP), typically you would download a newer version of the XAMPP installer or update the phpMyAdmin directory manually

Always make sure to back up your configurations and databases before performing an upgrade.

Advanced Configuration

For advanced users, configuring phpMyAdmin to recognize multiple servers, enable advanced features, and set up themes can be done by editing the config.inc.php file, usually located within the installation directory.

Connecting to Multiple Servers

$cfg['Servers'][$i]['host'] = 'localhost'; // MySQL hostname
$cfg['Servers'][$i]['port'] = ''; // MySQL port
$cfg['Servers'][$i]['connect_type'] = 'tcp'; // Connection type
$cfg['Servers'][$i]['compress'] = false; // Use compression for the MySQL connection
$cfg['Servers'][$i]['auth_type'] = 'cookie'; // Authentication method (config, http or cookie based)?

Enabling Advanced Features

Enabling features like bookmarking queries, browsing history, and designer settings can be done as follows:

$cfg['Bookmark']['enabled'] = true;
$cfg['History']['enabled'] = true;
$cfg['Designer']['enabled'] = true;

Custom Themes

phpMyAdmin supports themes, which can be downloaded from the official website. After downloading and extracting a theme, place the theme directory in ./themes/ within your phpMyAdmin directory. Change the theme by selecting it within the phpMyAdmin interface under the ‘Appearance Settings’ section.

Conclusion

This tutorial provided a comprehensive guide to setting up phpMyAdmin on various operating systems including Windows, Mac OS, and Ubuntu. Remember, security should be your top priority when configuring phpMyAdmin, and always keep your instance well-maintained by applying the latest updates and upgrades.