---
title: Step-by-Step Tutorial to Install phpMyAdmin Securely on Linux
description: Discover how to securely install phpMyAdmin on Linux with our concise guide. Learn essential steps for a safe and efficient setup, tailored for Linux users.
canonical: https://adamtheautomator.com/install-phpmyadmin/
---

# Step-by-Step Tutorial to Install phpMyAdmin Securely on Linux

> Discover how to securely install phpMyAdmin on Linux with our concise guide. Learn essential steps for a safe and efficient setup, tailored for Linux users.

Source: https://adamtheautomator.com/install-phpmyadmin/

---

- Step-by-Step Tutorial to Install phpMyAdmin Securely on Linux Tap to hide Home

- Tutorials

- Guidebooks

- Instructors

- Get Paid to Write

- Advertising

- Recommended Resources

- About Adam

                Search for:

-

-

-

-

# Step-by-Step Tutorial to Install phpMyAdmin Securely on Linux

        Published:22 November 2023 - 6 min. read

- Command Line
- Linux
- phpMyAdmin

          [](https://adamtheautomator.com/author/loeber-deryk/)

            [Loeber Deryk](https://adamtheautomator.com/author/loeber-deryk/)

            Read [more tutorials](https://adamtheautomator.com/author/loeber-deryk/) by Loeber Deryk!

        [](https://specopssoft.com/product/specops-password-auditor/?utm_source=adamtheautomator&utm_medium=referral&utm_campaign=adamtheautomator_referral_na&utm_content=display)
        Audit Active Directory for stale users, weak passwords, and other security risks with [Specops Password Auditor](https://specopssoft.com/product/specops-password-auditor/?utm_source=adamtheautomator&utm_medium=referral&utm_campaign=adamtheautomator_referral_na&utm_content=text).

Table of Contents

- Prerequisites for Installing phpMyAdmin
- Steps to Install phpMyAdmin on Ubuntu
- Configuring Apache2 for phpMyAdmin Installation
- Securing phpMyAdmin with a Strong Password
- Verifying phpMyAdmin Configuration Files
- Enabling mbstring Extension for phpMyAdmin
- Restarting Webserver for phpMyAdmin
- Best Practices for Creating a Secure phpMyAdmin User Account
- Step 1: Accessing MySQL Shell
- Step 2: Creating a New MySQL User
- Granting Full Privileges to Your New User
- Accessing the phpMyAdmin Interface
- Enhancing phpMyAdmin Security with Password Protection
- Step 1: Configuring Apache for .htaccess Use
- Step 2: Restarting Apache to Apply Changes
- Step 3: Creating the .htaccess File for phpMyAdmin
- Setting Up Additional Authentication for phpMyAdmin
- Accessing phpMyAdmin with Enhanced Security
- Wrapping Up: phpMyAdmin Installation and Security

                XFacebookLinkedIn

If you're looking to streamline your MySQL server management on Linux, why not consider a GUI-based approach? The command-line can be daunting, but a front-end tool like [phpMyAdmin](https://www.phpmyadmin.net) can make things a lot easier. In this guide, we'll cover the steps to install phpMyAdmin, a must-have for any sysadmin or developer. Let's dive in!

phpMyAdmin, with its web-based interface, simplifies MySQL management. This tutorial will show you how to install and configure phpMyAdmin, making database management a breeze.

By the end of this tutorial, you'll say goodbye to accidental database mishaps! Let's learn how to safeguard your databases and, ultimately, your job.

## Prerequisites for Installing phpMyAdmin

Before starting, ensure you have the following:

- An Ubuntu Server 18.04 or newer.

Related:[How to Install Ubuntu 20.04 [Step-by-Step]](https://adamtheautomator.com/install-ubuntu/)

- Root or sudo access on your server. Check out how to enable these in Ubuntu.

- Your server should have the LAMP (Linux, Apache, MySQL, PHP) stack. For installation guidance, refer to this guide.

- A separate computer with an SSH client like Putty, Bitvise, or the Chrome SSH Extension. This tutorial uses the default SSH client in Windows 10 (ssh.exe).

Related:[How to Set up the SSH Google Chrome Extension](https://adamtheautomator.com/ssh-chrome-extension/)

## Steps to Install phpMyAdmin on Ubuntu

There are various methods to install phpMyAdmin, but the simplest and most common is using the Advanced Package Tool (APT). Follow these steps for a smooth installation.

1. Connect to your Ubuntu server using an SSH client.

ssh username@server_name_or_IP

2. Begin by updating your server's package repository to ensure you're getting the latest software versions.

sudo apt update -y

Depending on your server's internet connection and system load, this update might take a few minutes.

Updating the package repository sources cache

3. After updating, install the phpmyadmin package along with its dependencies php-mbstring and php-gettext.

sudo apt install phpmyadmin php-mbstring php-gettext -y

4. During the phpMyAdmin installation process, you'll encounter a series of prompts to configure phpMyAdmin properly.

## Configuring Apache2 for phpMyAdmin Installation

On the webserver configuration screen, use the arrow keys to navigate. Highlight apache2 and press SPACE to select it. An asterisk [*] will appear next to apache2, indicating it's selected. Then, press Enter.

 Selecting apache2 as the webserver during the phpMyAdmin installation

5. The installer will then prompt for the phpMyAdmin database setup. Make sure <Yes> is selected and press Enter to proceed.

 Confirming the phpMyAdmin database installation

## Securing phpMyAdmin with a Strong Password

6. The phpMyAdmin installation process automatically creates a MySQL user named phpMyAdmin. Enter a strong password for this new account at the prompt, and press Enter.

 Assigning a new phpMyAdmin password

7. Confirm your phpMyAdmin password by re-entering it on the Password confirmation prompt and press Enter. Wait for the installation and configuration to complete.

 Confirming the new phpMyAdmin password

## Verifying phpMyAdmin Configuration Files

8. After installing phpMyAdmin, confirm the existence of the Apache configuration file for phpMyAdmin by running the following command.

ls /etc/apache2/conf-enabled/

The phpmyadmin.conf file contains vital phpMyAdmin settings, like installation location and the database server configuration. Usually, there's no need for manual edits to this file.

 Checking the /etc/apache2/conf-enabled directory for phpMyAdmin configuration

## Enabling mbstring Extension for phpMyAdmin

9. To optimize phpMyAdmin's functionality, enable the [mbstring](https://docs.phpmyadmin.net/en/latest/glossary.html#term-mbstring) PHP extension with the command below.

sudo phpenmod mbstring

## Restarting Webserver for phpMyAdmin

10. Finally, [restart your webserver for the changes](https://adamtheautomator.com/ubuntu-systemctl/) to take effect. This step is crucial for making phpMyAdmin accessible.

sudo systemctl restart apache2

Related:[Controlling Systemd services with Ubuntu systemctl](https://adamtheautomator.com/ubuntu-systemctl/)

11. Now, it's crucial to verify the webserver's status. This check confirms that the Apache server is running smoothly after the phpMyAdmin installation.

sudo systemctl status apache2

Look for a response indicating the Apache webserver service is active (running), as shown in the screenshot below. This confirmation is a key step in successfully installing phpMyAdmin.

 Verifying the web server's status after installing phpMyAdmin

## Best Practices for Creating a Secure phpMyAdmin User Account

As part of the phpMyAdmin setup, a default MySQL user named phpmyadmin is created. However, this account is limited to accessing only the phpMyAdmin database and doesn't have full administrative privileges.

To enhance security, it's advisable to create a new, dedicated privileged account instead of using the default. This approach reduces the risk of attacks, as common usernames are often targeted.

Follow these steps to set up a secure, dedicated management account for phpMyAdmin:

## Step 1: Accessing MySQL Shell

Start by opening the MySQL shell. You can do this directly from the terminal using the following command:

sudo mysql

Alternatively, log in as the root user with this command:

sudo mysql -u root -p

## Step 2: Creating a New MySQL User

Once in the MySQL prompt, create a new user with custom credentials. Replace ‘ata' and ‘pa$$word' with your desired username and strong password. Here's the command:

CREATE USER 'ata'@'localhost' IDENTIFIED BY 'pa$$word';

This step is vital for maintaining a secure phpMyAdmin setup.

 Creating a new MySQL user account during phpMyAdmin installation

## Granting Full Privileges to Your New User

3. The next step in securing your phpMyAdmin installation is to grant full privileges to your newly created user. This is done using the GRANT ALL PRIVILEGES statement, which provides complete access to all databases. The WITH GRANT OPTION clause is particularly important as it allows this user to manage other user privileges.

GRANT ALL PRIVILEGES ON *.* TO 'ata'@'localhost' WITH GRANT OPTION;

 Granting full privileges to the new user in phpMyAdmin

4. Once you've assigned the necessary privileges, exit the MySQL shell to proceed with the phpMyAdmin setup.

exit

## Accessing the phpMyAdmin Interface

With the installation and user configuration complete, it's time to access the phpMyAdmin web interface and verify the setup.

1. Open your web browser and go to http://your_domain_or_IP/phpmyadmin. Replace your_domain_or_IP with your server's IP address or domain name.

2. You'll see the Welcome to phpMyAdmin login page. Enter the username and password for the account you just created.

 Logging into phpMyAdmin with the new user credentials

3. Once logged in, the phpMyAdmin dashboard will be displayed, confirming a successful setup.

 The phpMyAdmin dashboard

4. Test the new account's privileges by navigating to the Database tab. Here, you can view all databases on the server and verify user privileges.

 Verifying the privileges of the new user account in phpMyAdmin

This completes the installation and setup of phpMyAdmin, ensuring you have a fully functional and secure database management interface on your Linux server.

 Viewing the list of users with database privileges in phpMyAdmin

## Enhancing phpMyAdmin Security with Password Protection

Given its widespread use, phpMyAdmin often becomes a target for unauthorized access attempts. It's essential to implement additional security measures to protect your installation.

A highly effective way to secure phpMyAdmin is by using Apache's .htaccess authentication and authorization features. This method adds an additional layer of security, restricting access to the phpMyAdmin interface.

Follow these steps to set up .htaccess protection for your phpMyAdmin installation:

## Step 1: Configuring Apache for .htaccess Use

Begin by editing the phpMyAdmin configuration file in Apache to allow .htaccess usage.

sudo nano /etc/apache2/conf-available/phpmyadmin.conf

2. In the <Directory /usr/share/phpmyadmin> section of the file, add the AllowOverride All directive. This setting enables .htaccess files in the phpMyAdmin directory.

 Configuring the AllowOverride All directive in Apache for phpMyAdmin

3. After adding the directive, save and exit the file. Remember to use spaces instead of tabs for indentation.

## Step 2: Restarting Apache to Apply Changes

4. Restart the Apache server to ensure the new configuration is active.

sudo systemctl restart apache2

## Step 3: Creating the .htaccess File for phpMyAdmin

5. The final step involves creating an .htaccess file in the phpMyAdmin directory. This file will manage access to phpMyAdmin.

sudo nano /usr/share/phpmyadmin/.htaccess

6. Inside the .htaccess file, add the necessary directives to manage access. Once done, save and close the file.

By completing these steps, you'll significantly increase the security of your phpMyAdmin installation on Linux, ensuring that only authorized users can access the management interface.

# Sets the authentication type to require entering the username and password.
AuthType Basic
# The message that the server displays on the credential prompt.
AuthName "Restricted Files"
# Specifies the file's location containing the valid users and passwords list.
AuthUserFile /etc/phpmyadmin/.htpasswd
# Allows the user who successfully authenticated to continue accessing phpMyAdmin.
Require valid-user

Not all web browsers display the [AuthName](https://httpd.apache.org/docs/2.4/mod/mod_authn_core.html#authname) directive value during authentication prompts.

 Creating the .htaccess file for phpMyAdmin security

## Setting Up Additional Authentication for phpMyAdmin

7. To further secure your phpMyAdmin installation, create an authentication file named .htpasswd. This file will store the usernames and encrypted passwords for authorized users.

sudo htpasswd -c /etc/phpmyadmin/.htpasswd username

Enter and re-confirm the password for the new user. A successful setup will enhance the security of your phpMyAdmin login process.

 Creating a new authentication file for phpMyAdmin

To add more users, use the command sudo htpasswd /etc/phpmyadmin/.htpasswd additionaluser, substituting additionaluser with the new username.

## Accessing phpMyAdmin with Enhanced Security

8. With the additional security in place, navigate to https://domain_name_or_IP/phpmyadmin in your browser. Enter the username and password you established to access the login page.

 The phpMyAdmin site prompting for username and password

After successful authentication, you will be taken to the main phpMyAdmin login page.

 The phpMyAdmin login page after enhanced security setup

If the authentication fails, you'll receive an Unauthorized response, indicating the need to recheck your credentials.

 Failed phpMyAdmin site authorization attempt

## Wrapping Up: phpMyAdmin Installation and Security

Congratulations on successfully installing and securing phpMyAdmin on Linux! You've now enhanced your database management capabilities, making MySQL management more accessible and secure.

Don't stop here. Explore more advanced phpMyAdmin features and further security enhancements, such as implementing HTTPS and disabling root logins. Check out additional resources like [this guide](https://www.tecmint.com/secure-phpmyadmin-centos-ubuntu/) for more insights. Keep your phpMyAdmin environment secure and efficient!

  Hate ads? Want to support the writer? Get many of our tutorials packaged as an ATA Guidebook.

  [Explore ATA Guidebooks](https://adamtheautomator.com/ata-guidebooks/)

## More from ATA Learning and Partners

- ### Recommended Resources! Recommended Resources for Training, Information Security, Automation, and more!

- ### Get Paid to Write! ATA Learning is always seeking instructors of all experience levels. Regardless if you’re a junior admin or system architect, you have something to share. Why not write on a platform with an existing audience and share your knowledge with the world?

- ### ATA Learning Guidebooks ATA Learning is known for its high-quality written tutorials in the form of blog posts. Support ATA Learning with ATA Guidebook PDF eBooks available offline and with no ads!

## Categories

- IT Ops

- Cloud

- DevOps

- Home Ops

- Information Security

- Software Development

## Site

- Home

- Tutorials

- Guidebooks

- Instructors

- Get Paid to Write

- Advertising

- Recommended Resources

- About Adam

        Copyright 2026&copy; ATA Learning | [Privacy Policy](https://adamtheautomator.com/privacy/)

                                                        Don't be left behind with the ATA Learning Newsletter!

Looks like you're offline!
