How to Install and Set Up Adminer on VPS for Database Management

Adminer is a powerful and lightweight database management tool that allows you to easily manage databases like MySQL, PostgreSQL, SQLite, and others. It is a single PHP file, which makes it a perfect solution for those who prefer a simple, fast, and secure way to manage their databases from a web interface.

In this guide, we will walk you through the steps to install and set up Adminer on a VPS to manage your databases efficiently.


Prerequisites

Before you begin the installation, ensure the following:

  1. A VPS running Ubuntu 20.04 or later (This guide assumes Ubuntu; you can adapt the instructions for other distributions such as CentOS or Debian).
  2. Root or sudo access to your VPS.
  3. A web server (Apache or Nginx).
  4. PHP installed on your server (PHP 7.1 or later recommended).
  5. A working MySQL, MariaDB, PostgreSQL, or SQLite database (or any other supported database).

Step 1: Update Your VPS

To ensure your system packages are up to date, run the following commands:

  1. Update system packages:
     
    sudo apt update && sudo apt upgrade -y

Step 2: Install Apache, PHP, and Required Extensions

Adminer requires a web server (Apache) and PHP to run. Follow these steps to install them.

Install Apache

  1. Install Apache Web Server:

     
    sudo apt install apache2 -y
  2. Enable Apache to start on boot:

     
    sudo systemctl enable apache2
  3. Verify Apache Installation: Open your browser and navigate to your server's IP address. You should see the default Apache page. Alternatively, check Apache's status:

     
    sudo systemctl status apache2

Install PHP

Adminer requires PHP to function properly. Install PHP and the necessary extensions:

  1. Install PHP and extensions:

     
    sudo apt install php php-mbstring php-xml php-curl php-zip php-mysqli -y
  2. Verify PHP installation:

     
    php -v

Step 3: Download and Install Adminer

  1. Navigate to the Web Directory: The default web directory for Apache is /var/www/html. Navigate to it:

     
    cd /var/www/html
  2. Download Adminer: Adminer is a single PHP file, and you can download it directly using wget or curl. Run the following command to download the latest version of Adminer:

     
    sudo wget "https://www.adminer.org/latest.php" -O adminer.php
  3. Set Correct Permissions: Ensure that the file has the correct permissions for the Apache server to serve it:

     
    sudo chown www-data:www-data /var/www/html/adminer.php sudo chmod 755 /var/www/html/adminer.php

Step 4: Configure Apache for Adminer

Since Adminer is a single PHP file, you don't need to configure any complex settings for it. However, you may want to set up a custom domain or alias to access it more easily.

  1. Create an Apache Configuration File (Optional): If you want to use a custom alias (e.g., adminer.yourdomain.com), you can create an Apache virtual host configuration.

    Create a new file in the Apache sites-available directory:

     
    sudo nano /etc/apache2/sites-available/adminer.conf

    Add the following content:

    apache
     
    <VirtualHost *:80> ServerAdmin webmaster@localhost ServerName adminer.yourdomain.com DocumentRoot /var/www/html <Directory /var/www/html> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>

    Note: Replace adminer.yourdomain.com with your actual domain name. If you don’t have a domain, you can access Adminer using the server's IP address (e.g., http://your_server_ip/adminer.php).

  2. Enable the New Site Configuration: Enable your new site and restart Apache:

     
    sudo a2ensite adminer.conf sudo systemctl restart apache2
  3. Enable mod_rewrite (Optional): If you want to use pretty URLs or rewrite URLs, enable Apache’s mod_rewrite:

     
    sudo a2enmod rewrite sudo systemctl restart apache2

Step 5: Access Adminer

  1. Access Adminer: Open your web browser and go to the following URL:

    • If you're using a domain: http://adminer.yourdomain.com/adminer.php
    • If you're using the server's IP: http://your_server_ip/adminer.php

    You should see the Adminer login page.

  2. Log in to Adminer: To log in, you need to provide the following details:

    • System: Select your database type (e.g., MySQL, MariaDB, PostgreSQL).
    • Server: Enter localhost or your database server IP address.
    • Username: Enter the username for your database (e.g., root, admin, or a custom user).
    • Password: Enter the password for your database user.
    • Database: Optionally, select the specific database you want to manage or leave it blank to see all available databases.
  3. Start Managing Databases: Once logged in, you can begin managing your databases using Adminer’s user-friendly interface.


Step 6: Secure Adminer

While Adminer is a great tool, you should take measures to secure it, especially when it is publicly accessible.

  1. Change the Adminer File Name: Changing the filename of the adminer.php file can help reduce the chances of automated attacks. Rename it to something less predictable:

     
    sudo mv /var/www/html/adminer.php /var/www/html/custom_adminer.php

    Update your web browser URL accordingly (http://your_server_ip/custom_adminer.php).

  2. Restrict Access to Adminer: You can limit access to Adminer by IP address or password protection using .htaccess.

    • Restrict by IP: You can restrict access to Adminer to specific IP addresses by modifying the Apache configuration:

       
      sudo nano /etc/apache2/sites-available/adminer.conf

      Add the following inside the <Directory /var/www/html> block:

      apache
       
      Require ip 192.168.1.100

      Replace 192.168.1.100 with the IP address you want to allow access to Adminer.

    • Password Protect Adminer: To add an additional layer of security, use HTTP authentication to protect Adminer. Install the necessary tools:

       
      sudo apt install apache2-utils -y

      Create a password file:

       
      sudo htpasswd -c /etc/apache2/.htpasswd admineruser

      Then, update the Apache configuration:

       
      sudo nano /etc/apache2/sites-available/adminer.conf

      Add the following lines inside the <Directory /var/www/html> block:

      apache
       
      AuthType Basic AuthName "Adminer Access" AuthUserFile /etc/apache2/.htpasswd Require valid-user

      Restart Apache to apply the changes:

       
      sudo systemctl restart apache2

Conclusion

You have successfully installed and configured Adminer on your VPS for database management. With Adminer, you can easily manage your MySQL, PostgreSQL, SQLite, and other databases from a web interface. Remember to secure your Adminer installation to prevent unauthorized access.

Now, you can efficiently manage your databases directly from your browser, making database administration much easier.

Was this answer helpful? 0 Users Found This Useful (0 Votes)

Powered by WHMCompleteSolution