Skip navigation

Raspberry Pi Projects

6 Posts authored by: PEarle

Tomcat on my Pi

Posted by PEarle May 2, 2014

I decided to install Tomcat on my Pi and see what the performance is like.


First thing to do is make sure I have got the latest version of all my currently installed function - e.g. use command


sudo apt-get update


Step 1 - Install Java


Java installation is very straightforward with the following command


sudo apt-get install oracle-java7-jdk


Once that has finished you can check that Java installed correctly  with the command java -version. You should get something like this




To double check that it was installed I wrote and compiled a simple java class - of course it had to be "HelloWorld".


Using the 'nano' editor, I created a file called which contains the following ;


public class HelloWorld {
     public static void main(String args[]) {
          System.out.println("Hello World !!");


I compiled this with the command javac which created class file HelloWorld.class.


Finally I executed the class using command java Helloworld and saw the expected output - i.e.




Step 2 - install Tomcat

Download Distribution

Get the Tomcat distributions and unzip it as follows


tar xzf apache-tomcat-7.0.42.tar.gz


This will unpack the distribution underneath your current location (e.g. /home/pi/apache-tomcat-7.0.42)


Configure user


Before we start tomcat we need to configure an administrator user. Edit file tomcat-users.xml in the conf subdirectory (e.g. sudo nano conf/tomcat-users.xml) and add an entry under <tomcat-user>


e.g. add <user username="system" password="raspberry" roles="manager-gui"/>




Start up


To start up Tmcat run in the bin sub-directory - e.g. sudo bin/

A small informational message will display and then the console will free up . Tomcat is now running in the background - to check this enter ps -ef | grep java and you should see something similar to the following;




The best test of course is to try it in a browser - open a browser (which can be on another machine on your network) and enter URL e.g.  (i.e. <server_name>:8080) and you should see something like this:



I recently got hold of a Wolfson Audio card and did a bit of trial recording using the command line - see

That all works fine - but what I want to be able to do is use use my Pi as a mini-recorder, which means operating on its won, away from a monitor/screen/internet connection, etc. I decided that, as I have a smart phone with a browser, if I could create a network connection between the Pi and my phone, I could wrote some php pages to control the audio card.


To do this I need to

  • Configure the Pi as a wireless Access point
  • Be able to connect from my phone to the Pi
  • Have some php pages to allow me to record and playback


Setting up a wireless access point


I found some instructions from Adafruit at here

which give detailed steps for configuring a wireless access point. I followed these to the letter - and it didn't work completely   - I could see the network that I had created from my phone, but i couldn't connect to it. I suggest you do this, and then follow the extra steps below. At some point I will take a clean install and repeat this process, so that I can come up with a definitive list of steps to follow !


When I looked at the board, I realised that there were conflicting services running as daemons in the linux installation, which I identified by  installing rcconf and viewing the logs at /var/logs/messages and /var/logs/syslog and looking at the messages on boot up.

So I ran rcconf and I removed isc-dhcp-server and installed udhcpd. (rcconf is a run level configuration tool - see ).


(isc-dhcp-server has been reported to just have problems by others online.)


I configured /etc/udhcpd.conf appropriately (see sample file attached), then ran rcconf and disabled dnsmasq , and made sure udhcpd was enabled.


I also disabled the hotplug line in /etc/network/interfaces and made sure all necessary options were there (see sample file attached). this final configuration proved a bit tricky - everything worked fine until I unplugged the pi from the network. I had had it connected so I could access it 'headless' via putty. I ended up with the following values in interfaces (comments in bold have been added for clarity - do not copy/paste this text but see sample attached !).


auto lo
iface lo inet loopback

Set a static IP address for the lan connection as we are not going to be connected to a network. This will stop the Pi trying to find a DHCP server

auto eth0
iface eth0 inet static


Set a static address for the wireless connection - this will be the IP address that we use on our phone

auto wlan0
#allow hotplug wlan0
iface wlan0 inet static



Accessing from my phone

With the pi booted up, I can see the network, as shown below. When I click on the network it opens, I'm prompted for the password, and then the phone connects.





Ive written some PHP pages to control the Wolfson card, which I will go into m,roe detail about in a separate blog. These allow me to set the input gain and volume, and the playback volume, and to start/tops recording and playback. I also added some options to enable me to shutdown and reboot the Pi as its not going to have a keyboard attached!


This is what it looks like - this is very much a first go, and Im planning to make it look a bit less clunky. This isn;t a phone app !! - its a web page that I have loaded from the Pi - see the URL at the top of the page, which is the static IP of the Pi that I assigned in the etc/network/interfaces file





Controlling  with a php script


The following is an explaination of how i have implemented one of the functions - i.e. start recording' It covers the main points of the application.


One of the things I want to do is to start a recording by pressing a button on the phone. To do that I want to do the following


  • Fire off a background job to start recording to a file
  • Change the page to show that the recording is running



I have written a shell script to run the recording, which takes a couple of parameters for gain and volume. I call a script to set the gain and recording volume on the card then use the arecord function to record to a date stamped file.


# Set up the card
/var/www/recording/use_case_scripts/ $1 $2

# record to file - create one that is datestamped
OUTPUT_FILE="/var/www/recording/music/record_`date +%Y%m%d_%H_%M_%S`.wav";
arecord -Dhw:0 -r 44100 -c 2 -f S32_LE $OUTPUT_FILE


Within the php page, when I clock the 'record button, this executes some java script to change the display (i.e. put out a /'recording' message') and then calls a separate php page to call the above script. This php contains the following code to do that


/* Get the gain and level parameters, passed through in the request */
$gain = $_GET["gain"];
$inputLevel = $_GET["inputLevel"];
$playbackLevel = $_GET["playbackLevel"];

/* Spawn the recording job - the statement '  > /dev/null &' causes it to run in the background */
exec("sudo /var/www/recording/ $gain $inputLevel  > /dev/null &");

/* return to the main page - returning the current values paramrters so those don't get lost */
header( 'Location: recordingcontrol.php?gain=' . $gain . '&playbackLevel=' . $playbackLevel. '&inputLevel=' . $inputLevel.'&recordingStarted=true') ;


Permissions Considerations (use sudo visudo)

The web pages and their functions run under the default apache user www-data. this user must therefore be given sudo access to some functions. This is done by editing the sudo users file - e.g. use command sudo visudo. You will need to make changes as follows (this is required in order to execute the record shell script, as mentioned above).


www-data ALL=/var/www/recording/
www-data ALL=NOPASSWD: /var/www/recording/

This article assumes that you have already successfully installed your Wolfson audio card - if you haven't done that yet, there is an excellent blog by cstanton  at


Once you have your card set up you will want to start recording with it. Like may people, I run my card 'headless' via a Putty shell, and therefore I don't have a screen attached to control recording or playback. therefore i want to be able to record and playback straight from the card - i.e. without using players like Audacity. My eventual aim is to have a recorder controlled from my phone, but as a starting point I want to be able to at least record and playback with a minimum of effort.


This post explains how to make a recording and play it back, and how the recording parameters can be amended. Its only a basic guide but should help get you started - and there is an attached tar which contains an example of working record and playback scripts.


amixer recording control

The distribution comes with the amixer function, which is a bit like a command line mixing desk. There is some documentation available at and I used this to experiment with recording settings.


When recording sound there are two main settings to worry about - the 'gain' control which affects how much signal comes into the device, and the 'level' control which determines how much of that signal gets recorded. The gain should be set so that you get a clear signal - to much and it will be distorted, too little and there will be a lot of hiss and noise. Once the signal level is correct you then use the level control to decide how loud you want the recording to be. This second option really has more relevance with multi-channel recording - for instance if you want one source quieter than another.


The distribution comes packaged with some scripts in the use-cases directory - these allow you to set up the control for different types of record/playback. In my case I want to record in the onboard mics, and then pay back through the headphone jack.



Displaying current values and control parameters


Current values for a device can be be obtained by using the command amixer cget name='xxxxxxx', where xxxxxx is the name of the control.

For example, to get the current input gain settings use amixer cget name='IN2L Digital Volume' which returns the following :



From this we can see the current value (i.e. 128) and also the settings for this control - i.e.

  • Minimum value -64.0 dB
  • Increment value 0.50 dB
  • Max value 191 (which works out at around 31.5dB - i.e. -64 + (191/2)


So with a current value of 128, the input gain is set to (-64 + 128/2) - i.e. 0dB.


Setting Control Values

Control levels are set using command amixer -Dhw:0 cset name='xxxxxxx' nnn where


  • xxxxxxx is the name of the control
  • nnn is the value to assign


I.e. to set the input gain for the left hand onboard mic to 3dB us


amixer -Dhw:0 cset name='IN2L Digital Volume' 130


(NB value of 128 is 0dB for this control as explained above).


Gain Control

The gain for the on board mics is set using devices IN2L  and IN2R (i.e. for left and right).

The control name for the onboard mic gain is IN2L Digital Volume (for the left channel) and IN2R Digital Volume


Using command amixer cget name='IN2L Digital Volume' to get the current gain


Input Volume

The recording input level is set using devices AIF1TX1 Input 1 Volume and AIF1TX2 Input 1 Volume (i.e. for left and right).

The recording device has to be assigned to each control and then he level set.


E.g. to set up the left hand onboard mic (IN2L)

amixer -Dhw:0 cset name='AIF1TX2 Input 1' IN2L
amixer -Dhw:0 cset name='AIF1TX2 Input 1 Volume' 32



Preparing to record

Before a recording is made the appropriate commands must be set up to enable the correct devices and set the levels. The following example prepares for recording using the onboard mics, with input gain set at 5db, and the input volume at 8dB.


#Record from onboard DMICs

# Gain Control
# 128 = 0db, increments in steps of 0.5db (starting from -64db)
# Max = 191 (i.e. +32db)
# (to see current setting, and documentation of values, use command "amixer cget name='IN2L Digital Volume'" )
amixer -Dhw:0 cset name='IN2L Digital Volume' 138
amixer -Dhw:0 cset name='IN2R Digital Volume' 138

# Input level : 32 = 0db, increments in steps of 1.0db, starting at -32db
# Max setting = 48 (=16Db)
# (to see current setting, and documentation of values, use command "amixer cget name='AIF1TX2 Input 1 Volume'" )
amixer -Dhw:0 cset name='AIF1TX1 Input 1' IN2R
amixer -Dhw:0 cset name='AIF1TX1 Input 1 Volume' 40
amixer -Dhw:0 cset name='AIF1TX2 Input 1' IN2L
amixer -Dhw:0 cset name='AIF1TX2 Input 1 Volume' 40
amixer -Dhw:0 cset name='DMIC Switch' on


Making a recording


To make a recording :

  • Initalise the sound card values
  • Set the recording parameters
  • Run the recording command


The distribution comes with a 'reset' script which will reset all the values.

Recording is achieved using the command

arecord -Dhw:0 -r 44100 -c 2 -f S32_LE output_file



# Make sure card is set up to record from the onboard Mic

# record to file
arecord -Dhw:0 -r 44100 -c 2 -f S32_LE music/petemp.wav



To playback the recording use the command

aplay -Dhw:0 -r 44100 -c 2 -f S32_LE recorded file


Prior to playback the playback medium (e.g. the headset) must be enabled. The output volumes can be adjusted in the same way as the recording levels.


Example recording configuration

The attached tar file contains examples of recording and playback set up scripts, plus a couple of scripts which will record and playback. The recorded file is created in sub directory 'music'.


To install


  • Navigate to a directory on the pi where you want to install the example
  • Copy the attached file to that location (e.g. using ftp)
  • Un-tar using command


tar -xvf ~/recording_example.tar


This will create directory recording and 2 sub directories use_cases and music


To make a recording run To play back use The recorded file is created as petemp.wav in sub directory music.


For more details, look inside the individual script files !


Pi Webpage Reboot

Posted by PEarle Apr 2, 2014

I have recently set up a LAMP Raspberry Pi and am using this at work to monitor some servers (see Raspberry PI as a LAMP server and PI as a Web Server Monitor)

I'm running it 'headless' (i.e. without a keyboard or mouse attached). This is fine until I wanted to reboot it yesterday, and realised that I would have to go through the hassle of opening a Putty session, connecting to the server, logging on, and issuing the reboot command. How convenient it would be if i could just click on a web link ...


After some investigation I discovered that I couldn't simply write a .php page with something like 'sudo reboot' in it. What I needed to do was ;


  • Write a python script that would reboot the server
  • Write a php page to execute the python script.
  • I would also need to make some configuration changes to allow the reboot command to be run from a web application


Python Script

If I was booting from the command line I would enter sudo reboot. My python script therefore needs to allow me to run a system command. This is done by using the python subprocess command (there's a useful reference page at Subprocess and Shell Commands in Python ). With that knowledge, the resulting code is fairly easy to understand - see below. Note that the 'sudo' and  'reboot' commands are evaluated with their full paths.


command = "/usr/bin/sudo /sbin/reboot"
import subprocess
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
print output


Time stamping


I decided that it would be nice to keep a record of the commands that were being issued as added a time stamp operation in the python code - this simply writes a line to a log file with the current date/time. I also found this useful when developing this mini app as I could have the script run (and see that it had run successfully!) without having to issue the 'reboot' command.


The timestamp code is as follows


# Construct a timestamp variable
import time
ts = time.time()
import datetime
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')

# Open a file and allow content to be appended to it
f = open('/var/www/remotecontrol/logs/reboot.log', 'a')

# write the timestamp and text to the file
f.write(' : REBOOT command issued\n')


For the entire script, see attached example.


PHP Page


Once I had the script, I needed a page to allow me to run it. Executing the script from a web page is quite straight forward - e.g.


 exec("python /var/www/remotecontrol/python/");

However I want to control the process so that the script only runs when a button is pressed. Therefore my page needs to :

  • Display a page with a button on it
  • When the user presses the button
    • Execute the script
    • Display a confirmation message

I achieved this with the following code :

Output a button - when it is clicked execute javascript function reboot().

<input type="button" id="reboot"  value="Reboot" onClick="reboot()"/>

The javascript function resubmits the page with an added parameter - i.e. status=reboot

  function reboot() {


Php code in the page looks for the existence of the 'status' parameter and acts accordingly - note that it executes the script and puts out an indicationon the screen that the server is rebooting

   $status = $_GET["status"];

  if ($status == "reboot"){
       exec("python /var/www/remotecontrol/python/");
       print '<h2>Server is rebooting ...</h2>';

The full code is attached below - note that the page offers two options reboot and shutdown. (The shutdown script is a clone of the reboot script - with the command changed to shutdown now.)


Configuration Changes

When I tried to run the function nothing happened - my page displayed the 'Server is rebooting' but the server didn't reboot. I looked in the logs and found sudo: no tty present and no askpass program specified. (NB the error.log file is located at /var/log/apache2). After some 'googling' I discovered that this was being issued because the current user doesn't have access to the command. although I always log on to the pi from the command line as the default user pi, this command is being issued by the web page via Apache - and with the default LAMP installation, Apache runs as user, therefore, this user (i.e. Apache) needs to be given access to the sudo command to run the reboot command.

This is achieved as follows.

  • From a putty session use command sudo visudo
    • This will open up the sudo configuration file in the editor.
  • Go to the end of the file and add the following line

www-data ALL=/sbin/reboot
www-data ALL=NOPASSWD: /sbin/reboot

the effect of tis will be to enable user www-data to use the reboot command. if you want to issue other commands using sudo from Apache (e.g. shutdown, then add additional lines to the sudo configuration file.


When I had made the changes I rebooted the Pi to make sure the changes were applied.



That's it! - when I go to the url I see the following page; (I may add some styling to make it look better !)





When I click on the 'reboot button I see this, and the Pi reboots !



If this was anywhere other than in a very closed environment I would add some extra functionality to prevent the reboot page being actioned by unwanted users ! - but in this particular case I don't need to worry


Useful links


Raspberry Pi as a LAMP Server
Pi as a Webserver Monitor
Python Subprocess Command





PI as a Web Server Monitor

Posted by PEarle Mar 20, 2014

In my recent blog I described how I went about setting up my Pi as a LAMP server. like most people, once I had got this working, I needed to work out something useful to do with it! here at work we have a couple of servers that we use for developing/testing web code, and these come up and down during the day as new builds are deployed, etc. Its sometimes a pain when they are down so I thought it would be really useful if there was a continually updating page that could show their status.


I decided I would write a simple PHP app which needed to do the following


  • Ping the external server
  • Display a message indicating whether the server is currently up or down
  • Refresh the display


To make it look a bit more interesting, I decided to show an image based on whether the server is up or down. I also decided to monitor two servers at the same time, called 'Dev' (the Development server) and 'Staging' ( a testing server). I also decided to show an image depending on whether the relevant server was up or down.


( I decided to monitor our live servers as well, just to make things a bit more interesting. Of course we have a dedicated team which look after this in our production environment, and we get notified immediately if anything happens to them so this is a bit redundant - I just added them in to the mix here to make the screen look more complete !);


Before doing this, I made sure I could ftp files to the pi (using FileZilla) and also access the PI remotely using Putty. If you don't know how to do this there's load of articles on the web ! (see the links at the bottom of the blog).


In the following sections I'll explain how I wrote the php to accomplish the various functions, and then in the final section explain how I've set up the Pi so that it 'just runs' - I don't have to do anything to it ! I'm not the world's most experienced php developer so there may be better ways of doing this !


Ping the external server

The php function file_get_contents allows the contents of a url to be written to a file. If the URL isn't available it throws an error. So all we need to do is to run this function, and if an error occurs, the site is down. I didn't want to just use ping or wget because sometimes our servers are in a 'holding page - e.g. while a new build is running. When this happens we want to consider the server 'down' - wget and ping will not throw an error, but file_get_contents does, because our holding page process returns a 501 error.


I coded the following to this (note that I have obfuscated the actual url used !)


try {
} catch (Exception $e) {
  //do something here


At first the above didn't trap an error even though I could see an error being thrown in the server error logs (e.g. at /var/www/logs/apache2/error.log). I found the following advice on the net and inserted this code before and after


I put this at the top of the php code ...


* Override the standard error handing so that it will throw an exception that we can trap
        '$severity, $message, $file, $line',
        'throw new ErrorException($message, $severity, $severity, $file, $line);'

... then I put this at the bottom


* reset the error handling



Finally, I created a variable to hold the  result of the server status - e.g.


$devstatus = "up";
try {
} catch (Exception $e) {
    $devstatus = "down";


Display a message indicating whether the server is currently up or down

Now we have a variable to indicate whether the server is up or down, I needed a neat way to show it on the screen I could have just put out a message 'Server is up/Down' but wanted something to look a bit neater! I decided that for each server I would display an image to show the status plus some text. To make things more interesting, if the server was down I would change the image randomly to keep the user's attention. I think the following code snippet explains it clearly enough !


* Assign image (held as serverdown1.jpg, serverdown2.jpg, etc)
* Using static image for up, random one for 'down'
$serverupImage = "serverup1.jpg";
$randomSuffix = rand(1, 5);
$serverdownImage = "serverdown" . $randomSuffix . ".jpg";

// Display appropriate icon and description in a table
print '<div style="width: 810px ; margin-left: auto ;  margin-right: auto ;">';
print ' <table> ';
print '<tr align="center"><th colspan="2" ><h1>Servers\' Status</h1></th></tr>';

  // Server name
  print '<tr>';
  print '<th width=400px">';
  // If server is down, put name in Red
  if ($devstatus == "down"){
  print '<h2 style="color:red">Dev Server</h2>';
  else {
  print '<h2>Dev Server</h2>';
  print '</th>';
  print '</tr>';

  // Decription
  print '<tr>';
  if ($devstatus == "up"){
  print '<td><hr><h3>Dev is Up</h3></td>';
  if ($devstatus == "down"){
  print '<td><hr><h3 style="color:red">Dev is Down</h3></td>';
  print '</tr>';

  // icons
  print '<tr>';
  print ' <td><img src="';
  if ($devstatus == "up"){
  print $serverupImage;
  if ($devstatus == "down"){
  print $serverdownImage;
  print '">';
  print '</td>';
  print '</tr>';

  print '</table>';
  print '</div>';


Refresh the display

A web page will auto refresh if the following code is included in the header : <meta http-equiv="refresh" content="30" > (in this case every 30 seconds)



  <meta charset="utf-8">
    <title>Status of Servers</title>
  <script type="text/javascript" src="script.js"></script>
  <meta http-equiv="refresh" content="30" >



Implementing it on the PI

Getting it to run on the PI is fairly straight forward (assuming you've got your LAMP setup running !). I created a separate sub directory (remoteserver) under /var/www and copied all my files into there using FileZilla(i.e. the php file and the images). Don't forget that you will need to make sure that the files can be read by the server - I used chmod to make sure they were accessible - e.g.


cd /var/www/remoteserver
sudo chmod 777 *


Once I have done this I can display the page simply by typing  into the browser of any computer on my network (assuming that my Pi's IP Address is, and that my php file is serverstatus.php, deployed in directory /var/www/remoteserver).


I want to run this permanently displayed in a screen attached to my Pi, but I don't want to have to load the browser each time I start up the PI. Luckily, its quite easy to configure the browser to open automatically at startup, and also to change the home page of the browser to be my server status url.


Change browser homepage

I'm using the Midori browser (installed on my Pi by default). Open the browser, then click on the Tool menu (the 'cog' icon at the top right hand side). select preferences and it will open a dialog where you can change the home page. Put in the URL that you want the browser to load when it opens. (Note that this isn't strictly required if you are going to do the following step as the initial page is specified there anyway.)


Load browser on startup (Midori)

When the Pi starts up, by default it loads the LXDE page. You need to change this so that instead it loads the browser. this is done by editing file autostart in /etc/xdg/lxsession/LXDE.

sudo nano /etc/xdg/lxsession/LXDE/autostart


Comment out all the lines that are already there and insert the following


# Auto run the browser
@xset s off
@xset -dpms
@xset s noblank
@midori -e Fullscreen -a httl://


This will have the dual effect of not loading the desktop when the Pi boots up, and automatically loading Midori in full screen mode with the specified url.

Note that if you want to display the LXDE desktop again the future you will have to reverse this change !


Load browser on startup (Chrome)

I decided to try using chrome - this doesnt require the above to load the browser on startup - instead you can alter the .profile file in the pi user home directory and add the following line at the bottom;


chromium --kiosk --incognito


This will launch Chrome at startup. Note that with Chrome it doesnt seem possible to edit the browser to get to the desktop which means that you MUST be able to ssh to the pi externally (e.g. via Putty) - if you cant do this then don't make the above change as you will be unable to do anything on the Pi !


(hint - take a copy of the disk image with the above commented out ..)


This is what it looks like up and running on the desk !



Running without keyboard and mouse

The Pi is now ready to go, and you don't need a keyboard or mouse attached. You will find that the cursor appears in the middle of the page - luckily you can get rid of  this. There are full details at

- what you have to do is as follows ;


Edit file  /etc/X11/xinit/xserverrc and add the -nocursor option to the /usr/bin/X command as shown below;


exec /usr/bin/X -nolisten -nocursor tcp "$@"


Without the keyboard, it means that we can neaten up the desktop by mounting the PI using a VESA adaptor on the back of the screen like this - the Pi also acts a useful cable tidy !




We had some fun deciding on images to display if any of the servers are down - as I said earlier we have five available and the app picks one at random - this is my favourite;






Useful Links


Setting up Putty
Autorun browser on startupAutorun browser on startup « Raspberry Pi Projects
How to disable the cursorraspbian - How to disable mouse cursor on LXDE? - Raspberry Pi Stack Exchange

Raspberry PI as a LAMP server

Posted by PEarle Feb 24, 2014




I decided to set up my Raspberry PI as a dedicated LAMP server. (LAMP is an acronym that stands for LinuxApacheMysqlPhp and are components required to run a Dynamic HTML webpage.).


All these components are Open Source ;


  • Apache is the webserver that will host my applications - for more information see
  • MySQL is "the world's most popular Open Source database" (their own claim !) - more information here
  • PHP is "a popular general-purpose scripting language that is especially suited to web development." (again their own claim !) - see



Before you start, it might be helpful to assign your Pi a fixed IP address - if you haven't done this already, see my post on how to do so at You will need to know your Pi's address in order to access the server once you have installed it!The first step is to make sure the OS is up to date (good practice before making any PI upgrades) so I ran the following commands ;

  • sudo apt-get update
  • sudo apt-get upgrade


Step 1 - install Apache


Install using the following command;


  • sudo apt-get install apache2 php5 libapache2-mod-php5


Once that has completed, start the serber using the following command


  • sudo service apache2 restart


To test that the server is running, type your Pi's IP Address into the browser, and you should get a simple page displayed - e.g.


It works!

This is the default web page for this server.

The web server software is running but no content has been added, yet.


Although Apache is all working at this point, there are a few configuration changes you can make to improved this - see the 'More Infomation' section at the bottom of this page.



Step 2 - Install MySQL


Use the following cmannd to install the MySQL database


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


During the install a prompt will pop up asking you to supply a password for the database root user - enter something appropriate !


Once the install is complete, the database will be up and running. To test this use the following to get comand line access to the database


  • mysql -u root -p


You will be prompted for the root password that you assigned above. You can use this utility to run SQL commands to create users, table, etc.


If you want to use a MySQL client there are several free ones available - I use Heidi (see If you want to do this you will need to do the following steps


  • Configure MySQL to use the Pi's IP Address
  • Create a database user for you client PC


Configure MySQL


Edit file my.cnf in /etc/mysql - i.e


cd /etc/mysql sudo nano my.cnf


Look for the entry bind-address and edit it to be the Pi's ip address - e.g.


bind-address            =



Create a database user for your client PC


You need to use the SQL client on the Pi to add a user for your client PC. You will need to define a user and password - these will then be the credentials that you use in your SQL Client. In these examples I am using user root and password password - I suggest you choose something less obvious!


Use the following command on he Pi to open the MySQL client


  • mysql -u root -p            (You will need to supply the MySql root password when prompted)


Enter the following, substituting your own user and password values that you want to use - don't forget to surround the values with quotes and terminate with a semi colon.


CREATE USER 'root'@'' IDENTIFIED BY 'password';


Note that in the above is the ip address of my client PC, not the Raspberry Pi !!


You will also probably want to create a database to use (MySql isn't much use without one !) - again you have to then assign privileges to your client in order to use it.

You might as well do this at this point, with the following sql commands on the Pi;


CREATE DATABASE petersdb; GRANT ALL PRIVILEGES ON 'petersdb'.* TO 'root'@'' IDENTIFIED BY 'password';


(Again, don't forget the quotes and terminating semi-colons!)


Having done all the above you can now use an SQL client on your PC (e.g. Heidi - see to connect to the MySQL instance on the Pi - you will need to supply


  • The IP Address of the Pi
  • The user and Password that you specified in the CREATE USER command above


Once you have done this you will need to restart MySQL - either reboot the Pi, or use the following command


  • sudo service mysql restart


*Edit* - try using PhpMyAdmin !


If you want to make managing your database(s) at lot easier, try installing PhpMyAdmin. There's some really good instructions available at


Step 3 - Install an FTP Server


Its very hard to utilise a web server effectively without being to put files on it! - so we need to install an FTP server. as follows


Change ownership of the web root, and then download the ftp server as follows. Note that if this is going to be a public facing server you need to create a new user and password to use - dont use the default pi/raspberry !!


  • sudo chown -R pi /var/www     (substitue the user you have cretaed for pi in this command)
  • sudo apt-get install vsftpd


Now we need to edit the conf file as follows.


  • sudo nano /etc/vsftpd.conf


Find and edit the following lines as specified:


  • Change anonymous_enable=YES to anonymous_enable=NO,
  • Uncomment local_enable=YES
  • Uncomment write_enable=YES
  • then go to the bottom of the file and add force_dot_files=YES


When you have done the above restart the FTP server using


  • sudo service vsftpd restart

Having done this you can now FTP to the PI use a free client such as FileZilla (see


You will ned to supply the following values

  • IP Address of your Pi
  • User and Password - this is the pi user and password that you use to log on to the pi - e.g. pi and raspberry by default. If this is going to be a public facing server, change your password !!!!



More Information


  • Apache configuration

Apache will work 'out of the box' as installed above - however this is a default configuration, and you can tidy it up a bit.


If you restart Apache (using the command sudo service apache2 restart) you will see an error along the lines of Could not determine the server's fully qualified domain name, using 127.0.X.1 for ServerName.

This is because the Pi hasn't been set up as a named server. This can be done quite easily - all you need to do is decided on a name for your server, and to know your IP address.


For the following instructions I have chosen to call my pi lamppi - and my IP address is


N.B. To edit files use sudo nano filename - e.g. to edit file hostname in directory /etc;


cd /etc sudo nano hostname



Edit file hostname in directory /etc to contain the entry as below (using the name you have chosen for your server).



Edit file /etc/hosts as below. you need to


  • Add a localhost entry for your IP address (e.g. localhost)
  • Add an entry for your chosen server (e.g.    lamppi)
  • lamppi_2.png

Next, create an extra file servername.comf in the /etc/apache2/conf.d. You can use nano to create the file - i.e


  • cd /etc/apache2/confd
  • sudo nano servername.conf


Create an entry as shown below




You should now find that you can stop/restart apache without any errors being thrown.






Helpful commands


Restart MySQLsudo service mysql restart
Update OS
  • sudo apt-get update
  • sudo apt-get upgrade







Filter Blog

By date: By tag: