{"id":16967,"date":"2023-11-03T09:33:28","date_gmt":"2023-11-03T09:33:28","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=16967"},"modified":"2023-11-03T09:33:30","modified_gmt":"2023-11-03T09:33:30","slug":"how-to-install-and-secure-phpmyadmin-on-ubuntu-22-04","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2023\/11\/03\/how-to-install-and-secure-phpmyadmin-on-ubuntu-22-04\/","title":{"rendered":"How To Install and Secure phpMyAdmin on Ubuntu 22.04"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"357\" src=\"https:\/\/www.appservgrid.com\/paw92\/wp-content\/uploads\/2023\/11\/image-3.png\" alt=\"\" class=\"wp-image-16968\" srcset=\"https:\/\/www.appservgrid.com\/paw92\/wp-content\/uploads\/2023\/11\/image-3.png 750w, https:\/\/www.appservgrid.com\/paw92\/wp-content\/uploads\/2023\/11\/image-3-300x143.png 300w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"introduction\"><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-and-secure-phpmyadmin-on-ubuntu-22-04#introduction\"><strong>Introduction<\/strong><\/a><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-and-secure-phpmyadmin-on-ubuntu-22-04#introduction\"><\/a><\/h3>\n\n\n\n<p>While many users need the functionality of a database management system like MySQL, they may not feel comfortable interacting with the system solely from the MySQL prompt.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.phpmyadmin.net\/\">phpMyAdmin<\/a>&nbsp;was created so that users can interact with MySQL through a web interface. In this guide, we\u2019ll discuss how to install and secure phpMyAdmin so that you can safely use it to manage your databases on an Ubuntu 22.04 system.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"prerequisites\"><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-and-secure-phpmyadmin-on-ubuntu-22-04#prerequisites\"><strong>Prerequisites<\/strong><\/a><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-and-secure-phpmyadmin-on-ubuntu-22-04#prerequisites\"><\/a><\/h2>\n\n\n\n<p>In order to complete this guide, you will need:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>An Ubuntu 22.04 server. This server should have a non-root user with administrative privileges and a firewall configured with&nbsp;<code>ufw<\/code>. To set this up, follow our&nbsp;<a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/initial-server-setup-with-ubuntu-22-04\">initial server setup guide for Ubuntu 22.04<\/a>.<\/li>\n\n\n\n<li>A LAMP (Linux, Apache, MySQL, and PHP) stack installed on your Ubuntu 22.04 server. If this is not completed yet, you can follow this guide on&nbsp;<a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-22-04\">installing a LAMP stack on Ubuntu 22.04<\/a>.<\/li>\n<\/ul>\n\n\n\n<p>Additionally, there are important security considerations when using software like phpMyAdmin, since it:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Communicates directly with your MySQL installation<\/li>\n\n\n\n<li>Handles authentication using MySQL credentials<\/li>\n\n\n\n<li>Executes and returns results for arbitrary SQL queries<\/li>\n<\/ul>\n\n\n\n<p>For these reasons, and because it is a widely-deployed PHP application which is frequently targeted for attack, you should never run phpMyAdmin on remote systems over a plain HTTP connection.<\/p>\n\n\n\n<p>If you do not have an existing domain configured with an SSL\/TLS certificate, you can follow this guide on&nbsp;<a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-22-04\">securing Apache with Let\u2019s Encrypt on Ubuntu 22.04<\/a>. This will require you to&nbsp;<a href=\"https:\/\/docs.digitalocean.com\/tutorials\/dns-registrars\/\">register a domain name<\/a>,&nbsp;<a href=\"https:\/\/www.digitalocean.com\/docs\/networking\/dns\/\">create DNS records for your server<\/a>, and&nbsp;<a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-the-apache-web-server-on-ubuntu-22-04#step-5-setting-up-virtual-hosts-recommended\">set up an Apache Virtual Host<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-1-installing-phpmyadmin\"><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-and-secure-phpmyadmin-on-ubuntu-22-04#step-1-installing-phpmyadmin\"><strong>Step 1 \u2014 Installing phpMyAdmin<\/strong><\/a><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-and-secure-phpmyadmin-on-ubuntu-22-04#step-1-installing-phpmyadmin\"><\/a><\/h2>\n\n\n\n<p>You can use APT to install phpMyAdmin from the default Ubuntu repositories.<\/p>\n\n\n\n<p>As your non-root sudo user, update your server\u2019s package index if you haven\u2019t done so recently:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\n<\/code><\/pre>\n\n\n\n<p>Following that you can install the&nbsp;<code>phpmyadmin<\/code>&nbsp;package. Along with this package, the&nbsp;<a href=\"https:\/\/docs.phpmyadmin.net\/en\/latest\/require.html\">official documentation also recommends<\/a>&nbsp;that you install a few PHP extensions onto your server to enable certain functionalities and improve performance.<\/p>\n\n\n\n<p>If you followed the prerequisite&nbsp;<a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-22-04\">LAMP stack tutorial<\/a>, several of these modules will have been installed along with the&nbsp;<code>php<\/code>&nbsp;package. However, it\u2019s recommended that you also install these packages:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>php-mbstring<\/code>: A module for managing non-ASCII strings and convert strings to different encodings<\/li>\n\n\n\n<li><code>php-zip<\/code>: This extension supports uploading&nbsp;<code>.zip<\/code>&nbsp;files to phpMyAdmin<\/li>\n\n\n\n<li><code>php-gd<\/code>: Enables support for the&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/GD_Graphics_Library\">GD Graphics Library<\/a><\/li>\n\n\n\n<li><code>php-json<\/code>: Provides PHP with support for JSON serialization<\/li>\n\n\n\n<li><code>php-curl<\/code>: Allows PHP to interact with different kinds of servers using different protocols<\/li>\n<\/ul>\n\n\n\n<p>Run the following command to install these packages onto your system. Please note, though, that the installation process requires you to make some choices to configure phpMyAdmin correctly. We\u2019ll walk through these options shortly:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl\n<\/code><\/pre>\n\n\n\n<p>Here are the options you should choose when prompted in order to configure your installation correctly:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>For the server selection, choose&nbsp;<code>apache2<\/code><\/li>\n<\/ul>\n\n\n\n<p><strong>Warning:<\/strong>&nbsp;When the prompt appears, \u201capache2\u201d is highlighted, but&nbsp;<strong>not<\/strong>&nbsp;selected. If you do not hit&nbsp;<code>SPACE<\/code>&nbsp;to select Apache, the installer&nbsp;<strong>will not<\/strong>&nbsp;move the necessary files during installation. Hit&nbsp;<code>SPACE<\/code>,&nbsp;<code>TAB<\/code>, and then&nbsp;<code>ENTER<\/code>&nbsp;to select Apache.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Select&nbsp;<code>Yes<\/code>&nbsp;when asked whether to use&nbsp;<code>dbconfig-common<\/code>&nbsp;to set up the database<\/li>\n\n\n\n<li>You will then be asked to choose and confirm a MySQL application password for phpMyAdmin<\/li>\n<\/ul>\n\n\n\n<p><strong>Note<\/strong>: Assuming you installed MySQL by following&nbsp;<a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-22-04#step-2-configuring-mysql\">Step 2 of the prerequisite LAMP stack tutorial<\/a>, you may have decided to enable the Validate Password plugin. As of this writing, enabling this component will trigger an error when you attempt to set a password for the&nbsp;<strong>phpmyadmin<\/strong>&nbsp;user:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/assets.digitalocean.com\/articles\/phpmyadmin_2004\/pma_vpp_error.png\" alt=\"phpMyAdmin password validation error\"\/><\/figure>\n\n\n\n<p>To resolve this, select the&nbsp;<strong>abort<\/strong>&nbsp;option to stop the installation process. Then, open up your MySQL prompt:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mysql\n<\/code><\/pre>\n\n\n\n<p>Or, if you enabled password authentication for the&nbsp;<strong>root<\/strong>&nbsp;MySQL user, run this command and then enter your password when prompted:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -u root -p\n<\/code><\/pre>\n\n\n\n<p>From the prompt, run the following command to disable the Validate Password component. Note that this won\u2019t actually uninstall it, but just stop the component from being loaded on your MySQL server:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>UNINSTALL COMPONENT \"file:\/\/component_validate_password\";\n<\/code><\/pre>\n\n\n\n<p>Following that, you can close the MySQL client:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>exit\n<\/code><\/pre>\n\n\n\n<p>Then try installing the&nbsp;<code>phpmyadmin<\/code>&nbsp;package again and it will work as expected:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install phpmyadmin\n<\/code><\/pre>\n\n\n\n<p>Once phpMyAdmin is installed, you can open the MySQL prompt once again with&nbsp;<code>sudo mysql<\/code>&nbsp;or&nbsp;<code>mysql -u root -p<\/code>&nbsp;and then run the following command to re-enable the Validate Password component:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>INSTALL COMPONENT \"file:\/\/component_validate_password\";\n<\/code><\/pre>\n\n\n\n<p>The installation process adds the phpMyAdmin Apache configuration file into the&nbsp;<code>\/etc\/apache2\/conf-enabled\/<\/code>&nbsp;directory, where it is read automatically. To finish configuring Apache and PHP to work with phpMyAdmin, the only remaining task in this section of the tutorial is to is explicitly enable the&nbsp;<code>mbstring<\/code>&nbsp;PHP extension, which you can do by typing:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo phpenmod mbstring\n<\/code><\/pre>\n\n\n\n<p>Afterwards, restart Apache for your changes to be recognized:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart apache2\n<\/code><\/pre>\n\n\n\n<p>phpMyAdmin is now installed and configured to work with Apache. However, before you can log in and begin interacting with your MySQL databases, you will need to ensure that your MySQL users have the privileges required for interacting with the program.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-2-adjusting-user-authentication-and-privileges\"><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-and-secure-phpmyadmin-on-ubuntu-22-04#step-2-adjusting-user-authentication-and-privileges\"><strong>Step 2 \u2014 Adjusting User Authentication and Privileges<\/strong><\/a><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-and-secure-phpmyadmin-on-ubuntu-22-04#step-2-adjusting-user-authentication-and-privileges\"><\/a><\/h2>\n\n\n\n<p>When you installed phpMyAdmin onto your server, it automatically created a database user called&nbsp;<strong>phpmyadmin<\/strong>&nbsp;which performs certain underlying processes for the program. Rather than logging in as this user with the administrative password you set during installation, it\u2019s recommended that you log in as either your&nbsp;<strong>root<\/strong>&nbsp;MySQL user or as a user dedicated to managing databases through the phpMyAdmin interface.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"configuring-password-access-for-the-mysql-root-account\"><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-and-secure-phpmyadmin-on-ubuntu-22-04#configuring-password-access-for-the-mysql-root-account\"><strong>Configuring Password Access for the MySQL Root Account<\/strong><\/a><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-and-secure-phpmyadmin-on-ubuntu-22-04#configuring-password-access-for-the-mysql-root-account\"><\/a><\/h3>\n\n\n\n<p>In Ubuntu systems running MySQL 5.7 (and later versions), the&nbsp;<strong>root<\/strong>&nbsp;MySQL user is set to authenticate using the&nbsp;<code>auth_socket<\/code>&nbsp;plugin by default rather than with a password. This allows for some greater security and usability in many cases, but it can also complicate things when you need to allow an external program \u2014 like phpMyAdmin \u2014 to access the user.<\/p>\n\n\n\n<p>In order to log in to phpMyAdmin as your&nbsp;<strong>root<\/strong>&nbsp;MySQL user, you will need to switch its authentication method from&nbsp;<code>auth_socket<\/code>&nbsp;to one that makes use of a password, if you haven\u2019t already done so. To do this, open up the MySQL prompt from your terminal:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mysql\n<\/code><\/pre>\n\n\n\n<p>Next, check which authentication method each of your MySQL user accounts use with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT user,authentication_string,plugin,host FROM mysql.user;\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Output+------------------+------------------------------------------------------------------------+-----------------------+-----------+\n| user             | authentication_string                                                  | plugin                | host      |\n+------------------+------------------------------------------------------------------------+-----------------------+-----------+\n| debian-sys-maint | $A$005$I:jOry?]Sy&lt;|qhQRj3fBRQ43i4UJxrpm.IaT6lOHkgveJjmeIjJrRe6         | caching_sha2_password | localhost |\n| mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | localhost |\n| mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | localhost |\n| mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | localhost |\n| phpmyadmin       | $A$005$?#{Z?`gN!c2az)}V-INCWXSuVdqB9zWteH1IkZfTe\/rOLgVhSzEMM9R3G6K9    | caching_sha2_password | localhost |\n| root             |                                                                        | auth_socket           | localhost |\n+------------------+------------------------------------------------------------------------+-----------------------+-----------+\n6 rows in set (0.00 sec)\n<\/code><\/pre>\n\n\n\n<p>This example output indicates that the&nbsp;<strong>root<\/strong>&nbsp;user does in fact authenticate using the&nbsp;<code>auth_socket<\/code>&nbsp;plugin. To configure the&nbsp;<strong>root<\/strong>&nbsp;account to authenticate with a password, run the following&nbsp;<code>ALTER USER<\/code>&nbsp;command. Be sure to change&nbsp;<code><mark>password<\/mark><\/code>&nbsp;to a strong password of your choosing:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '<mark>password<\/mark>';\n<\/code><\/pre>\n\n\n\n<p><strong>Note<\/strong>: The previous&nbsp;<code>ALTER USER<\/code>&nbsp;statement sets the&nbsp;<strong>root<\/strong>&nbsp;MySQL user to authenticate with the&nbsp;<code>caching_sha2_password<\/code>&nbsp;plugin.&nbsp;<a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/upgrading-from-previous-series.html#upgrade-caching-sha2-password\">Per the official MySQL documentation<\/a>,&nbsp;<code>caching_sha2_password<\/code>&nbsp;is MySQL\u2019s preferred authentication plugin, as it provides more secure password encryption than the older, but still widely used,&nbsp;<code>mysql_native_password<\/code>.<\/p>\n\n\n\n<p>However, some versions of PHP don\u2019t work reliably with&nbsp;<code>caching_sha2_password<\/code>.&nbsp;<a href=\"https:\/\/php.watch\/articles\/PHP-7.4-MySQL-8-server-gone-away-fix\">PHP has reported that this issue was fixed as of PHP 7.4<\/a>, but if you encounter an error when trying to log in to phpMyAdmin later on, you may want to set&nbsp;<strong>root<\/strong>&nbsp;to authenticate with&nbsp;<code>mysql_native_password<\/code>&nbsp;instead:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '<mark>password<\/mark>';\n<\/code><\/pre>\n\n\n\n<p>Then, check the authentication methods employed by each of your users again to confirm that&nbsp;<strong>root<\/strong>&nbsp;no longer authenticates using the&nbsp;<code>auth_socket<\/code>&nbsp;plugin:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT user,authentication_string,plugin,host FROM mysql.user;\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Output+------------------+------------------------------------------------------------------------+-----------------------+-----------+\n| user             | authentication_string                                                  | plugin                | host      |\n+------------------+------------------------------------------------------------------------+-----------------------+-----------+\n| debian-sys-maint | $A$005$I:jOry?]Sy&lt;|qhQRj3fBRQ43i4UJxrpm.IaT6lOHkgveJjmeIjJrRe6         | caching_sha2_password | localhost |\n| mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | localhost |\n| mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | localhost |\n| mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | localhost |\n| phpmyadmin       | $A$005$?#{Z?`gN!c2az)}V-INCWXSuVdqB9zWteH1IkZfTe\/rOLgVhSzEMM9R3G6K9    | caching_sha2_password | localhost |\n| root             | $A$005$3y\ufffdy|Z?'_&#91;} ZyVHuESVwNmjKWOH\/ndETwS.Kty0IH7UfiXjOfVvyWroy4a.   | caching_sha2_password | localhost |\n+------------------+------------------------------------------------------------------------+-----------------------+-----------+\n6 rows in set (0.00 sec)\n<\/code><\/pre>\n\n\n\n<p>This output shows that the&nbsp;<strong>root<\/strong>&nbsp;user will authenticate using a password. You can now log in to the phpMyAdmin interface as your&nbsp;<strong>root<\/strong>&nbsp;user with the password you\u2019ve set for it here.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"configuring-password-access-for-a-dedicated-mysql-user\"><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-and-secure-phpmyadmin-on-ubuntu-22-04#configuring-password-access-for-a-dedicated-mysql-user\"><strong>Configuring Password Access for a Dedicated MySQL User<\/strong><\/a><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-and-secure-phpmyadmin-on-ubuntu-22-04#configuring-password-access-for-a-dedicated-mysql-user\"><\/a><\/h3>\n\n\n\n<p>Alternatively, some may find that it better suits their workflow to connect to phpMyAdmin with a dedicated user. To do this, open up the MySQL shell once again:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mysql\n<\/code><\/pre>\n\n\n\n<p>If you have password authentication enabled for your&nbsp;<strong>root<\/strong>&nbsp;user, as described in the previous section, you will need to run the following command and enter your password when prompted in order to connect:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -u root -p\n<\/code><\/pre>\n\n\n\n<p>From there, create a new user and give it a strong password:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE USER '<mark>sammy<\/mark>'@'localhost' IDENTIFIED WITH caching_sha2_password BY '<mark>password<\/mark>';\n<\/code><\/pre>\n\n\n\n<p><strong>Note<\/strong>: Again, depending on what version of PHP you have installed, you may want to set your new user to authenticate with&nbsp;<code>mysql_native_password<\/code>&nbsp;instead of&nbsp;<code>caching_sha2_password<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER USER '<mark>sammy<\/mark>'@'localhost' IDENTIFIED WITH mysql_native_password BY '<mark>password<\/mark>';\n<\/code><\/pre>\n\n\n\n<p>Then, grant your new user appropriate privileges. For example, you could grant the user privileges to all tables within the database, as well as the power to add, change, and remove user privileges, with this command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>GRANT ALL PRIVILEGES ON *.* TO '<mark>sammy<\/mark>'@'localhost' WITH GRANT OPTION;\n<\/code><\/pre>\n\n\n\n<p>Following that, exit the MySQL shell:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>exit\n<\/code><\/pre>\n\n\n\n<p>You can now access the web interface by visiting your server\u2019s domain name or public IP address followed by&nbsp;<code>\/phpmyadmin<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>https:\/\/<mark>your_domain_or_IP<\/mark>\/phpmyadmin\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/assets.digitalocean.com\/articles\/phpmyadmin_2004\/pma_sammy_login_small.png\" alt=\"phpMyAdmin login screen\"\/><\/figure>\n\n\n\n<p>Log in to the interface, either as&nbsp;<strong>root<\/strong>&nbsp;or with the new username and password you just configured.<\/p>\n\n\n\n<p>When you log in, you\u2019ll be taken to phpMyAdmin\u2019s user interface:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/assets.digitalocean.com\/articles\/phpmyadmin_2204\/pma_home_sammy_2204.png\" alt=\"phpMyAdmin user interface\"\/><\/figure>\n\n\n\n<p>Now that you\u2019re able to connect and interact with phpMyAdmin, all that\u2019s left to do is harden your system\u2019s security to protect it from attackers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-3-securing-your-phpmyadmin-instance\"><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-and-secure-phpmyadmin-on-ubuntu-22-04#step-3-securing-your-phpmyadmin-instance\"><strong>Step 3 \u2014 Securing Your phpMyAdmin Instance<\/strong><\/a><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-and-secure-phpmyadmin-on-ubuntu-22-04#step-3-securing-your-phpmyadmin-instance\"><\/a><\/h2>\n\n\n\n<p>Because of its ubiquity, phpMyAdmin is a popular target for attackers, and you should take extra care to prevent unauthorized access. One way of doing this is to place a gateway in front of the entire application by using Apache\u2019s built-in&nbsp;<code>.htaccess<\/code>&nbsp;authentication and authorization functionalities.<\/p>\n\n\n\n<p>To do this, you must first enable the use of&nbsp;<code>.htaccess<\/code>&nbsp;file overrides by editing your phpMyAdmin installation\u2019s Apache configuration file.<\/p>\n\n\n\n<p>Use your preferred text editor to edit the&nbsp;<code>phpmyadmin.conf<\/code>&nbsp;file that has been placed in your Apache configuration directory. Here, we\u2019ll use&nbsp;<code>nano<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/apache2\/conf-available\/phpmyadmin.conf\n<\/code><\/pre>\n\n\n\n<p>Add an&nbsp;<code>AllowOverride All<\/code>&nbsp;directive within the&nbsp;<code>&lt;Directory \/usr\/share\/phpmyadmin&gt;<\/code>&nbsp;section of the configuration file, like this:<\/p>\n\n\n\n<p>\/etc\/apache2\/conf-available\/phpmyadmin.conf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;Directory \/usr\/share\/phpmyadmin&gt;\n    Options SymLinksIfOwnerMatch\n    DirectoryIndex index.php\n    <mark>AllowOverride All<\/mark>\n    . . .\n<\/code><\/pre>\n\n\n\n<p>When you have added this line, save and close the file. If you used&nbsp;<code>nano<\/code>&nbsp;to edit the file, do so by pressing&nbsp;<code>CTRL + X<\/code>,&nbsp;<code>Y<\/code>, and then&nbsp;<code>ENTER<\/code>.<\/p>\n\n\n\n<p>To implement the changes you made, restart Apache:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart apache2\n<\/code><\/pre>\n\n\n\n<p>Now that you have enabled the use of&nbsp;<code>.htaccess<\/code>&nbsp;files for your application, you need to create one to actually implement some security.<\/p>\n\n\n\n<p>In order for this to be successful, the file must be created within the application directory. You can create the necessary file and open it in your text editor with root privileges by typing:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/usr\/share\/phpmyadmin\/.htaccess\n<\/code><\/pre>\n\n\n\n<p>Within this file, enter the following information:<\/p>\n\n\n\n<p>\/usr\/share\/phpmyadmin\/.htaccess<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>AuthType Basic\nAuthName \"Restricted Files\"\nAuthUserFile \/etc\/phpmyadmin\/.htpasswd\nRequire valid-user\n<\/code><\/pre>\n\n\n\n<p>Here is what each of these lines mean:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>AuthType Basic<\/code>: This line specifies the authentication type that you are implementing. This type will implement password authentication using a password file.<\/li>\n\n\n\n<li><code>AuthName<\/code>: This sets the message for the authentication dialog box. You should keep this generic so that unauthorized users won\u2019t gain any information about what is being protected.<\/li>\n\n\n\n<li><code>AuthUserFile<\/code>: This sets the location of the password file that will be used for authentication. This should be outside of the directories that are being served. We will create this file shortly.<\/li>\n\n\n\n<li><code>Require valid-user<\/code>: This specifies that only authenticated users should be given access to this resource. This is what actually stops unauthorized users from entering.<\/li>\n<\/ul>\n\n\n\n<p>When you are finished, save and close the file.<\/p>\n\n\n\n<p>The location that you selected for your password file was&nbsp;<code>\/etc\/phpmyadmin\/.htpasswd<\/code>. You can now create this file and pass it an initial user with the&nbsp;<code>htpasswd<\/code>&nbsp;utility:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo htpasswd -c \/etc\/phpmyadmin\/.htpasswd <mark>username<\/mark>\n<\/code><\/pre>\n\n\n\n<p>You will be prompted to select and confirm a password for the user you are creating. Afterwards, the file is created with the hashed password that you entered.<\/p>\n\n\n\n<p>If you want to enter an additional user, you need to do so&nbsp;<strong>without<\/strong>&nbsp;the&nbsp;<code>-c<\/code>&nbsp;flag, like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo htpasswd \/etc\/phpmyadmin\/.htpasswd <mark>additionaluser<\/mark>\n<\/code><\/pre>\n\n\n\n<p>Then restart Apache to put&nbsp;<code>.htaccess<\/code>&nbsp;authentication into effect:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart apache2\n<\/code><\/pre>\n\n\n\n<p>Now, when you access your phpMyAdmin subdirectory, you will be prompted for the additional account name and password that you just configured:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>https:\/\/<mark>domain_name_or_IP<\/mark>\/phpmyadmin\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/assets.digitalocean.com\/articles\/phpmyadmin_2004\/pma_htaccess_small.png\" alt=\"phpMyAdmin apache password\"\/><\/figure>\n\n\n\n<p>After entering the Apache authentication, you\u2019ll be taken to the regular phpMyAdmin authentication page to enter your MySQL credentials. By adding an extra set of non-MySQL credentials, you\u2019re providing your database with an additional layer of security. This is desirable, since phpMyAdmin has been vulnerable to security threats in the past.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\"><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-and-secure-phpmyadmin-on-ubuntu-22-04#conclusion\"><strong>Conclusion<\/strong><\/a><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-and-secure-phpmyadmin-on-ubuntu-22-04#conclusion\"><\/a><\/h2>\n\n\n\n<p>You should now have phpMyAdmin configured and ready to use on your Ubuntu 22.04 server. Using this interface, you can create databases, users, and tables, as well as perform the usual operations like deleting and modifying structures and data.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-and-secure-phpmyadmin-on-ubuntu-22-04\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction While many users need the functionality of a database management system like MySQL, they may not feel comfortable interacting with the system solely from the MySQL prompt. phpMyAdmin&nbsp;was created so that users can interact with MySQL through a web interface. In this guide, we\u2019ll discuss how to install and secure phpMyAdmin so that you &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2023\/11\/03\/how-to-install-and-secure-phpmyadmin-on-ubuntu-22-04\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How To Install and Secure phpMyAdmin on Ubuntu 22.04&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-16967","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/16967","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=16967"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/16967\/revisions"}],"predecessor-version":[{"id":16969,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/16967\/revisions\/16969"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=16967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=16967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=16967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}