arrow_upward

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Easy phpMyAdmin Installation On Linux
#1
Easy phpMyAdmin Installation On Linux
[Image: tkpP9Xw.png]


Howdy Post4VPS!

Welcome to another Post4VPS user request based tutorial for the command-line installation of software and applications on Linux servers. In this guide I will teach you how to easily install the phpMyAdmin web application on your Linux based server with a web server, PHP and a MySQL based database server. If you want to know how to install a web server with PHP and MariaDB you can take a look at the following instructions: Host Your Own WP Blog Using Debian 10, Nginx, PHP 8 & MariaDB. A small additional information: phpMyAdmin is a web application that is meant to be downloaded, unzipped and used after a bit of configuration. Therefore I highly recommend to install it from the official source and always use the latest available version. Don't rely on the phpMyAdmin software packages that you can install via package managers in Linux distributions! This way wou will have the latest phpMyAdmin and thus will lower the risk of opening security holes in your web hosting stack. Also keep in mind to always update to the latest phpMyAdmin version afterwards!

This tutorial will NOT cover the following points: a) how to install and configure a web server like Apache or Nginx, b) how to install and configure PHP (e.g. PHP 8) and c) how to install and configure a MySQL database server like MariaDB. You can use the previously linked guide to learn how to do that based on Nginx, PHP 8 and MariaDB. Other kind of setups using different web servers and / or database servers can be found in this forum or all around the web. Additionally this tutorial will not include steps that may help you to secure your phpMyAdmin installation. This is due to different web servers offering different ways to secure it. This subject alone would be worth a dedicated standalone tutorial (in my opinion at least).

Below is the setup I'm going to use during this tutorial:
  • Intel Pentium N4200 4x 2.4 GHz
  • 4 GB DDR4 2400 MHz RAM
  • 64 GB eMMC Flash Storage
  • Debian "Buster" 10 64 Bit
  • Nginx Stable 1.20
  • PHP 8.0
  • MariaDB 10.5

This is the very same server that I used when I created the previous guide that I linked above. It serves well as an example system to perform a phpMyAdmin installation to make the management of databases easier. Although you may know that I'm not a big of of any kind of control panels, I admin that I'm happily using phpMyAdmin when necessary to quickly create users, databases or perform other operations like database optimization or backups. However, I strongly recommend to secure any phpMyAdmin installation by mainly limiting access to it to a certain set of IP addresses (and as mentioned before: always keep it up-to-date!).



Before we start with the main parts of the guide I have some additional information for you.


Easy is not very easy
- In the past the installation of phpMyAdmin basically used to be very easy. It was mainly: a) download the latest version, unzip the latest version and c) adjust a little part of the configuration file. After this three main steps it was basically ready to go. New security measures introduced by MySQL and thus MySQL based database servers require some more work now. The main necessity is the creation of a dedicated database user with full administration rights that can be used in phpMyAdmin for any administrative operations. Earlier it was possible to simply use the root user but this has been disabled to increase security.

Different web hosting stacks require different phpMyAdmin versions
- Certain parts of web hosting stacks such as the PHP version and MySQL server version dictate which phpMyAdmin version you can use or rather said need to use to have a working instance of phpMyAdmin running. So be careful here and watch out what kind of software versions you are using and which phpMyAdmin version you need. I will only mention it this time and no other time during the whole tutorial. Example if you have PHP 8.0 and MySQL 5.5 or MariaDB you need to get the latest stable version 5.1.0 of phpMyAdmin. The older but still supported version (security fixes only) 4.9.7 will not work with PHP 8.0.
- PHP 7.1 and newer and MySQL/MariaDB 5.5 and newer -> phpMyAdmin 5.1.0.
- PHP 5.5 to 7.4 and MySQL/MariaDB 5.5 and newer -> phpMyAdmin 4.9.7.

No phpMyAdmin software packages from Linux distribution package managers
- As mentioned before we will not be using phpMyAdmin software packages that can be installed by package managers coming with Linux distributions like apt, yum or similar. Most are out of date and are only tailored to web hosting stack software version that are also available by default through the package managers on the Linux distributions. As easy as that would make it to install phpMyAdmin it's simply not the right way where you will learn how to install it yourself and it most likely will not compatible with different web hosting stacks (e.g. might only work with Apache installed by the package manager but will not work with Nginx).



Prerequisites

First we will install a few necessary tools via apt. To do that first connect to your server and login (best would be to login as root or a user with sudo access as you will need administrative permissions to run some of the commands).

Run the following command in your terminal as root or a user with sudo access (remember to add sudo before the command) to install the necessary tools:
apt-get install wget nano ca-certificates tar gzip -y

The command will install the CLI downloader "wget", the CLI text editor "nano", the TLS CA certificate base (to download from HTTPS links without certificate errors) and the archive management tool tar + gzip for tar and gunzip archives.



phpMyAdmin MySQL Administration User

Next step before the phpMyAdmin installation is the creation of the necessary MySQL administration user that you can use in phpMyAdmin instead of the MySQL root user.

Start the MySQL CLI management console as the MySQL root user:
mysql -u root -p
(Enter your MySQL root password when prompted.)

Create a new user that will become the administrator:
CREATE USER 'pmaadmin'@'localhost' IDENTIFIED BY 'mypassword123';
(I'll use pmaadmin as the username. Remember to adjust it to your liking and also set your own password instead of mypassword123.)

Grant all permissions to all databases and also special permission to the new user:
GRANT ALL PRIVILEGES ON *.* TO 'pmaadmin'@'localhost' WITH GRANT OPTION;

Reload all user privileges:
FLUSH PRIVILEGES;

Exit the MySQL CLI tool:
exit
(Remember to adjust the username to yours!)

You now have a MySQL user that basically has a lot of power over the database server. It is like the MySQL root user. You will use this use to login in phpMyAdmin when you need to create a new user/database or do other administrative tasks.



phpMyAdmin Installation

Now we can finally perform the phpMyAdmin installation.

Change your directory to the folder containing your website (where you want to install phpMyAdmin):
cd /var/www/hiddenrefuge.eu.org
(Adjust the path to your own website on your own web hosting stack.)

Download the latest version that is compatible with your web hosting stack. You can get the download links on this page. Take the download link for the archive file ending with tar.gz.
wget https://files.phpmyadmin.net/phpMyAdmin/5.1.0/phpMyAdmin-5.1.0-all-languages.tar.gz
(Here you would use the link for the correct and latest version.)

Extract the downloaded phpMyAdmin archive:
tar -zxvf phpMyAdmin-5.1.0-all-languages.tar.gz
(Here you should use the file name of the version you downloaded.)

You will now have a folder called like the archive name (without .tar.gz). Rename this folder to a easier to remember name:
mv phpMyAdmin-5.1.0-all-languages sqlmgmt
(Here you should use the folder name of your version and your new wish name for the folder. Make it something not so obvious to prevent bots trying to look for phpMyAdmin - so AVOID calling the folder pma or phpmyadmin/phpMyAdmin!)

You can now remove the downloaded tar.gz archive:
rm -rf phpMyAdmin-5.1.0-all-languages.tar.gz
(Here you should use the file name of the version you downloaded.)

Set correct ownership/permissions for the phpMyAdmin folder:
chown -R nginx:nginx /var/www/hiddenrefuge.eu.org/sqlmgmt
(Here you should adjust the user and group to the one you use for the web server and PHP processes. Additionally remember to adjust the path to your phpMyAdmin folder.)

To verify that you can access phpMyAdmin and it works (not displaying any kind of errors or something) should open the phpMyAdmin instance on your website in a web browser.

You should see this page:
[Image: pBApgyV.png]


phpMyAdmin Configuration

After the phpMyAdmin installation it is necessary to configure a few things or else you will not be able to use phpMyAdmin properly.

Change directory in to your phpMyAdmin folder:
cd /var/www/hiddenrefuge.eu.org/sqlmgmt
(Adjust the path to your phpMyAdmin installation.)

Rename the sample configuration file to the main configuration file name:
mv config.sample.inc.php config.inc.php

Open the configuration file with nano:
nano /var/www/hiddenrefuge.eu.org/sqlmgmt/config.inc.php
(Adjust the path to your phpMyAdmin installation.)

Go to this page and generate yourself a new blowfish secret.

Inside your configuration file replace
Quote:$cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

With the new configuration line with your blowfish secret from the page, e.g.:
Quote:$cfg['blowfish_secret'] = 'MN66UsUnxf,uVql{Dt1uzCE[cnE5M6Rb';
(Don't use the blowfish secret from the example above! Get your own from the page that I linked to above.)

Save the file with CTRL + O and ENTER. Exit the nano text editor with CTRL + X.

This is about it in terms of the configuration of phpMyAdmin.


Getting started with phpMyAdmin

Now navigate to your phpMyAdmin installation on your website via web browser and try to login with the user that you created during the phpMyAdmin MySQL Administration User setup step.

[Image: m39NtjU.png]

If everything went well you should be in and it should look like this:
[Image: kGhTppC.png]

Do you see the warning message at the bottom of the screenshot? You need to do a little something to fix this issue.

Go to http://hiddenrefuge.eu.org/sqlmgmt/index...-relations in your web browser. Remember to adjust the part before "index.php?route=/check-relations" to the web address of your phpMyAdmin installation.

You will see the error below:
[Image: MGIommv.png8]

To fix this click on the blue "Create" link. This will generate a databse called phpmyadmin where phpMyAdmin will store its own configuration changes and settings.

After that you can go back to the main page of phpMyAdmin and the warning message should be gone.


That's all folks! You now have installed phpMyAdmin. To update it you would simply download the latest version and overwrite all files. The configuration files config.inc.php will remain unchanged. After overwritting the files you also have to set the ownership/permission again. You would basically simply repeat the phpMyAdmin Installation part with a newer version.
[Image: zHHqO5Q.png]
#2
Thank you for this resource, this is definitely way more detailed that what I outlined in my tutorial. One thing I've learned also is to restrict access by IP so that folks cannot brute force into your PHPMyAdmin, which is unlikely, but it can happen.
Thank you to CubeData and Posts4VPS for the services of VPS 8.
#3
Hello @Mashiro
I have phpmyadmin with mysql for some project database. no webpage installed yet. 
when i login to phpmyadmin i got some error message tabs. like bellow. 

   


What is the reason of those errors and how to fix it?
Heart LOVE FOR ALL  HATRED FOR NONE Heart
#4
@sagher

Given the error message I assume that you didn't follow this tutorial and installed phpMyAdmin using a different installation method? Anyway.


Method #1

Open your config.inc.php phpMyAdmin configuration file inside your phpMyAdmin installation folder.

Find the following code block:
Quote:/* User used to manipulate with storage */
// $cfg['Servers'][$i]['controlhost'] = '';
// $cfg['Servers'][$i]['controlport'] = '';
// $cfg['Servers'][$i]['controluser'] = 'pma';
// $cfg['Servers'][$i]['controlpass'] = 'pmapass';

/* Storage database and tables */
// $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
// $cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
// $cfg['Servers'][$i]['relation'] = 'pma__relation';
// $cfg['Servers'][$i]['table_info'] = 'pma__table_info';
// $cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
// $cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
// $cfg['Servers'][$i]['column_info'] = 'pma__column_info';
// $cfg['Servers'][$i]['history'] = 'pma__history';
// $cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
// $cfg['Servers'][$i]['tracking'] = 'pma__tracking';
// $cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
// $cfg['Servers'][$i]['recent'] = 'pma__recent';
// $cfg['Servers'][$i]['favorite'] = 'pma__favorite';
// $cfg['Servers'][$i]['users'] = 'pma__users';
// $cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
// $cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
// $cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
// $cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';
// $cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
// $cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';

Comment this whole code block by adding "//" at the beginning of every line that belongs to the code block. So it looks like in the quote above.

Save the file, reload phpMyAdmin and the error should be gone.


Method #2

Fix the actual issue with your control user.

The configuration of the phpMyAdmin control user is above. There you need to provide MySQL login information for a simple user that has access to a phpMyAdmin control database. That control database needs to be created using a specific schema provided by phpMyAdmin somewhere in its files.

Everything can be configured in the code block that you see in method #1.

Not sure how up-to-date this reply is but it is basically what you need to do: https://stackoverflow.com/a/11506495


My two cents: method #1 is the easier way. The whole phpMyAdmin control user and database is by default disabled anyway when you just install phpMyAdmin straight from the source using my guide. phpMyAdmin works without this feature being enabled.
[Image: zHHqO5Q.png]
#5
Brilliant tutorial again @Mashiro  No steps missed.  I sailed through it perfectly. My phpmyadmin is working as it should and also looked exactly as in your examples every step of the way. Many many thanks for posting it.

In the weeks preceding your first tutorial for LEMP + WP, while I was trying a great number of tutorials on the Web you can't imagine the inquiries on the Web for why phpmyadmin wouldn't work. Right from LAMP to LEMP, there were so many issues.  I couldn't make it work either.

My main issue was "chown" and I now see why it wouldn't work.  And then the configuration afterwards.  I haven't come across a single reply to the inquiries that included a suggestion for additional configuration.  

Again many thanks for this great tutorial.  With the detailed explanations behind all of the steps I feel completely empowered as I have a much greater understanding for how it works.  Like matching the Database Version with the PHPmyAdmin version - that also didn't come up before and I think must be one other large reason for phpmyadmin not working before.   Cool



I've just thought of something. If one has more than one Website on the VPS, i.e. two URLs instead of the main one. Is there a way that phpmyadmin can include databases from other URL's on the same VPS? Or does one need to create a phpmyadmin for each URL?
Terminal
Thank you to Post4VPS and VirMach for my awesome VPS 9!  
#6
@deanhills

Great to hear your positive feedback and that you had absolutely no issue on your server when following this guide.


deanhills Wrote:I've just thought of something. If one has more than one Website on the VPS, i.e. two URLs instead of the main one. Is there a way that phpmyadmin can include databases from other URL's on the same VPS? Or does one need to create a phpmyadmin for each URL?

phpMyAdmin is a general MySQL database management system that can manage all databases on the whole server. There is no need to install a new instance everytime you add a new website to the server. That would be pointless waste of disk space and a unnecessary workload for yourself with keeping things running and up-to-date.
[Image: zHHqO5Q.png]
#7
(05-27-2021, 06:16 AM)Mashiro Wrote: @sagher

Given the error message I assume that you didn't follow this tutorial and installed phpMyAdmin using a different installation method? Anyway.


Method #1

Open your config.inc.php phpMyAdmin configuration file inside your phpMyAdmin installation folder.

Find the following code block:

Comment this whole code block by adding "//" at the beginning of every line that belongs to the code block. So it looks like in the quote above.

Save the file, reload phpMyAdmin and the error should be gone.


Method #2

Fix the actual issue with your control user.

The configuration of the phpMyAdmin control user is above. There you need to provide MySQL login information for a simple user that has access to a phpMyAdmin control database. That control database needs to be created using a specific schema provided by phpMyAdmin somewhere in its files.

Everything can be configured in the code block that you see in method #1.

Not sure how up-to-date this reply is but it is basically what you need to do: https://stackoverflow.com/a/11506495


My two cents: method #1 is the easier way. The whole phpMyAdmin control user and database is by default disabled anyway when you just install phpMyAdmin straight from the source using my guide. phpMyAdmin works without this feature being enabled.

If i reinstall the package by giving your command lines. then is this automatically fix the errors or i go for the manual edit methods? 
i dont need mariadb because the database which i like to run is based on mysql.
i have php 7.0 and php 7.2, 
and mysql  Ver 14.14 Distrib 5.7.34, for Linux (x86_64) using  EditLine wrapper 
and a user created as a root user in mysql of phpmyadmin. 
i wish to ask about database files. if i reinstall phpmyadmin then all connected files users databases are gone. right?
Heart LOVE FOR ALL  HATRED FOR NONE Heart
#8
@sagher

Simply try method #1 first and see what it brings. It should be the fix for this warning messages.

If you reinstall phpMyAdmin the database server remains untouched unless you, for whatever reason, decide to reinstall your database server while reinstalling phpMyAdmin (which is totally unnecessary).

If you don't know what you are doing and are too afraid to break things you should DO NOTHING and ask someone direct help.
[Image: zHHqO5Q.png]



person_pin_circle Users browsing this thread: 1 Guest(s)
Sponsors: VirMach - Host4Fun - CubeData - Evolution-Host - HostDare - Hyper Expert - Shadow Hosting - Bladenode - Hostlease - RackNerd - ReadyDedis - Limitless Hosting