Guide: Installing phpMyAdmin on a Linux Server
This guide will walk you through the process of installing phpMyAdmin on your Linux server. phpMyAdmin is a free and open-source administration tool for MySQL and MariaDB.
Prerequisites:
- A running Apache2 web server (as set up in the previous guide)
- A MySQL or MariaDB database server installed and running
- PHP installed with necessary extensions (e.g., php-mbstring, php-zip, php-gd, php-json, php-curl, php-mysql)
Step 1: Install phpMyAdmin
Install phpMyAdmin using your system's package manager. This command will also pull in any necessary PHP extensions that aren't already installed.
sudo apt install phpmyadmin
During the installation process, you will be prompted with a few questions:
- Web server to reconfigure automatically: Select apache2 by pressing the spacebar to mark it with an asterisk, then press Enter.
- Configure database for phpmyadmin with dbconfig-common?: Select Yes and press Enter. This will set up the necessary database for phpMyAdmin's internal use.
- MySQL application password for phpmyadmin: You'll be prompted to enter a password for the phpmyadmin user that phpMyAdmin will use to connect to your database. It's recommended to leave this blank to have one generated automatically, or set a strong password. If left blank, remember to retrieve it from /etc/phpmyadmin/config-db.php if needed later.
Step 2: Enable the phpMyAdmin Apache Configuration
The installation usually places a configuration file for phpMyAdmin in Apache's conf-available directory. You need to enable it.
sudo a2enconf phpmyadmin
Step 3: Restart Apache2 and your Database Server
After installing phpMyAdmin and enabling its Apache configuration, you need to restart Apache2 and your database server for the changes to take effect.
sudo systemctl restart apache2
sudo systemctl restart mysql # Or mariadb if you use MariaDB
Step 4: Secure phpMyAdmin (Highly Recommended)
phpMyAdmin is a powerful tool, so securing it is crucial.
Option A: Change the Access Alias (Recommended)
By default, phpMyAdmin is accessible at http://your_domain/phpmyadmin. Changing this URL makes it harder for automated bots to find.
1. Open the Apache configuration file for phpMyAdmin:
sudo nano /etc/apache2/conf-available/phpmyadmin.conf
2. Find the line starting with Alias /phpmyadmin. Change phpmyadmin to something unique and hard to guess, e.g., myadminpanel, dbmanage, etc.
# Original:
# Alias /phpmyadmin /usr/share/phpmyadmin
# Changed to:
Alias /mysecretadmin /usr/share/phpmyadmin
3. Save and exit (Ctrl+O, Enter, Ctrl+X).
4. Restart Apache2:
sudo systemctl restart apache2
Now you would access it via http://your_domain/mysecretadmin (or whatever alias you chose).
Option B: Create a Dedicated Database User (Crucial for Security)
NEVER use the MySQL/MariaDB root user for daily phpMyAdmin access. Create a separate user with limited privileges.
1. Log in to your MySQL/MariaDB server as root (or a user with create user privileges):
sudo mysql -u root -p
(Enter your MySQL root password when prompted)
2. Create a new user and grant specific privileges. Replace 'pma_user' and 'your_strong_password' with your desired username and a strong password. You can grant more specific privileges based on your needs, but for general administration, this is a good starting point.
CREATE USER 'pma_user'@'localhost' IDENTIFIED BY 'your_strong_password';
GRANT ALL PRIVILEGES ON *.* TO 'pma_user'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;
- Using 'localhost' means this user can only log in from the server itself. For remote access, you'd use '%' instead of 'localhost', but this is less secure.
Step 5: Access phpMyAdmin
Open your web browser and navigate to your phpMyAdmin installation.
- If you changed the alias: https://your_domain/your_new_alias (e.g., https://your_domain/mysecretadmin)
- If you did not change the alias: https://your_domain/phpmyadmin
You should see the phpMyAdmin login screen. Log in with the dedicated database user you created in Step 4 (e.g., 'pma_user') and its password.
Conclusion
You have successfully installed and configured phpMyAdmin, allowing you to manage your MySQL/MariaDB databases through a web interface. Remember to keep it updated and secure!