Skip navigation

RaspPiRR.jpg

 

 

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 http://www.apache.org/.
  • MySQL is "the world's most popular Open Source database" (their own claim !) - more information here http://www.mysql.com/
  • PHP is "a popular general-purpose scripting language that is especially suited to web development." (again their own claim !) - see http://php.net/


Preparation

 

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 http://www.element14.com/community/docs/DOC-54237/l/static-ip-address-for-my-pi. 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 http://www.heidisql.com/). 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            = 192.168.1.80

 

 

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'@'192.168.1.10' IDENTIFIED BY 'password';

 

Note that in the above 192.168.1.10 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'@'192.168.1.10' 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 http://www.heidisql.com/) 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 http://www.dingleberrypi.com/2012/09/tutorial-install-phpmyadmin-on-your-raspberry-pi/.

 

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 https://filezilla-project.org/

 

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 192.168.1.80

 

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).

lamppi_1.png

 

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

 

  • Add a localhost entry for your IP address (e.g. 192.168.1.80 localhost)
  • Add an entry for your chosen server (e.g. 192.168.1.80    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

 

lamppi_3.png

 

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

 

 

 

 

 

Helpful commands

 

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

 

 

 

 

 


 


I've been blogging about my experience in Road Test reviewing the Ultimate Raspberry Pi Bundle. As a part of this Road Test I'm creating a Fridge/Freezer Temperature Alarm system for our local food shelf, Channel 1. You can see where this Road Test started for me here


IMG_3071Sm.JPG


Since my last post I've been busy, last weeks on FIRST Robotics, but I managed to order some temperature sensors and get them working with the Raspberry Pi! So I'm quite close to my target project the temperature sensor/monitor for our local Food Shelf known as Channel One (and in the last week they've had another weekend outage, and another loss of food, so these sensors can really fill a need)


Previously I used the PiFace Control and Display to create a Raspberry Pi Powered Joke Machine - The Ultimate Raspberry Pi Bundle

for the Channel One Temperature Sensor I cracked open the Adafruit version of an LCD display (also included in the Ultimate Raspberry Pi Bundle) It's known as the Adafruit RGB Positive 16x2 LCD + Keypad Kit for Raspberry Pi I was glad I did too, for the following reasons:

  • The Adafruit LCD Plate is mutli colored, you can programmatically change the LCD background to 7 different colors. I decided to use the color feature to my advantage, my Temperature Sensor is normally Green, and I change it to Red if the temperature is too hot, and blue if the temperature is too cool
  • The Adafruit LCD features a nice set of Tutorials right on the product website and one tutorial was almost exactly what I was looking for, it explains how to use the DS18B20 1-wire temperature sensor and the Pi and PiPlate. I simply had to modify things slightly to use 2 sensors and then figure out how to use the LCD display as well.
  • With the PiFace I was wondering how to tap into the open ports after the shield was plugged in, Adafruit pointed out a neat device that could be used to make things easier here...stacking headers
  • Assembly instructions were very clear and easy to follow even though the pcb had been recently rearranged.
  • The Adafruit LCD does not have the IR sensor found on the PiFace CAD, or the extra togglebutton. However for this project I didn't really need those features
  • The Adafruit LCD buttons are controlled by polling instead of the event driven design found on the PiFace CAD. This is significant, for example I wanted to have a button that cancels the temperature sensor...if the buttons were event driven this would be easy, but since I have to poll the buttons with the Adafruit design, I'll need to poll temp sensor one, temp sensor two, then loop looking for button presses and then timeout when no buttons are pressed.


So the Raspberry Pi and the temperature sensors can detect when the Freezer or Fridge unit are out of range (too hot or too cold) and the LCD display can show the current temperature and even change colors when the temp is out of range? But how do we notify someone who can hopefully correct the situation? Well we don't have to worry about the issue of a power outage, as there is already an alarm in place for that, we also can assume that we have Wifi access. In a previous project I sent a twitter message to send a warning Create an Internet Connected Pill Dispenser but Channel One wanted to have a text message sent to one or more folks. While Twitter was free, I couldn't find a free SMS solution, but Twilio seemed like a reasonable cost for this project, each text costing only a penny or so. (Still would like to find a free solution)


Assembling the Adafruit LCD 16x2 Plate

IMG_3059AdaFruitSm.JPG


Testing on the home Fridge and Freezer

TempsensorSmIMG_3073.JPG


Issues I found this time around

  • The mini keyboard is once again annoying, sometimes types multiple characters and I found it does not have a "\" ...a key that is necessary with  python
  • Running out of time to review/blog about all the things in my Ultimate pi Bundle, still to come: Gertboard, PiFace Digital, Camera, Protoboard, and Embedded Pi

Filter Blog

By date: By tag: