Linux.com

Home News Hardware Servers Plugging Ahead: DIY Basic Apache/PHP Web Server

Plugging Ahead: DIY Basic Apache/PHP Web Server


I've been working with the Arduino micro-controller for a couple of years and have been seeking an inexpensive, compact solution for connecting it to my network.

An old Pentium II desktop machine worked OK as my remote Arduino-connected server, because it was cheap (free) and had a couple of serial ports. Using it was a worthwhile prototyping exercise, but it wasn't exactly compact or energy efficient. Since I eventually wanted to put the machine out in the garage, to control my sprinklers and other devices, the antique desktop route just wasn't going to cut it.

I looked into using the Lantronix Xport network-enabled Ethernet port. It is a self contained serial to Ethernet controller, with a built-in Web server. The Xport is a very nice, compact solution for connecting a micro-controller to your network and costs around US$50. The device is about the size of an RJ-45 socket. As cool as the Xport was, it didn't really meet my needs, since it has a limited capability to create Web pages.

I know the basics of PHP and want to build interesting Web pages to display the data. I also want to be able to perform calculations and kick off tasks, like sending emails to my cell phone based on the micro-controller supplied data. MySQL might also come into the picture, as I gain more experience with putting (and reacting to) data that's circulating around my network.

The Marvell SheevaPlug computer, that appeared on the market a few months ago, ended my search.

It's a full featured, headless Linux machine, with a 1.2 GHz processor, 512 MB of RAM, Gigabit Ethernet, USB port, SD slot, and 512 MB of solid-state storage. It is also about 2” x 3” x 4” in size and plugs right into a 110-V socket. How does US$99 for the developer kit version grab you? At some point the Plug Computer itself is rumored to be offered at US$79.

I should have ordered a dozen of them.

Unpacking The Plug Computer

Being so new, it seemed like it took years for the SheevaPlug box to arrive. Actual time of delivery was about three months.

Enclosed in the little box was the Plug Computer, a short CAT5 cable, USB to mini USB cable, a development CD, power cord, and a little power-line plug adapter. The device can sit on a table and run on the power cord or can hang right in a wall socket, using the adapter (see Figure 1).

My kit didn't have any instructions or reference documents, in the box. A few documents appeared on the CD, but were primarily geared to a bare-metal installation of Linux on the computer via the USB console port. You'll either need to have a basic understanding of running a Debian-based system or be reasonably proficient at Web research, in order to get the machine configured and tweaked.

As for appearances, the antique white finish of the little Penguin is shiny and simple, with the RJ-45 and USB 2.0 connectors on the bottom. The power cable or adapter plugs into the top. The right side houses the SD slot and mini-USB console connection. Power lights are on the front, as shown in Figure 2.

Needless to say, after looking at the parts for a minute or two, I simply attached the Plug to my router and powered it up.

It was time to make the device do something.

It's A Server, Not A Desktop

Buying and using the SheevaPlug assumes that you understand that this is a headless server with no local video capabilities. Other reviewers have blasted the SheevaPlug for the lack of a video card and implied that it will not be very useful to a lot of people. Well, what the heck are servers used for anyway?

I'm happy to report that it is a very capable, small-footprint, Debian-based server platform. Remotely logging in with SSH and doing everything through the command line is definitely the order of the day. All the standard Linux commands are available.

Actually getting the SheevaPlug running is pretty straightforward.

The first thing I needed was the root password. After a quick Web search, it turned out to be “nosoup4u”.

The next thing to tackle was the SheevaPlug's IP address. My Trendnet 802.11n router assigns them automatically via DHCP. The SheevaPlug's DHCP client is running by default, so you can log into your router and look to see which IP address has been assigned. I just ran nmap to scan my network for new addresses.

rreilly$: nmap 192.168.1.1-200

The router had assigned 192.168.1.103. After that, it was a simple matter to log into the Plug Computer from my ASUS notebook (running Kubuntu), using a standard console terminal.

I used the following to log into the SheevaPlug.

rreilly$: ssh -l root 192.168.1.103

Obviously, you'll want to assign a new root password, just to be on the safe side. You'll also probably want to add a static IP since it will be used as a Web server. Now on to installing Apache and PHP.

Installing Apache and PHP5 with apt-get

After working with the SheevaPlug for a couple of days I came to the conclusion that it is pretty much regular old Debian with a 2.6.22.18 32-bit kernel.

At first, I had some problems getting apt-get to work. You'll need to add a few new directories, because it gave an error when I tried to run the command. I fixed it up by logging in as root and using mkdir to create /var/cache/apt/archives and /var/cache/apt/archives/partial. These go away after a reboot. I suspect that it has something to do with the solid-state storage. Perhaps there is a way to permanently create these directories, but I don't know how at this point.

Installation of Apache was pretty simple:

rreilly$: apt-get install apache2

PHP is equally as easy to install. I also added the command line PHP interface (php5-cli), so I could develop some data crunching routines, that could be executed as regular programs.

rreilly$: apt-get install php5 php5-cli

HTML and PHP files reside in the /var/www directory. You can edit the index.html file using a text editor like vi. You can view the file by pointing your browser at http://192.168.1.103. The following PHP code can also be entered in the file a file named testindex.php.

  

Test PHP Script


print (“Hello, World!


”);
phpinfo();
?>

Point your browser at http://192.168.1.103 to see information about your version of PHP. You can also see if PHP is working from the command line.

rreilly$: php -v

What's Next?

I've outlined how to install and run a very basic Apache and PHP implementation on the Plug Computer. Shortly, I will be sending data from the Arduino micro-controller and displaying the results on a Web page. I haven't figured out how that's done yet. I plan to also be able to fill in some form data and use buttons to actuate physical devices on the Arduino's analog and digital output pins.

This is a great start to an affordable, compact, Linux-based server system. Hopefully, we'll see interest in the community as the little boxes get more visibility.

Rob Reilly is a consultant and freelance technology writer. His interests include Linux, anything high-tech, speaking, and working with conferences. You can visit his web page at http://home.earthlink.net/~robreilly.

Comments (16)Add Comment
Roland
arduino
written by Roland, May 13, 2009
I found your article very interesting. You say " I will be sending data from the Arduino micro-controller and displaying the results on a Web page. I haven't figured out how that's done yet." I suggest you get Simple Message System from http://www.arduino.cc/playgrou...System.zip
or my mini-site, http://user.cavenet.com/rolandl, and my shellscript package, SMS1.tgz. Then you will have full command-line control. Full IO & PWM control. AD is scaled to mV and CSV formatted for import to most spreadsheets. GUI via xdialog. It can do 100 AD readings (x6 chans) in under 40 secs. Don't need all that? Strip down both packages--they are just proof-of-concept. Hint: you WILL need a helper process, I use 'cat $UNIT1 >> logfile1.raw &'.

Apache seems overkill in this situation to me. Try 'apt-get install mini-httpd', see http://www.acme.com/software/mini_httpd. No PHP support, but I don't see why you'd need it if you've got a shell script in the background updating index.html periodically, via sed.

I am using reed relays connected directly to the IO pins: elexp.com #22RD5, a buck and change each. 10ma per coil is easily within spec for the unit, and the IO pins are already diode-protected.

Finally, your blogging system didn't send me an email after registering for 20 minutes. Why is it so slow?
John
...
written by John, May 13, 2009
As for me, I prefer lighttpd on such weak hardware. Unlike Apache, lighttpd is really light and can cope with decent load when uploading static content while still being able to use PHP and others via FastCGI. Given a proper optimizations(let's say PHP's output caching so there is just static data served most of time), such "plug" could turn into a quite decent server. It is a bit harder to set up than Apache on powerful machine but still funny, challenging and could result in something really worth of efforts. Let's say, you can run your own forum, blog or whatever on such thing easily and for most of cases it will have enough horsepower. Btw, few years ago servers were weaker than this plug and were able to cope with a decent load smilies/smiley.gif

P.S. other people may also try nginx, yet another fast but quite featured server. It could do a tremendous job even on limited hardware and on powerful one it serves huge overloaded monsters like Wordpress site.
Andrea Benini
Interesting Post
written by Andrea Benini, May 13, 2009
Hi Rob,
This topic was already known by me, I follow several RSS feeds on embedded hw so I've already seen it.
As John I prefer Lighttpd for this kind of device, it's light and more flexible, it doesn't have all the feature Apache has but you can still use PHP, GD, ...
I'm so interested in your article and in this kind of devices, I'm trying to open new discussions on this group (http://www.linux.com/community...ms+Hacking Embedded Platform Hacking), i wish to see there your comments or posts as well

Hope it helps
Ben
Rob Reilly
Apache/PHP and the Plug Computer
written by Rob Reilly, May 13, 2009
Thanks for all the great comments, I'll use them when I move forward with my Arduino work.

Yes, it is a good idea to run a small-footprint Web server on this device, although the mainstream Apache server is pretty easy to use and set up. Lot's of extras available too. Thanks for starting the discussion and alerting readers to other options.

As for interfacing the Arduino to the Plug Computer, I didn't mention that the serial-USB drivers don't seem to be present, in this version of the Plug Computer Ubuntu system load. If a serial-USB device, like the Arduino, is attached to the Plug Computer, it will not assign a ttyUSBxxx connection. I suspect that the kernel has only certain drivers compiled in and the serial-USB is not one of them. I don't deal with kernel things much and have not had time to dive into the job. The holdup, I believe, is that the Arduino can't communicate with the serial-USB port because of driver issues. Perhaps a reader, with a Plug Computer, can help us out with a solution to the problem.

I think that the Plug Computer a good idea and the price is certainly right for easy expansion and development. BTW, the $99 offering is the developer kit, with CD and cross compiling info. The basic Plug, by itself supposedly costs less, but I have not purchase one that way, yet.
Roland
thanks for the warning
written by Roland, May 14, 2009
I will skip buying a Plug Computer until they fix udev & USB. Avoid version 1.0 of anything. Maybe by then they will get enough volume to lower the price. Oh well. smilies/sad.gif
Andrea Benini
Still searching
written by Andrea Benini, May 15, 2009
But as you I'm still searching for a cheap (
Andrea Benini
Still Searching
written by Andrea Benini, May 15, 2009
Still looking for a cheap device, let's say under 50$ with usb and ethernet, I'm scavenging in the Access point world but new suggestions are welcomed
Brian
...
written by Brian, May 19, 2009
Did you get the sprinklers working? What else is in the plans with a project like this?
Andrea Benini
sprinklers, indeed
written by Andrea Benini, May 20, 2009
Even sprinklers, I've already did it. My personal goal is to create an home automation system, cheap and affordable for guys with no bucks, fully hackable and customizable, so the search continues

Ben
Roland
...
written by Roland, May 23, 2009
I just saw an article stating this thing had an update:
http://www.desktoplinux.com/ne...ml?kc=rss
Did that affect the udev system? Did it fix this problem?
"...second update due for availability today" (May 22)
Stanislav Ivashchenko
...
written by Stanislav Ivashchenko, May 26, 2009
Is it noisy? I need something quiet for 24/7 torrent client. Do you know if it can operate with 220V power supply? This should be written on the back side as on Fig.1
Thanks for your post.
Marigowda Divya
...
written by Marigowda Divya, June 05, 2009

Stanislav Ivashchenko: ...
Is it noisy? I need something quiet for 24/7 torrent client. Do you know if it can operate with 220V power supply? This should be written on the back side as on Fig.1
Thanks for your post.11


there is no fan; it is quiet. It can operate with 220v, but the plug supplied (removable) is for U.S. usage. You will need a power cord suitable for your location; it is similar to the one used for Notebook power supply; last I checked it was less than $10.00.
Marigowda Divya
Andrea Benini: Still Searching
written by Marigowda Divya, June 05, 2009
Andrea Benini: Still Searching
Still looking for a cheap device, let's say under 50$ with usb and ethernet, I'm scavenging in the Access point world but new suggestions are welcomed


you may want to look into the Linksys NSLU2.
Andrea Benini
Marigowda Divya
written by Andrea Benini, June 05, 2009
Marigowda Divya:
Already have a slug NSLU2, OpenWRT with it but no luck with Samba and Vista without modding NTLM credentials
Ken Shirriff
Using the Arduino with the Sheevaplug
written by Ken Shirriff, August 18, 2009
If you're still trying to get the Arduino and Sheevaplug working together, see my blog post: http://arcfn.com/2009/06/ardui...dware.html
Among other things, it explains where to get a new kernel with the necessary USB drivers.
Rob Reilly
...
written by Rob Reilly, August 18, 2009
Ken,

Thanks for the Arduino and SheevaPlug link. I had come across a kernel that worked for my purposes. Of course, how I'll integrate an upgrade presents another challenge.

It is nice to see someone else with similar interests and ambition. There is a lot of potential for this combination and I think we are at the beginning of a great new journey.

Keep up the good work and stay in touch.

Rob

Write comment
You must be logged in to post a comment. Please register if you do not have an account yet.

busy
 
Become a Linux Foundation Member

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Members / Staff / Board