phpMyAdmin is an extensively utilized and feature-rich web-based application, specifically designed to streamline the management of MySQL and MariaDB databases, allowing users to perform various tasks, such as creating, modifying, and deleting databases, tables, fields, or rows. In addition, it offers an intuitive interface for executing SQL queries and managing users and permissions. This comprehensive tutorial aims to guide you meticulously through the entire process of how to install phpMyAdmin on CentOS 7, a widely acclaimed and versatile Linux distribution that has gained significant traction among web server administrators and developers alike, owing to its stability, security, and ease of use. So, without further ado, let’s embark on this exciting journey of setting up phpMyAdmin on CentOS 7!
How to Install phpMyAdmin
Prerequisites
Before installing phpMyAdmin, ensure you have:
- A CentOS 7 server with root access.
- LAMP stack (Linux, Apache, MySQL, and PHP) installed. If you haven’t, check out our guide on setting up LAMP on CentOS 7.
Install EPEL Repository
phpMyAdmin is not available in the default CentOS repositories, so we’ll install the Extra Packages for Enterprise Linux (EPEL) repository, which includes phpMyAdmin:
sudo yum install epel-release
Install phpMyAdmin
With EPEL repository enabled, install phpMyAdmin using yum
:
sudo yum install phpmyadmin
Configure Apache
After installing phpMyAdmin, configure the Apache web server to serve phpMyAdmin. To do this, create a new configuration file for phpMyAdmin in the /etc/httpd/conf.d
directory:
sudo nano /etc/httpd/conf.d/phpmyadmin.conf
Paste the following configuration into the file:
Alias /phpmyadmin /usr/share/phpmyadmin
<Directory /usr/share/phpmyadmin/>
AddDefaultCharset UTF-8
<IfModule mod_authz_core.c>
# Apache 2.4
<RequireAny>
Require ip 127.0.0.1
Require ip ::1
</RequireAny>
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>
<Directory /usr/share/phpmyadmin/setup/>
<IfModule mod_authz_core.c>
# Apache 2.4
<RequireAny>
Require ip 127.0.0.1
Require ip ::1
</RequireAny>
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>
By default, phpMyAdmin allows access only from the local machine. To access phpMyAdmin remotely, replace Require ip 127.0.0.1
and Require ip ::1
with Require all granted
. Don’t forget to restart Apache afterward:
sudo systemctl restart httpd
Configure phpMyAdmin
To enhance security, create a new phpMyAdmin configuration file:
sudo cp /usr/share/phpmyadmin/config.sample.inc.php /usr/share/phpmyadmin/config.inc.php
Open the configuration file with a text editor:
sudo nano /usr/share/phpmyadmin/config.inc.php
Locate the line containing $cfg['blowfish_secret']
and set a secret passphrase between the single quotes. This passphrase will be used for cookie authentication:
$cfg['blowfish_secret'] = 'your_secret_passphrase_here';
Save and close the file.
Set Up the phpMyAdmin Storage
To enable advanced features in phpMyAdmin, like bookmarking queries and tracking changes, set up the phpMyAdmin storage by running the following command:
sudo mysql < /usr/share/phpmyadmin/sql/create_tables.sql
Now, open the config.inc.php
file again:
sudo nano /usr/share/phpmyadmin/config.inc.php
Add the following lines at the end of the file to configure the control user and password for phpMyAdmin:
$cfg['Servers'][$i]['controluser'] = 'pma';
$cfg['Servers'][$i]['controlpass'] = 'your_pma_password';
Save and close the file.
Next, log in to the MySQL shell:
mysql -u root -p
Enter your MySQL root password when prompted. Then, run the following commands to create a new pma
user, grant privileges, and flush privileges:
CREATE USER 'pma'@'localhost' IDENTIFIED BY 'your_pma_password';
GRANT SELECT, INSERT, UPDATE, DELETE ON phpmyadmin.* TO 'pma'@'localhost' IDENTIFIED BY 'your_pma_password';
FLUSH PRIVILEGES;
EXIT;
Access phpMyAdmin
You can now access phpMyAdmin by opening a web browser and navigating to http://your_server_IP_address/phpmyadmin
. Log in with your MySQL username and password to start managing your databases.
Conclusion
Congratulations! You’ve successfully installed and configured phpMyAdmin on CentOS 7. Now you can efficiently manage your MySQL and MariaDB databases through this user-friendly web interface.
For more tutorials on CentOS 7 and other Linux distributions, check out our LinuxBoost guides. Here are some popular ones: