• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install phpMyAdmin with Apache on Ubuntu 18.04

Written by Admin, Updated On May 7, 2019
apache, mariadb, mysql, php, phpmyadmin, ubuntu
How to Install phpMyAdmin with Apache on Ubuntu 18.04

phpMyAdmin is a free, open source and web interface based database management tool for MySQL and MariaDB. It’s PHP based application to interact with MySQL and MariaDB easily. Using phpMyAdmin you can manage MySQL databases, user accounts and privileges, execute SQL-statements, import and export data in a variety of data formats and much more. This tutorial will show you steps to install phpMyAdmin with Apache on Ubuntu 18.04 server.

Prerequisites#

  • You should logged in on Ubuntu server as non-root user account with sudo privileges.
  • Ensure that LAMP (Linux, Apache, MySQL and PHP) stack is installed on your Ubuntu machine.

It is optional but recommend to access your phpMyAdmin installation over HTTPS connections. So it will prevent from unecessary attacks to phpmyadmin. If your domain is not secure with an SSL/TLS certificate, you can follow this guide to Secure Apache with Let’s Encrypt on Ubuntu.

Installing phpMyAdmin with Apache on Ubuntu#

To start installation you need to update Ubuntu package index and upgrade system by using the following command:

sudo apt update
sudo apt upgrade

Next, install the phpMyAdmin package from the default Ubuntu repositories with the below command:

sudo apt install phpmyadmin php-mbstring php-gettext

You will be prompted for few configuration options. At first, it will ask to choose web server as following screenshot. Select Apache by click on OK button.

install command

Next, you will be ask to use dbconfig-common to configure the database for phpMyAdmin. Select Yes and hit Enter key to continue.

Configuration

Now enter password for phpMyAdmin to register with the database, select OK and press Enter.

set password

Again, you will be prompted to confirm the password by entering same password and hit on OK button.

Confirm Password phpMyAdmin

Next, you need to enable php-mbstring extension by typing below command:

sudo phpenmod php-mbstring

After that, you need to restart Apache to take effect of your configuration changes by typing:

sudo systemctl restart apache2

Creating MySQL User and Set Privileges#

In Ubuntu systems, the root MySQL user is using the auth_socket plugin by default to authenticate. It means that you can’t authenticate as a root by providing a password. This will increase some greater security and usability in many cases, but it can also complicate when you need to allow an external program like phpMyAdmin.

In order to log in to phpMyAdmin as your root MySQL user, you will need to switch its authentication method from auth_socket to mysql_native_password. It will not be good to change authentication method for the MySQL root user. Since phpMyAdmin requires users to authenticate with a password, so instead of changing authentication method we will create a new administrative MySQL account in order to access the interface. This user will have the same privileges as the root user and will be set to use the mysql_native_password authentication method.

Now, we will use that user to login to phpMyAdmin and do further administrative tasks on our MySQL or MariaDB server.

You can login by below command:

sudo mysql

Next, create a new administrative user with strong password and grant appropriate permissions by typing:

mysql> CREATE USER 'newadmin'@'localhost' IDENTIFIED BY 'STRONG-PASSWORD';
mysql> GRANT ALL PRIVILEGES ON . TO 'newadmin'@'localhost' WITH GRANT OPTION;

Accessing phpMyAdmin#

To access the phpMyAdmin interface open web browser and type your server’s public IP address or domain name followed by /phpmyadmin:

https://IP_ADDRESS_OR_YOUR_DOMAIN/phpmyadmin
phpMyAdmin Login page

Enter the administrative account username and password which you created on previous step and hit on Go button.

After successful log in, you’ll see the phpMyAdmin user interface, which will look something like this:

dashboard

Securing phpMyAdmin#

Generally, phpMyAdmin is a popular target for attackers, so we can add extra security layer to make phpMyAdmin directory password protected by setting up a basic authentication.

At First, we will create a password file with user using the htpasswd tool that comes with the Apache package. We will store the .htpasswd file in /etc/phpmyadmin directory:

sudo htpasswd -c /etc/phpmyadmin/.htpasswd newadmin

Here, newadmin is administrative username which we created for access phpMyAdmin interface. You can choose any user name of your choice. Once you execute above command it will prompt you to enter password and confirm password as below:

New password:
Re-type new password:
Adding password for user newadmin

Now we will configure Apache to password protect the phpMyAdmin directory and use the .htpasswd file. To do it open phpmyadmin.conf by typing :

sudo nano /etc/apache2/conf-available/phpmyadmin.conf

Make changes as following:

<Directory /usr/share/phpmyadmin>
    Options  +FollowSymLinks +Multiviews +Indexes  # change this line
    DirectoryIndex index.php

    # Add new line start
    AllowOverride None
    AuthType basic
    AuthName "Authentication Required"
    AuthUserFile /etc/phpmyadmin/.htpasswd
    Require valid-user
    # Add new line end

    <IfModule mod_php5.c>
    ...

After that, Save and close the file. To take effect restart the Apache service by type:

sudo systemctl restart apache2

Now, when you access your phpMyAdmin subdirectory, you will be prompt for the additional account name and password that you just configured:

https://ip_address_or_your_domain/phpmyadmin
login box

Once you will enter basic authentication details then only you will be taken to the phpMyAdmin login page where you need to enter your MySQL administrative user login credentials.

Conclusion#

Finally, you have successfully installed phpMyAdmin with Apache on Ubuntu 18.04 system. If you have any question feel free to leave a comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article Secure Nginx with Let’s Encrypt on CentOS 7
Next Article   How to Install Nginx on Debian 9 Server

Related Posts

  • How to Install and Use PHP Composer on Ubuntu 22.04

    How to Install Composer on Ubuntu 22.04

    January 31, 2023
  • How to Install Nginx on Ubuntu 22.04

    How to Install Nginx on Ubuntu 22.04

    January 28, 2023
  • How to Install Puppet Agent on Ubuntu 22.04

    How to Install Puppet Agent on Ubuntu 22.04

    January 22, 2023

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install SSH Keys on Ubuntu 22.04
    How to Set up SSH Keys on Ubuntu 22.04 January 7, 2023
  • How to Install Mongodb on Debian 11
    How to Install MongoDB on Debian 11 Linux January 11, 2023
  • How to Install Puppet Agent on Ubuntu 22.04
    How to Install Puppet Agent on Ubuntu 22.04 January 22, 2023
  • How to Install Jenkins on Debian 11
    How to Install Jenkins on Debian 11 January 5, 2023
  • How to Change-Hostname Ubuntu 22.04
    How to Change Hostname on Ubuntu 22.04 January 19, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook