Install Phpmyadmin Ubuntu 18.04 Nginx


Install PhpMyAdmin Ubuntu 18.04 Nginx

What is PhpMyAdmin?

PhpMyAdmin is an open source software written in PHP that provides a graphical web-based interface for accessing and managing your MySQL or MariaDB databases running on the Ubuntu server. It is an ideal tool for managing databases on the go, as it is both powerful and easy to use. With a few clicks, users can easily create, edit, and delete databases and tables.

PhpMyAdmin supports a wide range of operations including data manipulation (insert, update, delete, order by), data import and export, administration of database users and their privileges, database backups, and a wide range of other operations.

The stable latest version of phpMyAdmin at the time of writing this article is 4.9.4. In this article, we will demonstrate how to install phpMyAdmin on an Ubuntu 18.04 server running the Nginx web server.

Prerequisites for Installing PhpMyAdmin on Ubuntu 18.04

Before you start with the tutorial, make sure you have the following requirements:

Step 1: Installing the Dependencies

The first step is to install the dependencies required for phpMyAdmin, including php5.6-mbstring. To do this, run the following command:

sudo apt-get update
sudo apt-get install php5.6-mbstring php-gettext

The commands will update the package lists and then install the packages, respectively.

Step 2: Installing phpMyAdmin

In order to install phpMyAdmin, first you need to download the latest stable version of it. To do this, run the following command:

wget https://files.phpmyadmin.net/phpMyAdmin/4.9.4/phpMyAdmin-4.9.4-english.tar.gz

Once the download is complete, extract it using the following command:

tar -xvzf phpMyAdmin-4.9.4-english.tar.gz

This will extract it into the phpMyAdmin directory. Now, you need to move this folder into the root web directory. To do so, run the following command:

sudo mv phpMyAdmin-4.9.4-english /usr/share/nginx/html/phpmyadmin

Once the folder has been moved, you need to give it the correct permissions so that the web server can access it:

sudo chown -R www-data:www-data /usr/share/nginx/html/phpmyadmin

Now, you can open phpMyAdmin in your browser. For this, go to http://server_IP_address/phpmyadmin in your browser, and you will be redirected to the phpMyAdmin login page.

Step 3: Configuring Nginx

Now, you need to configure the Nginx web server so that it can properly serve the phpMyAdmin files. To do this, you will have to create a new Nginx server block configuration file for phpMyAdmin:

sudo nano /etc/nginx/sites-available/phpmyadmin.conf

Add the following lines inside the file:

server {
listen 80;
server_name server_IP_address;

location / {
root /usr/share/nginx/html/phpmyadmin;
index index.php index.html index.htm;
}

location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

Save and close the file, then enable the phpMyAdmin server block with the following command:

sudo ln -s /etc/nginx/sites-available/phpmyadmin.conf /etc/nginx/sites-enabled/

Test the Nginx configuration and then restart Nginx for the changes to take effect:

sudo nginx -t
sudo systemctl restart nginx

Step 4: Configuring phpMyAdmin

Now, you need to configure phpMyAdmin to use the MySQL credentials for logging in. To do this, you need to copy the sample phpMyAdmin configuration file:

sudo cp /usr/share/nginx/html/phpmyadmin/config.sample.inc.php /usr/share/nginx/html/phpmyadmin/config.inc.php

Once the file has been copied, edit it:

sudo nano /usr/share/nginx/html/phpmyadmin/config.inc.php

At the bottom of the file, you need to add a line that defines the MySQL login credentials as follows:

$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['user'] = 'username';
$cfg['Servers'][$i]['password'] = 'username_password';

Save and close the file. Now, you can access phpMyAdmin in your web browser, and login using the credentials you just defined.

Conclusion

In this article, we have demonstrated how to install phpMyAdmin on an Ubuntu 18.04 server running the Nginx web server. We hope you have found this tutorial helpful. Thank you for reading.

Thank you for reading this article. We hope you found this article to be helpful. Feel free to check out other articles on our website to learn more about web hosting and server management.