How to Install Adminer on the Raspberry Pi ?

Hackbs

How to Install Adminer on the Raspberry Pi ? Step By Step Explained

Key Takeaways

  • Adminer offers lightweight MySQL database management through a web UI
  • Install LAMP prerequisites first on your Raspberry Pi
  • Download adminer.php script and configure Apache access
  • Secure Adminer behind HTTP authentication
  • Create databases and dedicated users in MySQL
  • Connect Adminer to start managing databases visually
  • Follow least privilege and backup best practices for security

Adminer is a fast and lightweight database management tool that can be installed on a Raspberry Pi to manage MySQL databases easily through a web interface.

In this comprehensive guide, we will cover everything you need to know to get Adminer running on your Raspberry Pi, including:

  • What is Adminer and why use it
  • Installing LAMP stack prerequisites
  • Downloading and configuring Adminer
  • Securing Adminer with authentication
  • Creating databases and users
  • Connecting to databases through the Adminer interface
  • Adminer usage tips and best practices

Follow along below for step-by-step guidance and expert advice to start leveraging the power of Adminer for your Raspberry Pi database projects.

What is Adminer?

Adminer is a lightweight database management tool written in PHP that allows you to manage MySQL, SQLite, PostgreSQL and MongoDB databases through an easy-to-use web interface.

Some key features and benefits of Adminer include:

  • Lightweight – under 1MB file size with minimal dependencies
  • Supports multiple database engines like MySQL, MariaDB and more
  • Easy to use web-based interface comparable to phpMyAdmin
  • Requires no database configuration since it connects directly to databases
  • Secure – offers protection against SQL injection and XSS vulnerabilities
  • Available for free under Apache license

For Raspberry Pi users, having Adminer installed provides a simple way to manage all your MySQL databases for web applications and other projects without having to connect via command line. And since it’s so lightweight, it has very minimal impact on Pi system resources.

Overall, Adminer makes database administration more visual and user friendly so it’s great for developers, DBAs and server administrators of all skill levels.

Why Use It on Raspberry Pi?

Some of the reasons Adminer is a good fit for Raspberry Pi database management include:

  • Minimal resource usage is good for the Pi’s limited hardware
  • Easy web interface for graphical database access
  • No need for additional MySQL client installation
  • Good tool for learning database concepts through hands-on interaction
  • Active development community providing support and updates

Now let’s go through the installation process step-by-step.

Steps to Install Adminer on the Raspberry Pi

Step 1: Install LAMP Stack Prerequisites

Since Adminer is a PHP application, the first requirement is to get a LAMP stack installed on your Raspberry Pi.

LAMP stands for Linux (the operating system), Apache (the web server), MySQL (the database management system), and PHP (the scripting language).

Here are the LAMP components we need to have in place first:

  • Linux – Raspberry Pi OS or Ubuntu Server
  • Apache – Apache2 web server package
  • MySQL – MySQL community edition database
  • PHP – PHP scripting language support

There are a few different ways you can setup LAMP on a Raspberry Pi. The easiest is by using Tasksel which is a Debian/Ubuntu tool to install pre-configured bundles.

To install LAMP stack with Tasksel, connect to your Raspberry Pi via SSH or log in directly to the console. Then execute the following commands:

sudo apt update

sudo apt install Tasksel -y

sudo Tasksel install lamp-server

Once the installation completes, Tasksel will have Apache2, MySQL and PHP installed and ready to build applications with.

Optionally, you can choose to install components individually using apt if desired.

With LAMP stack in place, we can now install Adminer itself.

Step 2: Download and Configure Adminer

Download Adminer

First we’ll download the latest Adminer PHP script. This can be done via wget on the command line.

Run this command which will download Adminer into the current user’s home folder:

wget https://www.adminer.org/latest.php -O ~/adminer.php

The file is now saved as adminer.php and ready to be configured.

Configure Adminer

Before we can access Adminer through the web server, we need to set up some access permissions.

Using your preferred text editor, open /etc/apache2/apache2.conf with root privileges.

At the bottom of the file, add the following configuration block:

<Directory /home/pi/>

    Allow Override All

    Require all granted

</Directory>

Note: Replace “/home/pi” with the path you downloaded Adminer to if different.

This will allow .php scripts in user directories to be executed when accessed through the Apache web server.

Save and exit the text editor when finished updating apache2.conf.

Finally, enable the rewrite module which helps with redirecting requests:

sudo a2enmod rewrite

sudo systemctl restart apache2

Adminer is now ready to be connected to MySQL and accessed through the web browser.

Step 3: Secure Adminer with Authentication

Before exposing Adminer on your network, it’s best to add a layer of authentication for security.

The easiest method is through an htpasswd file. Apache can require a username and password before allowing access to the Adminer tool.

First, let’s create an admin user and password:

sudo htpasswd -c /etc/adminer.htpasswd adminuser

You will be asked to enter and confirm a password for this new admin user.

Next, we enforce password authentication in Apache’s configuration by editing /etc/apache2/apache2.conf again.

Add this line within the <Directory> block we created earlier:

AuthType Basic

AuthName "Adminer Login"  

AuthUserFile /etc/adminer.htpasswd

Require valid-user

Restart Apache for the authentication to be enabled:

sudo systemctl restart apache2

Now only the adminuser account will be able to access the Adminer tool through the web server.

Let’s connect a database next.

Step 4: Create Databases and Users in MySQL

For Adminer to be functional, it needs a database to connect to.

If you haven’t already configured users in MySQL, you’ll want to create at least one database and user account that Adminer can use.

First, log into the MySQL shell:

sudo MySQL -u root

Then create a new database:

sql

CREATE DATABASE adminer_db;

Next create a separate MySQL user for Adminer, along with permissions for the new database:

sql

CREATE USER 'adminer_user'@'localhost' IDENTIFIED BY 'password123';

GRANT ALL PRIVILEGES ON adminer_db . * TO 'adminer_user'@'localhost';

Flush the privileges to update permissions and exit MySQL shell.

sql

FLUSH PRIVILEGES; 

exit

Now you have a user called “adminer_user” with full access to a database named “adminer_db” configured.

Adminer will be able to use these credentials to access and manage this database instance.

Step 5: Connect to Databases through Adminer

With all the pieces in place, we can now open a web browser to view our Adminer interface.

To access Adminer, browse to the following address using your Pi’s IP address:

http://<raspberry_pi_ip>/adminer.php

For example:

http://192.168.1.123/adminer.php

You should be greeted with an authentication prompt:

Enter the admin username and password configured earlier.

Once authenticated, the main Adminer dashboard will load:

From here, you can connect to existing databases by entering your connection details on the right:

  • Select MySQL database driver
  • Enter your Pi hostname or IP address
  • Use the MySQL username and password created previously
  • Select the database you want to manage from the dropdown

And click the login button.

Adminer will then connect directly to your MySQL databases for convenient management through its graphical tool.

Some of what you can do after connecting a database includes:

  • Browse database tables
  • View, edit, insert and delete records
  • Update table structures
  • Import and export data
  • Run SQL queries from the interface
  • Manage indexes, stored procedures and more

Overall, almost anything that can be done from the mysql command line or GUI desktop tools can also be done through Adminer’s web-based console.

Create Additional Connections

You can save connection credentials to quickly switch between databases by adding more connections:

Simply fill in the credentials and connection name, then those databases can easily be accessed again without re-entering details.

This allows managing multiple databases from the same Adminer portal.

Now that you have Adminer up and running, let’s go over some usage best practices.

Adminer Usage Tips

As with any powerful database management tool, there are things you can do to leverage Adminer most effectively while staying secure. Here are some key suggestions:

  • Practice Least PrivilegeOnly grant database users the minimum permissions needed to perform required tasks. Avoid using the root user through Adminer for everyday operations.
  • Use Strong CredentialsAlways enforce secure passwords following best practices for any database users. Disable unused accounts and restrict hosts where possible.
  • Limit Direct Database AccessDon’t expose MySQL ports directly to public networks. Keep the database server and Adminer tool within your internal infrastructure.
  • Back Up Your DatabasesDownload backups frequently in case data gets corrupted or accidentally changed. Adminer makes database exports easy.
  • Monitor for Suspicious QueriesCheck MySQL logs periodically for any abnormal SQL statements or connection attempts from Adminer users.

Keep Adminer Updated

When new Adminer versions release with security fixes, download the latest PHP script to replace your existing copy.

Following these recommendations will help secure your databases while still allowing convenient access through the Adminer portal.

And that covers the full installation process and usage of Adminer on a Raspberry Pi LAMP server!

With Adminer properly integrated following these steps, you can now easily access and control MySQL databases on your Pi without command line or desktop tools.

Adminer strikes a nice balance of usability and security for developers and administrators managing databases on Raspberry Pi servers.

Conclusion

Getting Adminer operational on Raspberry Pi provides a user-friendly database management console accessible from anywhere on the network. With minimal resource overhead, it’s an ideal tool for remotely administering MySQL instances on Pi devices through an intuitive web UI comparable to phpMyAdmin.

Now you can visually create databases, manage data records, run queries, import/export and more from Adminer’s simple yet powerful dashboard. Paired with a LAMP stack, it completes an extensible platform for launching PHP-based web apps and tools backed by a managed database.

We encourage you to further explore all that Adminer has to offer for taking control of your MySQL servers on Raspberry Pi and beyond. Its active open source community will continue enhancing capabilities and security well into the future.

FAQs

Q: Does Adminer work on Raspberry Pi OS Lite?
A: Yes, as long as you have Apache and PHP installed, Adminer can run on the Raspberry Pi headless OS since it’s web-based.

Q: Can I enable HTTPS access for Adminer?
A: Absolutely. Once you have an SSL certificate installed, adjust Apache sites-enabled config to enable HTTPS for the location of Adminer.

Q: Is Adminer compatible with MariaDB instead of MySQL?
A: Yes, Adminer 4.8+ has support for both MariaDB and MySQL databases when configuring connections.

Q: How do I backup my entire MySQL database through Adminer?
A: On the homepage, click Export to backup the full database. This downloads an SQL file you can restore from anytime.

Q: Can I manage PostgreSQL or SQLite databases with Adminer on Pi?
A: Indeed! On the login page, switch the database system to PostgreSQL or SQLite to start managing those database types instead.

Q: Where are Adminer credentials and login history stored?
A: Credentials are stored in ~/.adminer.php per user. There is no login history tracking by default but can be added with plugins.

Q: Is there a way to restrict SQLite database access in Adminer?
A: Yes, assign file system permissions using chown and chmod to limit read/write access to SQLite database files on disk.

Q: How can I customize or translate the Adminer interface language?
A: You can create custom CSS, plugins and language localization files stored as adminer-{type}.php to customize UI text and components.

Q: Can I connect Adminer to a MySQL database running on another device?
A: Yes, as long as the remote MySQL server grants access to the user account from your Pi’s IP address, you can manage external databases.

Q: Is it possible to import data from a spreadsheet directly through Adminer?
A: Yes, Adminer has an Excel/CSV import plugin to help migrate tabular data into your databases more easily from spreadsheets.

Q: How do I remove old database connections from the saved profiles in Adminer?
A: You can manually edit ~/.adminer.php and remove unused JSON objects in the saved “servers” array.

Q: What PHP extensions are required to run Adminer successfully?
A: Beyond the base PHP package, Adminer may utilize the MySQLi, PostgreSQL, SQLite3, LDAP and GD extensions if installed on your system.

Q: Can I call Adminer functions from within another custom PHP script?
A: Yes, check out the documentation on using included_functions.php to reference and execute some Adminer logic from your own code.

Q: Is there a way to display database server metrics in Adminer?
A: Yes, there are user contributed plugins like Adminer Dashboard to add server statistics charts visualizing disk, memory, connection usage and more.

Q: How can I tell if my database driver supports using Prepared Statements in Adminer or not?
A: Check your database version – MySQL has supported prepared statements since v4.1. SQLite and PostgreSQL have varying levels of support as well.

Q: Is it possible to customize the color theme or stylesheet of my Adminer interface?
A: Yes! Adminer allows bundling custom adminer.css files to override default styles by adding css hooks to various elements.

Q: Can Adminer manage views, stored procedures and triggers for MySQL databases?
A: Absolutely – the interface provides full DDL capability to create, edit and drop views, stored procedures, triggers, events and more database objects.

Q: What are some common Adminer extensions and plugins worth checking out?
A: Some popular addons include Table Filter, Bulk Export, Charts, Pretty JSON Viewer, Brute Force Protection, and Foreign Data Wrapper plugins.

Leave a Comment