Managing databases can be a daunting task, especially when working on a server without a graphical user interface. That’s where phpMyAdmin comes in! This powerful web-based tool simplifies the process of managing your MySQL and MariaDB databases, all from the comfort of your web browser. In this article, we’ll walk you through the steps on How to Install phpMyAdmin on Ubuntu Server.
How to Install phpMyAdmin on Ubuntu Server
Prerequisites
Before we begin, make sure you have the following:
- An Ubuntu server with a non-root user having sudo privileges.
- LAMP (Linux, Apache, MySQL, PHP) stack installed on your server. You can follow our guide on how to set up a web server on Ubuntu using Apache if you haven’t already.
Update Your System
First, update your package index and upgrade the system:
sudo apt update && sudo apt upgrade
Install phpMyAdmin on Ubuntu Server
Once your system is up to date, install phpMyAdmin with the following command:
sudo apt install phpmyadmin
During the installation process, you’ll be prompted to choose the web server you’re using. Select Apache by pressing the spacebar and then hit Enter.
Next, the installer will ask if you want to configure the database for phpMyAdmin with dbconfig-common. Choose “Yes” and press Enter.
Finally, provide a password for the phpMyAdmin application. You’ll be asked to confirm the password. This is not the same as your MySQL or MariaDB password, but a separate one for phpMyAdmin.
Configure Apache
To access phpMyAdmin via your web browser, you need to configure Apache to serve phpMyAdmin. Create a new configuration file:
sudo nano /etc/apache2/conf-available/phpmyadmin.conf
Paste the following content into the file:
Alias /phpmyadmin /usr/share/phpmyadmin
<Directory /usr/share/phpmyadmin>
Options SymLinksIfOwnerMatch
DirectoryIndex index.php
<IfModule mod_php5.c>
php_admin_value upload_max_filesize 128M
php_admin_value post_max_size 128M
php_admin_value max_execution_time 360
php_admin_value max_input_time 360
</IfModule>
<IfModule mod_php.c>
php_admin_value upload_max_filesize 128M
php_admin_value post_max_size 128M
php_admin_value max_execution_time 360
php_admin_value max_input_time 360
</IfModule>
</Directory>
<Directory /usr/share/phpmyadmin/setup>
<IfModule mod_authz_core.c>
<RequireAny>
Require ip 127.0.0.1
Require ip ::1
</RequireAny>
</IfModule>
<IfModule !mod_authz_core.c>
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>
Save and exit the file.
Enable the configuration and restart Apache:
sudo a2enconf phpmyadmin
sudo systemctl restart apache2
Secure phpMyAdmin
By default, phpMyAdmin can be accessed by anyone with your server’s IP address or domain name. To enhance security, we recommend restricting access to specific IP addresses or networks.
Edit the Apache configuration file:
- Open the Apache configuration file for editing:
sudo nano /etc/apache2/sites-available/000-default.conf
- Add the following lines inside the
<VirtualHost>
section to configure the phpMyAdmin alias:
Alias /phpmyadmin "/usr/share/phpmyadmin"
<Directory "/usr/share/phpmyadmin">
Options FollowSymLinks
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
- Save and exit the file by pressing
Ctrl + X
, thenY
, and finallyEnter
. - Enable the necessary PHP modules and restart Apache:
sudo phpenmod mbstring
sudo systemctl restart apache2
Configure phpMyAdmin
- Set up the phpMyAdmin configuration storage:
sudo mysql < /usr/share/phpmyadmin/sql/create_tables.sql
- Create a new MySQL user and grant privileges:
sudo mysql -u root -p
mysql> CREATE USER 'phpmyadmin'@'localhost' IDENTIFIED BY 'your_password_here';
mysql> GRANT ALL PRIVILEGES ON phpmyadmin.* TO 'phpmyadmin'@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> EXIT;
- Edit the phpMyAdmin configuration file:
sudo nano /etc/phpmyadmin/config.inc.php
- Add the following lines at the end of the file, replacing
your_password_here
with the password you created for the ‘phpmyadmin’ user:
$cfg['Servers'][$i]['controluser'] = 'phpmyadmin';
$cfg['Servers'][$i]['controlpass'] = 'your_password_here';
- Save and exit the file.
- Install
htpasswd
to create a password file:
sudo apt install apache2-utils
- Create a password file and add a user:
sudo htpasswd -c /etc/phpmyadmin/.htpasswd your_username_here
- Enter a password for the user when prompted.
- Edit the Apache configuration file:
sudo nano /etc/apache2/sites-available/000-default.conf
- Add the following lines inside the
<Directory "/usr/share/phpmyadmin">
section:
AuthType Basic
AuthName "Restricted Access"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user
sudo systemctl restart apache2
Access phpMyAdmin
- Open your web browser and navigate to
http://your_server_ip/phpmyadmin
. - Log in using the username and password you created for the
.htpasswd
file. - You should now see the phpMyAdmin interface, where you can manage your MySQL databases.
Conclusion
Congratulations! You have successfully installed and configured phpMyAdmin on your Ubuntu server. You can now manage your MySQL databases through the phpMyAdmin web interface. Remember to keep phpMyAdmin up-to-date for security reasons and always back up your data before making significant changes.