If you’re navigating the world of Rocky Linux 9 and looking to streamline your MariaDB or MySQL database management, installing phpMyAdmin is the way to go. This guide will walk you through the process installation, how to install phpMyAdmin on Rocky Linux 9, ensuring that you can harness the full power of this user-friendly MySQL administration tool on your Rocky Linux 9 system.
Table of Contents
- Understanding the Need for phpMyAdmin
- Simplified Database Management
- Prerequisites for Install phpMyAdmin
- Installing phpMyAdmin on Rocky Linux 9
- Conclusion
Understanding the Need for phpMyAdmin
Before we dive into the installation process, let’s take a moment to understand why phpMyAdmin is a valuable addition to your Rocky Linux 9 environment.
Now, let’s explore the advantages of using phpMyAdmin.
Simplified Database Management
phpMyAdmin provides a web-based interface that simplifies the often complex task of managing MySQL databases. With its intuitive GUI (Graphical User Interface), even users without extensive technical expertise can interact with databases seamlessly.
Prerequisites for Install phpMyAdmin
Before we dive into the phpMyAdmin installation process, make sure you have the following prerequisites in place:
- A Rocky Linux 9 system with root or sudo access, to set this up, follow our guide Initial Setup Rocky Linux 9 Server: Secure and Efficient You can deploy this on a physical machine or a virtual environment like VMware or VirtualBox.
- A stable internet connection to download packages
- Basic familiarity with command-line operations.
Now that we’ve highlighted the benefits, let’s move on to the step-by-step installation process.
Installing phpMyAdmin on Rocky Linux 9
Follow these steps to install phpMyAdmin on your Rocky Linux 9 and harness its powerful features for your web hosting needs:
Step 1: Update Your System
Before any installation of phpMyAdmin, it’s a good practice to ensure that your system is up-to-date. Open your terminal and run:
$ sudo dnf update
This command will update the package lists and install any available updates.
With the system updated, let’s proceed to the next step.
Step 2: Install the EPEL Repository
phpMyAdmin requires the Extra Packages for Enterprise Linux (EPEL) repository. Install it using the following command:
$ sudo dnf install epel-release
This step ensures that you have access to the necessary packages.
Now that we have the EPEL repository installed, let’s move on to the phpMyAdmin installation.
Step 3: Install Apache Web Server
PhpMyAdmin is a web-based tool, and to use it, you need to install the Apache web server using the following commands.
$ sudo dnf install httpd
Once installed, start the Apache service and enable it to start at boot.
$ sudo systemctl start httpd
$ sudo systemctl enable httpd
As I have noted before, you can install Apache Web Server by using our previous guides below.
Step 4: Install Database Server
Additionally for installing phpMyAdmin, you’ll require a database server. You have the option to install either MariaDB or MySQL, but for this example, we’ll opt for MariaDB.
$ sudo dnf install mariadb-server
After installation, initiate the MariaDB service and set it to start automatically during boot.
$ sudo systemctl start mariadb
$ sudo systemctl enable mariadb
Now, let’s make sure your MariaDB installation is safe. Run the script, and it will ask you to set a password for the main user, stop remote root logins, and get rid of any anonymous users. Additionally, it will delete the test database, which anonymous users can usually access by default.
$ sudo mariadb-secure-installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] Y
Enabled successfully!
Reloading privilege tables..
... Success!
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] Y
New password: [Your Password]
Re-enter new password: [Your Password]
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
If you want to use MySQL, you can follow this guide
Step 5: Install PHP
PhpMyAdmin is built with PHP, so we need to install PHP and some required extensions using the following command.
$ sudo dnf install php php-mysqlnd php-json php-mbstring
For details installation, I recommend referring to the accompanying following tutorial.
Step 6: Install phpMyAdmin
Next, install PhpMyAdmin on our Linux system by navigating to the web server’s document root directory, which is /var/www/html.
Run the following command for installing phpMyAdmin along with its dependencies:
$ cd /var/www/
Afterwards, retrieve the most recent version of PhpMyAdmin by employing the provided wget
command.
$ sudo wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz
After you’ve downloaded the archive, extract its contents and rename the directory for ease of use.
$ sudo tar -xvzf phpMyAdmin-latest-all-languages.tar.gz
$ sudo mv phpMyAdmin-*/ phpmyadmin
Afterward, modify the owner of the ‘phpmyadmin’ directory to the ‘apache’ user using the following chown command:
$ sudo chown -R apache:apache phpmyadmin
Create a configuration file for PhpMyAdmin.
$ sudo cp /var/www/phpmyadmin/config.sample.inc.php /var/www/phpmyadmin/config.inc.php
$ sudo chown -R apache:apache /var/www/phpmyadmin/config.inc.php
Then edit the configuration file:
$ sudo vi /var/www/phpmyadmin/config.inc.php
Find the following line and set your own blowfish_secret:
$cfg['blowfish_secret'] = 'your_password';
Save and exit the file.
Step 7: Create Database for phpMyAdmin
During this phase, you’ll create a fresh database and user specifically for phpMyAdmin. This database will serve as the repository for storing phpMyAdmin configurations.
$ mysql -u root -p
Create a new database named ‘phpmyadmin’ using the provided query.
CREATE DATABASE phpmyadmin;
SELECT PASSWORD('your-strong-password');
Afterward, generate a new user named ‘pma’ with the password encrypted. Subsequently, provide the user with access to the ‘phpmyadmin’ database, and implement the necessary updates.
CREATE USER 'pma'@'localhost' IDENTIFIED VIA mysql_native_password USING '*918DD9A67EC81CE28027875FF141071F088CA7CF';
GRANT SELECT, INSERT, UPDATE, DELETE ON phpmyadmin.* TO 'pma'@'localhost';
FLUSH PRIVILEGES;
Then type ‘quit‘ to exit from the mariadb shell.
Import the Database Schema for phpMyAdmin
Following the creation of the database and user, proceed to import the database schema for phpMyAdmin. Change the working directory to ‘/var/www/phpmyadmin/sql
‘.
$ cd /var/www/phpmyadmin/sql
Run the following command to import the database schema into the ‘phpmyadmin’ database.
$ mysql -u root -p phpmyadmin < create_tables.sql
With phpMyAdmin and database installed, the next step is configuring it to work with your web server.
Step 8: Configure phpMyAdmin
phpMyAdmin needs to be configured to work with your web server, typically Apache. In this step, you’ll establish a new Apache/httpd configuration for phpMyAdmin. Additionally, you’ll set up Apache basic authentication to enhance the security of phpMyAdmin.
Navigate to the ‘/etc/httpd/conf.d’ directory and generate a new configuration file named ‘phpmyadmin.conf’ using the vim editor.
$ cd /etc/httpd/conf.d/
$ sudo vi phpmyadmin.conf
Copy and paste the following configuration.
# Alias for accessing phpmyadmin
Alias /phpmyadmin /var/www/phpmyadmin
# document root phpmyadmin
<Directory /var/www/phpmyadmin>
# Enable Basic authentication
AuthType Basic
AuthName "Please Enter Your Password"
AuthUserFile /var/www/phpmyadmin/.htpasswd
Require valid-user
# If you're paranoid - use this and allow a specific IP address
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
# Allow from ::1
</Directory>
Press ‘Ctrl+x‘, type ‘y‘, then press ‘Enter‘ to save and exit.
Execute the subsequent command to generate a new Apache basic authentication password. Replace the user ‘samm’ with your own username.
htpasswd -c /var/www/phpmyadmin/.htpasswd samm
Afterward, navigate to the ‘/var/www/phpmyadmin’ directory and craft a new configuration named ‘.htaccess’ using the vim editor.
$ cd /var/www/phpmyadmin/
$ sudo vi .htaccess
Copy and paste the following configuration.
AuthUserFile /var/www/phpmyadmin/.htpasswd
AuthGroupFile /dev/null
AuthName "Secret"
AuthType Basic
require valid-user
<Files ~ "^.(htpasswd|htaccess)$">
deny from all
</Files>
Then press ‘Ctrl+x‘, type ‘y‘, then press ‘Enter‘ to save and exit.
Subsequently, alter the ownership of the configuration files ‘.htaccess’ and ‘.htpasswd’ (generated using the htpasswd command) to ‘apache’ with the following command.
$ sudo chown apache:apache .htaccess .htpasswd
Ensure the httpd configuration is error-free by conducting a verification. Subsequently, restart the httpd service to implement the recent changes.
Restart Apache to apply the changes:
$ sudo apachectl configtest
$ sudo systemctl restart httpd
Step 9: Access phpMyAdmin
Launch your web browser and enter your server’s IP address, followed by the directory path ‘/phpmyadmin’.
For instance: http://SERVER-IP/phpmyadmin/
Enter the username and password associated with the Apache/httpd basic authentication when prompted.
If your username and password are accurate, you’ll access the phpMyAdmin login page. In case of incorrect credentials, you’ll either be redirected to the same page or encounter a ‘401 Unauthorized’ access message.
On the phpMyAdmin login page, input the database username ‘root’ and the corresponding password. Subsequently, click ‘Go’ to log in to phpMyAdmin.
Step 10: Configure FirewallD
Apache typically utilizes ports 80 and 443 for HTTP and HTTPS by default. To grant access to PhpMyAdmin on your server, execute the following command to open the necessary Apache ports:
$ sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
$ sudo firewall-cmd --zone=public --add-port=443/tcp --permanent
$ sudo firewall-cmd --reload
Executing these commands incorporates a rule that permits incoming traffic on the designated port and then execute firewall reload to implement the modifications.
Congratulations! You’ve successfully installed phpMyAdmin on Rocky Linux 9.
Conclusion
In this guide, we’ve covered the essential steps to installing phpMyAdmin on Rocky Linux 9. By following these straightforward instructions, you now have a powerful tool at your disposal for efficient MySQL database management. Whether you’re a seasoned administrator or just starting with Rocky Linux, phpMyAdmin’s user-friendly interface makes database management a breeze.
As you explore phpMyAdmin on Rocky Linux 9, remember that regular updates and security checks are key to maintaining a robust and stable system.
By incorporating phpMyAdmin into your workflow, you’ve taken a significant step toward optimizing your database management tasks on Rocky Linux 9. Enjoy the benefits of streamlined administration and improved efficiency as you navigate the world of MySQL databases with ease. Happy managing!
Also Read Our Other Guides :
- How To Install MongoDB 6.0 on Rocky Linux 9
- How To Install Node.js on Rocky Linux 9 With 3 Different Ways
- How To Install Varnish Cache for Nginx on Rocky Linux 9
- The Easy Ways to Check File Size in Linux
Finally, now you have learned how to install phpMyAdmin on Rocky Linux 9.