How to Install and Configure phpMyAdmin on Ubuntu (Step-by-Step Guide)

phpMyAdmin is a popular web-based database management tool that allows users to manage MySQL and MariaDB databases easily. If you’re running an Ubuntu server and want a user-friendly way to interact with your databases, installing phpMyAdmin is the perfect solution.

In this guide, we’ll walk you through the step-by-step process of installing and configuring phpMyAdmin on Ubuntu.

Prerequisites

Before proceeding, ensure you have:

  • A server running Ubuntu 20.04/22.04
  • Root or a user with sudo privileges
  • LAMP (Linux, Apache, MySQL/MariaDB, PHP) installed

If LAMP is not installed, run the following command to install it:

sudo apt update && sudo apt install apache2 mysql-server php php-mbstring php-zip php-gd php-json php-curl

Step 1: Install phpMyAdmin

To install phpMyAdmin, run:

sudo apt update
sudo apt install phpmyadmin

During installation, you will be prompted to:

  1. Choose a web server: Select Apache2 and press Enter.
  2. Configure database for phpMyAdmin: Choose Yes.
  3. Set a MySQL application password: Enter and confirm a strong password.

Step 2: Enable phpMyAdmin in Apache

Once installed, phpMyAdmin is not automatically enabled in Apache. You need to create a symbolic link:

sudo ln -s /usr/share/phpmyadmin /var/www/html

Restart Apache to apply changes:

sudo systemctl restart apache2

Now, you can access phpMyAdmin by navigating to:

http://your-server-ip/phpmyadmin

Step 3: Secure phpMyAdmin (Recommended)

3.1 Secure MySQL root Access

By default, MySQL root access via phpMyAdmin is disabled. To create a dedicated user, log in to MySQL:

sudo mysql -u root -p

Then create a new user:

CREATE USER 'admin'@'localhost' IDENTIFIED BY 'StrongPassword';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

Use this new user to log in to phpMyAdmin instead of root.

3.2 Enable .htaccess Protection

To add an extra layer of security, enable .htaccess for phpMyAdmin:

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

Add the following inside <Directory /usr/share/phpmyadmin>:

AllowOverride All

Save and close the file, then restart Apache:

sudo systemctl restart apache2

Now create a .htaccess file in the phpMyAdmin directory:

sudo nano /usr/share/phpmyadmin/.htaccess

Add:

AuthType Basic
AuthName "Restricted Access"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user

Save and close the file. Then create a user for authentication:

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

Enter a strong password. Restart Apache:

sudo systemctl restart apache2

Now, phpMyAdmin will require authentication before access.

Step 4: Troubleshooting Common Issues

Issue 1: phpMyAdmin Not Found (404 Error)

Try restarting Apache:

sudo systemctl restart apache2

Ensure the symlink exists:

sudo ln -s /usr/share/phpmyadmin /var/www/html

Issue 2: Cannot Log In to phpMyAdmin

  • Ensure the MySQL user exists and has the correct privileges.
  • If using MySQL 8+, change authentication method:
ALTER USER 'admin'@'localhost' IDENTIFIED WITH mysql_native_password BY 'StrongPassword';
FLUSH PRIVILEGES;

Conclusion

By following this guide, you have successfully installed and secured phpMyAdmin on Ubuntu. This setup allows you to manage databases efficiently while keeping them secure.

Need more help? Let us know in the comments!

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Need Help ? Call Our award-winning support team 24/7 at 01-4983900

© 2023 All right reserved to sobiztrend.com