16) Install phpMyAdmin

<-- Previous    Next –>

So far we have PHP, MySQL and Apache 2 installed on the server now we can install Install phpMyAdmin which is a web application to administer MySQL.

The easiest way to install phpMyAdmin is through apt-get:

sudo apt-get install phpmyadmin

During the installation, phpMyAdmin will walk you through a basic configuration. Once the process starts up, follow these steps:

  • Select Apache2 for the server
  • Choose YES when asked about whether to Configure the database for phpMyAdmin with dbconfig-common
  • Enter your MySQL password when prompted
  • Enter the password that you want to use to log into phpMyAdmin web interface
  • After the installation has completed, add phpMyAdmin to the Apache configuration.
sudo nano /etc/apache2/apache2.conf

Add the following line to the file:

Include /etc/phpmyadmin/apache.conf

This can be placed at the end of the file.

Restart Apache using:

sudo service apache2 restart

You can then access phpMyAdmin by going to http://youripaddress/phpmyadmin.

Security of phpMyAdmin

To add an extra level of security it is recommended to use the htaccess / htpasswd system to stop anyone accessing the web pages.

Set Up the .htaccess File

To set this up, start off by allowing the .htaccess file to work within the phpMyAdmin directory.

sudo nano /etc/phpmyadmin/apache.conf

Under the directory section, add the line “AllowOverride All” under “Directory Index”, so the section will look like this:

<Directory /usr/share/phpmyadmin>
Options FollowSymLinks
DirectoryIndex index.php
AllowOverride All
[…]

Configure the .htaccess file

With the .htaccess file allowed, we can proceed to set up an login to access the phpmyadmin web page.

Start by creating the .htaccess page in the phpMyAdmin directory:

sudo nano /usr/share/phpmyadmin/.htaccess

Then enter the following:

AuthType Basic
AuthName “Restricted Files”
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user

Below you’ll see a quick explanation of each line:

AuthType: This refers to the type of authentication that will be used to the check the passwords. The passwords are checked via HTTP and the keyword Basic should not be changed.
AuthName: This is text that will be displayed at the password prompt. You can put anything here.
AuthUserFile: This line designates the server path to the password file (which we will create in the next step.)
Require valid-user: This line tells the .htaccess file that only users defined in the password file can access the phpMyAdmin login screen.

Create the htpasswd file

Now we will go ahead and create the valid user / password information.

Start by creating a htpasswd file. Use the htpasswd command, and place the file in a directory of your choice as long as it is not accessible from a browser. Although you can name the password file whatever you prefer, the convention is to name it .htpasswd.

sudo htpasswd -c /etc/phpmyadmin/.htpasswd username

Where username is the username of your choice.

A prompt will ask you to provide and confirm your password.

Once the username and passwords pair are saved you can see that the password is encrypted in the file.

Now restart Apache:

sudo service apache2 restart

Accessing phpMyAdmin

Now when you go to the web page http://servername/phpmyadmin a login box will be displayed.

Fill it in with the username and password that you generated. After you login you can access phpmyadmin with the MySQL username and password as before.

<-- Previous    Next –>

15) Installing MySQL on your Raspberry Pi

<-- Previous    Next –>

The installation of MySQL should be straight forward, however, there is an issue that can catch you out to do with the file system size.

To install MySQL use:

sudo apt-get install mysql-server mysql-client php5-mysql

However, this may fail because the filesystem on the SD card will become full. This can be seen by running the command:

sudo df -h

The SD card is probably 4GB. The filesystem will be around 1.9GB. This was done to make it fit on 2GB cards. To stretch the filesystem to the full size you need to run:

sudo raspi-config”

and choose the:

expand_rootfs

option. Then you need to reboot.

Now:

sudo df -h

should tell you that the filesystem has much more free space.

Run the installation script shown above again.

To completely un-install MySQL should your installation fail:

If the installation has failed, you may find it better to un-install MySQL and start again.

To completely un-install MySQL:

sudo service mysql stop #or mysqld
sudo killall -9 mysql
sudo killall -9 mysqld
sudo apt-get remove –purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
sudo deluser mysql
sudo rm -rf /var/lib/mysql
sudo apt-get purge mysql-server-core-5.5
sudo apt-get purge mysql-client-core-5.5

To secure your MySQL installation

To further secure your MySQL installation you should use mysql_secure_installation utility in your terminal.

This utility does the following:

  • You can set a password for root accounts.
  • You can remove root accounts that are accessible from outside the local host.
  • You can remove anonymous-user accounts.
  • You can remove the test database (which by default can be accessed by all users, even anonymous users), and privileges that permit anyone to access databases with names that start with test_.

All you need to do is go into your terminal and type mysql_secure_installation and follow the prompts.

<-- Previous    Next –>