Popup

Wait! Don’t Go Yet! 👋

Become a Member Today and Unlock Access to All eBooks! 😍

Thousands of eBooks at your fingertips. Read, learn, and grow anytime, anywhere ✨

How to install phpLiteAdmin Database in a Raspberry Pi

In this blog post, I’ll introduce you to phpLiteAdmin, which is a web-based user interface written in PHP that makes it easy to interact with SQLite databases.

Don’t have a Raspberry Pi board? Read Best Raspberry Pi Starter Kits.

Basic Raspberry Pi setup

Before you continue reading this project, make sure you have the Raspbian Operating System installed on your Raspberry Pi.

You can read my Getting Started with the Raspberry Pi Guide to install Raspbian and complete the basic setup.

Installing SQLite

You also need to have SQLite installed in your Raspberry Pi.

Installing Apache2 and PHP

You need to install Apache2 on your Raspberry Pi; Apache is used to serve your web pages. Enter the next command:

pi@raspberry:~ $ sudo apt-get install apache2 -y

Top 6

Raspberry Pi eBooks

From Zero to Professional

Raspberry Pi Projects

You also need to install PHP, which is an open-source web scripting language that is used to build dynamic web applications. To install PHP and its modules, type in this command:

pi@raspberrypi:~ $ sudo apt-get install php5 libapache2-mod-php5 php5-sqlite -y

Move to your /var/www/html directory and edit the dir.conf file:

pi@raspberry:~ $ cd /var/www/html
pi@raspberrypi:/var/www/html $ sudo nano /etc/apache2/mods-enabled/dir.conf

Make the next change to the file. Before: index.html index.php

before changing dir conf

After: index.php index.html

after changing dir conf

Ctrl+X, type Y, and press Enter to save your changes. Restart the Apache2 service for the changes to take effect:

pi@raspberrypi:/var/www/html $ sudo service apache2 restart

Testing your installation

Create a new PHP file with the name index.php:

pi@raspberrypi:/var/www/html $ sudo nano index.php

Copy the next line to your index.php file:

<?php phpinfo(); ?>
php info

Ctrl+X, type Y, and press Enter to save your changes.

Go to your Raspberry Pi IP address (use the command ifconfig to print your Pi IP address in your terminal window), and this is what you should see:

Raspberry Pi IP address

Your PHP installation was successful. Now, you can remove the index.php file:

pi@raspberrypi:/var/www/html $ sudo rm index.php

Installing phpLiteAdmin

While on the /var/www/html directory, create a new folder called database:

pi@raspberrypi:/var/www/html $ sudo mkdir database
pi@raspberrypi:/var/www/html $ cd database/
pi@raspberrypi:/var/www/html/database $

Follow the next command to download and prepare phpLiteAdmin:

pi@raspberrypi:/var/www/html/database $ sudo wget https://bitbucket.org/phpliteadmin/public/downloads/phpLiteAdmin_v1-9-7-1.zip
pi@raspberrypi:/var/www/html/database $ sudo unzip phpLiteAdmin_v1-9-7-1.zip
pi@raspberrypi:/var/www/html/database $ sudo rm phpLiteAdmin_v1-9-7-1.zip

To set a password and the path to your SQLite database in your phpLiteAdmin configuration, this is what you need to do:

pi@raspberrypi:/var/www/html/database $ sudo cp phpliteadmin.config.sample.php phpliteadmin.config.php
pi@raspberrypi:/var/www/html/database $ sudo nano phpliteadmin.config.php

Change your file to look similar to mine (see below). Type a unique password and the path to your SQLite database:

phplite admin config

Create a SQLite database file

You can use the file created in the previous tutorial or simply create a new one:

pi@raspberrypi:/var/www/html/database $ sqlite3 sensordata.db
sqlite> .quit

Changing file and folder permissions

In order to make phpLiteAdmin work properly, you need to change some permissions and file ownership. Run the following commands:

pi@raspberrypi:/var/www/html/database $ cd ..
pi@raspberrypi:/var/www/html $ sudo chmod 777 database
pi@raspberrypi:/var/www/html $ sudo chmod 777 database/*
pi@raspberrypi:/var/www/html $ sudo chown root:root database
pi@raspberrypi:/var/www/html $ sudo chown root:root database/*

After running the preceding commands, confirm that root is the owner and those are the permissions for the database folder:

pi@raspberrypi:/var/www/html $ ls -l
drwxrwxrwx 2 root root 4096 Jan 30 15:11 database

Testing phpLiteAdmin

Open your http://RPi_IP_Address/database/phpliteadmin.php. This is how it should look:

login page phpSQLiteadmin

Enter your password to login and this is the web page that loads:

sensor data tab

On the left menu, you can see your database and table (if you’ve used the database created in the previous tutorial). Open the dhtreadings table:

open dhtreadings

Inside that table, you can see two rows:

dhtreadings table

Open the Structure tab:

opening dhtreadings schema

You can see the settings of each column, and you can change them if necessary.

dhtreadings schema

Next, open the sensordata database:

open create new table tab

Select the Create new table option and give it a name, for example, outputs:

create new table

Then, you could define the data columns for each row:

create new table schema

Wrapping up

The real advantage of using phpLiteAdmin is that, instead of sending SQL commands through a terminal window, you can add, remove, and update all data through a nice user interface.

Do you have any questions? Leave a comment down below!

Share your love

🚀 Discover the world of electronics and innovation!

✨ Create, program, and experiment with all your creative ideas with ease.

Spotpear

Leave a Reply

Your email address will not be published. Required fields are marked *

Secure Payments
Securing online payments is a shared responsibility, and everyone can contribute.
Free Shipping
You get unlimited free shipping on eligible items with Ebokify, with no minimum spend.
24/7 Support
Sales gifts are helpful tools often used to show appreciation to clients for their purchase.
Gifts & Sales
Our customer care service is offered in the form of 1st or 2nd level support.