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

Subscribe to Comments Feed

Who we are ?

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

More About the foundation...

Frequent Questions

Join / Linux Training / Board