Managing MySQL databases can be cumbersome without a user-friendly interface. phpMyAdmin simplifies this process by providing an intuitive web-based graphical interface to interact with your MySQL or MariaDB databases. This guide will walk you through installing and connecting to phpMyAdmin using a MySQL username and password.

Step 1: Update Your System

Before installing any new software, ensure your system is updated. Open your terminal and run the following commands:

sudo apt update
sudo apt upgrade -y

This will ensure your system has the latest security patches and updates.

Step 2: Install Apache, MySQL, and PHP

phpMyAdmin requires a web server, a database server, and PHP to run. Install them using the following command:

sudo apt install apache2 mysql-server php php-mysql libapache2-mod-php -y

Verify Installation:

  • Apache: Open your browser and navigate to http://localhost. You should see the Apache default page.
  • MySQL: Log in to MySQL to ensure it’s running using:
sudo mysql -u root -p
  • PHP: Test PHP by creating a file:
sudo nano /var/www/html/info.php

Add the following content:

<?php
phpinfo();
?>

Navigate to http://localhost/info.php in your browser. If PHP is installed, you’ll see a PHP information page.

Step 3: Install phpMyAdmin

To install phpMyAdmin, run:

sudo apt install phpmyadmin -y

Configure phpMyAdmin:

During installation, a prompt will appear to configure phpMyAdmin:

  1. Select Apache2 as the web server ( Click on Tab to select ).
  2. Choose “Yes” when asked to configure the database for phpMyAdmin.
  3. Set a strong password for the phpMyAdmin database user.

Enable phpMyAdmin Configuration:

After installation, ensure phpMyAdmin is enabled in Apache:

sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
sudo systemctl restart apache2

Navigate to http://localhost/phpmyadmin in your browser to verify the installation.

Step 4: Create a MySQL User

For better security, avoid using the root user for phpMyAdmin. Create a new MySQL user:

  1. Log in to MySQL:
sudo mysql -u root -p
  1. Create a new user:
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'yourpassword';
  1. Grant permissions to this user:
GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

Step 5: Log In to phpMyAdmin

Open your browser and navigate to http://localhost/phpmyadmin. Enter the MySQL username and password created in the previous step to log in.

You will now have access to the phpMyAdmin dashboard, where you can create databases, manage tables, run SQL queries, and more.

Common Commands Recap (Optional )

  1. System Update:
sudo apt update && sudo apt upgrade -y
  1. Install LAMP Stack:
sudo apt install apache2 mysql-server php php-mysql libapache2-mod-php -y
  1. Install phpMyAdmin:
sudo apt install phpmyadmin -y
  1. Enable phpMyAdmin in Apache:
sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
sudo systemctl restart apache2
  1. Create MySQL User:
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Troubleshooting Tips

  1. phpMyAdmin Not Found: Ensure phpMyAdmin is properly linked to Apache using the ln -s command.
  2. Access Denied: Double-check the MySQL username and password, and ensure privileges are granted.
  3. PHP Modules Missing: Install required modules using:
sudo apt install php-mbstring php-zip php-gd php-json php-curl
sudo systemctl restart apache2

Conclusion

phpMyAdmin provides a simple yet powerful way to manage MySQL databases. By following this guide, you’ve learned how to install and connect to phpMyAdmin using a secure MySQL username and password. This setup ensures an efficient workflow for database management while maintaining security and reliability.

If you have any questions or need further assistance, feel free to reach out at devopsbyrushi@gmail.com.

Similar Posts

Leave a Reply

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