Wednesday, 24 April 2013

Setting Up A Web Server

Look, it's a web server!
This was surprisingly straightforward.

In the end, I realised this web-page was bit of overkill for what I wanted. So I just gave that a read for background purposes, and went with the explanation in the Raspberry Pi User Guide by Eben Upton & Gareth Halfacre.

LAMP

Firstly, I logged on and installed what's called a 'Lamp Stack'. Lamp stands for Linux, Apache, MySql, and PHP. Linux obviously provides the operating system and is already installed; Apache is the web server; MySQL is the database handler; and PHP is the language that gives life to your web-site.

[In fact, xAMP stacks are apparently behind the majority of servers. There are also WAMPs which have Windows instead of Linux, and MAMPs that have the Mac OS]

I installed the LAMP using the following commands:
  • sudo apt-get update
  • sudo apt-get install apache2 php5 php5-mysql mysql-server
These can take some time to run (especially that 'update' if you've not done it before), it took about an hour to finish.

Along the way, MySQL asked me to set a password, then confirm it. I made sure it was secure i.e. Not easy to work out by visitors to my site.

Once the installation had completed, the MySQL and Apache servers were running.

Final Checks

To check that the server was up, I got my netbook out (which is part of my home network connected via a router) and typed the Pi's IP address into a web browser (I got the IP address using the 'ifconfig' command and found it listed in the 'eth0' section).

This displayed the default web page. Nearly done.

Finally, I had to confirm PHP was working, so, still following the guidance in above manual, I used the following command to create a test script:

     sudo sh -c 'echo "<?php phpinfo(); ?>"  >  /var/www/phptest.php'

This new file asks PHP to provide an information page when called. And I did that through the netbook again, tacking /phptest.php onto the end of the ip address.

This also worked. Job done!

Final Note

From this point on, every time I switch on the Pi, it becomes a local web server. I don't even have to log in for this to happen.

Friday, 19 April 2013

Next Steps With The Pi

Having read through my Raspberry Pi Users Guide, I've decided that my next step will be to set-up a web server to host a small website.

My reasons are basically: I've never done it before; I'll be able to learn and practise stuff HTML, CSS, Javascript, and PHP to build the website. Which could be useful in my current job.

I'll be using advise from that Users Guide I mentioned and this site to build my server.

I'll tell you how that goes soon.

Saturday, 13 April 2013

USB Hubs

So, here's the thing: Not all USB hubs work with the Raspberry Pi.

Hard to believe isn't it? You just take it for granted that you can just plug these into any computer and they just work.

I got my first clue when I looked at the packaging for some of these hubs. Just about all of them say they're compatible with Windows or MacOS. No mention of Linux or anything Pi related.

So I got on-line and did a quick search. Sure enough I found this page. It lists known compatible and incompatible hubs. It's not an exhaustive list (how could it be?) but it's a start and gives you idea what to look out for.

I took the easy option, I just bought from a site that specialises in Pi accessories. I went for a CIT-UH207P-01-HUB, USB 2.0 7 Port (Not the one pictured above).

The reason I went for it was that it has 7 ports (plenty of room for expansion....but probably over the top), and it's got it's own power supply. That's important because the Pi's not up to powering a bucket-load of usb peripherals.

In fact, I've gone a step further and bought a USB A Male to Micro B Male lead so that the hub can power the Pi. That would save me a power socket. Let's hope it works!

Update: Nope, the CIT hub isn't beast enough to power the Pi. If I were to do this again, I'd go for the D-Link Dub-H7 7 Port USB 2.0 Hub. Now that will do the job properly.

Friday, 5 April 2013

VGA Monitors, Sound, And More Speed (Take 2)

It's taken me a while to get round to trying out the suggestions from my previous post but I've finally had success. Not without a struggle though.....

VGA Monitors

The problem I had when I switched from an HDMI TV to a monitor as a screen was that I was getting no picture.

So I changed the config.txt file on the SD card (using the SD card reader on my netbook) to say:

     hdmi_safe=1

This command sets the Pi to low resolution output and should always give you a picture.

When I re-booted, it worked. Now all I had to do was figure out how to get a higher resolution (Giant icons on your desktop is not a good look!).

I just had to match up the monitor's best resolution with the table given here, and change the config.txt file accordingly.

The settings that did the trick on my monitor were:

     hdmi_drive=2
     hdmi_group=2
     hdmi_mode=83
     hdmi_force_hotplug=1
     disable_overscan=0

However, it took the best part of an evening to discover that each command needs to be on a separate line otherwise it doesn't work!

Anyway, hdmi_drive=2 means that the voltage output is for HDMI (1=DVI voltages).  

hdmi_group=2 means I'm using a monitor (1=An HDMI TV).  

hdmi_mode=83 is connected with the hdmi_group, 83 means I want 1600 x 900 resolution (See the table I mentioned above).

hdmi_force_hotplug=1 forces the Pi to use the HDMI port even if it can't detect a monitor.

disable_overscan=0 No idea why it works but it does.

More Speed

When I first got the Pi going on an HDMI tv, I noticed that some of the games were painfully slow. Apparently this is a common problem. The solution most people go for is so-called 'over-clocking' which boosts the CPU's clock frequency. However, the makers warn against this as it shortens the life of your Pi. For this reason it invalidates the warranty.

However, the makers have now come up with a setting that speeds things up without killing your Pi or invalidating the warranty.

The way to set it is to login then use

     sudo raspi-config

Now look for the overclocking option and work your way to this menu:


Select the Turbo preset.

Sound


Nightmare! I expected to just plug my headphones into the audio socket and get sound but it's not that simple.

In the end, I had to work through this entire link to get my audio set-up, including a full system update. Another couple of evenings blown. Why on earth should it be so difficult?! I get the impression the Pi is designed around connecting to an HDMI device and anything else is an afterthought.

Oh well, it's done now. I can finally get on with using it. I think I'll read through the Raspberry Pi User Guide to see what I'm going to have a go at next.