Raspberry Pi Home Server: Extra, SD cards gone bad

Sometimes bad things happen to SD cards, and Windows doesn’t always handle it gracefully. I’ve had cards that Windows refused to recognize, and SD Formatter wouldn’t touch. There are a number of ways to fix this. Sometimes, putting the card in a camera, and telling it to format the card will work. If that doesn’t work, all is not necessarily lost. Here are some steps you can try.

Remember that you will lose any information that was on the drive, so don’t do this if you need to recover data from the bad card. There are utilities out there for rescuing data from damaged cards, but that’s beyond the scope of this article.

Note: These instructions are written for a Windows user. The “fdisk” command in Linux performs similar operations, but you’ll have to look elsewhere for the walkthrough.

Remove the bad SD card, along with any other flash drives or SD cards from your computer so you don’t accidentally format the wrong one. Press the Windows key, and “R” together, type “diskpart” at the prompt, and press enter.


You’ll find yourself looking at something that is almost, but not quite entirely, unlike a command prompt.


Type “list disk” to see all the disks in the computer.


Now insert the bad SD card into your reader, and type “List Disk” again, and look for the disk that wasn’t there before.


In this example, Disk 3 is the new entry in the list, and therefore the SD card that we want to reformat. Type “select disk x” where “x” is the number of the new disk from the list.


Before proceeding, be VERY sure you’ve selected the right disk. We’re about to blow away its partition table. If you accidentally chose your primary hard drive, very bad things will happen. Don’t blame me. I warned you plenty.

Once you are ABSOLUTELY sure you have the right disk selected, type “clean” and press enter.


The drive you selected is now a blank slate. Type “create partition primary” to create a brand-new partition table.


Finally, format the new partition by typing “format fs=fat32 quick”. Don’t forget the “quick” part, or you’ll be waiting around a while.


And that’s it. The drive is freshly formatted and ready to use again. If you open a file explorer window at this point, you should see your drive. It will still have its old name, but will be completely empty. Type “exit” to close diskpart. You can now proceed as usual.

Posted in Computers and Internet, Home Server, Raspberry Pi | Tagged | Leave a comment

Raspberry Pi Home Server: Part 9, WordPress

The Raspberry Pi can do more than just share things inside your own house. It can host websites and blogs that you make available to the public. Why you’d want to do this rather than just put up a free blog on wordpress.com, well, that’s a question you’ll have to answer for yourself. I’m not judging. I’m just going to show you how to set it up.

Create WordPress database

Way back in part 4 of this series, you installed a LAMP stack. If you recall, the “M” was for “MySQL”, and while we haven’t done anything with it yet, it’s been there, waiting for someone to put it to use. The WordPress blog engine is going to use MySQL to store all of the content for a blog. Get yourself logged in as “pi”, and enter the following commands at the command prompt, replacing the highlighted passwords with something of your choice.

mysql -uroot
create database wordpress;
create user wpuser;
set password for wpuser = password(“raspberry”);
grant all privileges on wordpress.* to wpuser@localhost identified by ‘raspberry‘;
sudo service mysql restart

Let’s break that down:

  • Open the MySQL command-line utility, logging in as root.
  • Create a brand-new database for WordPress to put stuff in.
  • Create a service account WordPress will use to talk to the database.
  • Set a password on that service account for WordPress to use when authenticating.
  • Make the service account the owner of everything in the new database.
  • Exit the MySQL command-line utilty
  • Restart MySQL to make sure the changes stuck

Install WordPress

WordPress will be installed just like everything else, using apt-get.

sudo apt-get install wordpress

Next, you’ll create a “symbolic link”, which means that all references to one address will be redirected somewhere else. Specifically, anything trying to get to http://SERVERNAME/blog should go to the WordPress folder instead.

sudo ln -s /usr/share/wordpress /var/www/blog

In the Linux world, almost everything maps into one unified file structure, even things that aren’t actually files, like web addresses. Just roll with it. Next, copy the provided sample configuration file into WordPress’ folder.

Note: Enter this all as one line, even though it’s wrapped here.

sudo cp /usr/share/wordpress/wp-config-sample.php

Edit the configuration file you just copied, replacing the DB_NAME, DB_USER, and DB_PASSWORD settings with values matching what you used in the previous step.

sudo nano /etc/wordpress/config-default.php


Restart the Apache webserver so that it will notice the changes.

sudo service apache2 restart

The result should look something like this:


Configure WordPress

WordPress, being a web-based product, handles most of its configuration through its own web interface. Open a browser to your Raspberry Pi’s address, with an additional “/blog” on the end. That redirect you set up earlier will send the browser to WordPress, which will prompt for some initial values, and then complete its own installation.

Provide a title for your blog, a password for the admin user, and an email address that won’t work without some additional configuration anyway, and click “Install WordPress”


WordPress will do some initial configuration in the background, and let you know when it has finished.


Click the “Log In” button to go to the Log In form, where you’ll need to provide the name and password you just established.


You’ll be taken to the WordPress Dashboard page. The care and feeding of a WordPress site is beyond the scope of this article, but I would like to point out one more thing that you’ll need to check. The addresses used by WordPress for things like links and style sheets are absolute addresses which include the name of the server. That server name might be set to “localhost” right now. I’ve done this installation a number of times, and sometimes it just comes out wrong.

I haven’t quite figured out the pattern yet, but if you try to look at the site from a computer other than the Raspberry Pi itself, and all the theming is broken like this:


…then you need to fix the site’s name. You’ll need to get to a browser on the Raspberry Pi itself in order to fix this. Navigate to http://localhost/blog/wp-admin, and log in with the credentials you established above. From the navigation menu on the left, go to Settings –> General


In the “General Settings” section, replace “localhost” with “rphs” (or whatever you named your Raspberry Pi) in the “WordPress Address” and “Site Address” fields, and click the “Save Changes” button at the bottom of the page.


You should now be able to see the full site from other computers on your home network. Making this work from outside of your house is beyond the scope of this article, but would require your own domain, or at least a static IP address, which you would put in the same two addresses.

You should be able to get away with a Dynamic IP provider like no-ip.org, although I have not tried this myself, yet.

What’s next?

I’m currently working on more jobs for the Raspberry Pi to do, and will add them to the series as I complete them. When that happens, I’ll update this article to link to them. For right now, though, this is the end of the line.

Posted in Computers and Internet, Home Server, Raspberry Pi | Tagged | Leave a comment

Raspberry Pi Home Server: Part 8, Transmission

Sometimes you want to download something large. For instance, the NOOBS zip file that started off this whole series. “Transmission” is a cross-platform BitTorrent server that will run quite happily on a Raspberry Pi.

What’s a BitTorrent?

Let’s say I wanted to download the NOOBS zip file. I could get it straight from the Raspberry Pi website, but that means that I’m competing for bandwidth with all of the other people trying to get that same file, and that bandwidth is costing the Raspberry Pi Foundation money, money they could be using to build more cool toys.

Torrents work by asking all of the computers downloading a particular file to talk to each other and trade the bits they already have amongst each other instead of everybody downloading the same bits of the same file from the Raspberry Pi Foundation’s server. Through the magic of BitTorrent, one computer could says to the others “Hey, I already have the first half of the file, does anyone have the second?”, and another computer might answer “Well, I don’t have the whole second half, but I have most of it. I’ll give you what I have if you give me the first third, ‘cause I’m totally missing that”.

At the center of it all is one computer that started the whole thing off by hosting the complete file first, and staying on to serve as “matchmaker” when new computers get added to the mix. In the case of the NOOBS software, that’s the Raspberry Pi Foundation’s server again. The foundation’s server started with a complete copy of the file, from which it created a .torrent file. The .torrent file describes the file you’re trying to get, providing information like how big it is, how many chunks it’s been broken into, and providing a checksum hash of the complete file so that you can be sure you got all the pieces right, and to stop jerks from ruining it for everyone by hosting files with the wrong bits in them.

You start a download of the large file you want by first downloading the much smaller .torrent file. You feed this file to a BitTorrent client like Transmission, which contacts the original server to see what peers are online sharing the load. Then, the client starts getting bits from all the different peers in the network, and only contacting the original server for those parts that no-one else has yet.

When the download of the large file is complete, the client stays online as part of the network, and just keeps on sharing (or “seeding”) the bits of the large file to anyone else who might need them.

Torrents have a kind of a bad reputation since they have become a kind of ersatz peer-to-peer file sharing mechanism for trading things like Hollywood movies, but they can be terribly useful for anyone that wants to mitigate the bandwidth costs of distributing large files on the internet.

Installing Transmission

To install the Transmission “daemon” (that’s a “service” to you Windows folks), type the following at the command prompt.

sudo apt-get install transmission-daemon

It’s a pretty simple installation, but will require some configuration before it’s ready to use.

Configuring Transmission

Before editing the configuration file, make sure the transmission daemon is stopped.

sudo service transmission-daemon stop

Transmission keeps its settings in a JSON-formatted text file. Open it in the nano editor with the following command.

sudo nano /etc/transmission-daemon/settings.json

Change the following settings, modifying the download path to match whatever you called your external drive:

“download-dir”: “/mnt/external/Downloads”,
“rpc-enabled”: true
“rpc-whitelist-enabled”: false
“rpc-username”: “transmission”
“rpc-password”: “raspberry”

Once again, a program is managing its own list of passwords. You get that a lot in the Linux world. I’ve kept the default user name of “transmission” here, and used the default password for “pi”. Pick whatever you want. Finally, start the transmission daemon (service) by typing

sudo service transmission-daemon start

Transmission provides its own web interface, so there is nothing to add to Webmin. Open a browser and navigate to the Raspberry Pi, port 9091. You should see the Transmission interface, which is pretty basic.


Time to give back

At this point, I’d like to suggest that you seed the archives for NOOBS and other Raspberry Pi images. Click on the open folder icon in the top left, enter the url of one of the NOOBS torrent files, and click “Upload”. The latest version of the NOOBS torrents are always available from the following addresses:

A row for each .torrent file you upload will be added to the list, and the torrent will begin downloading. Click on the new row to select it, and click the blue “i” icon in the upper right to get more detailed information about how the download is progressing. When all the bits have finished downloading, and a torrent goes into “seeding” mode, its progress bar will turn green like this:


torrent files for the other official OS images are available from http://www.raspberrypi.org/downloads. You might consider seeding all of the Raspberry Pi images if you can spare the space. Remember to pay attention to how much CPU is being used, and don’t overtax your Pi. If you seed too many torrents, there may not be much CPU left for other tasks.

There are Transmission “remote control” applications available for many platforms that will give you greater control over the download process, but they are beyond the scope of this post. You can start by looking at the Add-Ons section of the Transmission website (https://www.transmissionbt.com/resources)

What’s next?

In the next post, we’ll add WordPress so that you can host a blog from the Raspberry Pi because… why not?

Posted in Computers and Internet, Home Server, Raspberry Pi | Tagged | Leave a comment

Raspberry Pi Home Server: Part 7, MiniDLNA Media Server

Now that the Raspberry Pi is on the network, and sitting on top of a (hopefully) massive pile of your media on its external drive, it would be nice to have it share that media in a form other than simple file shares. File shares are great for a lot of things, but Media can be done a little better.

DLNA (Digital Living Network Alliance… what a horrible acronym) is the technology standard that lets you play songs from your phone and have them come out of the stereo in your living room. It’s not ubiquitous yet, but it’s catching on. It also lets programs like Windows Media Player play music and video “libraries” that are being shared by other computers on the network.

The Raspberry Pi is about to become one of those libraries.

Installing MiniDLNA

This installation will be done from the command line, and involves a bit more configuration than some of the other features in this series. Get yourself logged in to a command line as “pi”, and start by installing MiniDLNA via the same apt-get mechanism as everything else.

sudo apt-get install minidlna

As installs go, this one’s pretty quick, but there is a bit of configuration to be done before it’s ready to go. Start by editing the minidlna defaults:

sudo nano /etc/default/minidlna

Find the line that says “#USER=”minidlna””, and remove the pound sign / hash mark from the beginning, so that if just says “USER=”minidlna””. Close and save the file. Next, edit the main MiniDLNA configuration file.

sudo nano /etc/minidlna.conf

There are several things to be done here. The first is to set up the folders that will hold the various kinds of media you want shared. A little way down the file, find the first line that isn’t a comment. It should say something like “media_dir=/var/lib/minidlna”. On my drive, there are separate folders for Music, Pictures, and Videos, so I’ll add multiple media_dir lines, one for each kind of media. The comments in the file do a pretty good job explaining the syntax, but for reference, here’s what mine says:


The letters A, P, and V indicate what kind of content each folder contains (audio, pictures, or video). Next, change the database and log folders to go to the hard drive as well. This will speed things up, conserve space and reduce wear & tear on the relatively small SD card that is acting as the Raspberry Pi’s system drive. The lines to configure this are just below the media_dir lines modified above:


The result should look something like this:


Close and save the file (Ctrl-X, Y, Enter). Next, you need to set up MiniDLNA to run automatically at boot time with this command:

sudo update-rc.d minidlna defaults

And finally, manually start the MiniDLNA service.

sudo service minidlna start

A Webmin module exists for MiniDLNA that will make it easier to manage things in the future. It is available at http://sourceforge.net/projects/minidlnawebmin/files. Pick the latest version, and download the .wbm file to somewhere convenient. You could download this through a browser directly on the Raspberry Pi if you want, but I’ll write the directions for downloading it from your primary computer.

Once the .wbm file is downloaded, go to Webmin –> Webmin Configuration, and click on “Webmin Modules”. Pick “From uploaded file”, click the “Choose File” button, and browse to find the file you just saved. Click “Install Module”, and the MiniDLNA module will be installed.

You should now have an entry under Servers called “MiniDLNA server”. This module is pretty simple, and does little more than show you the settings from its configuration file. Down at the bottom of the page, though, are two buttons that restart the server, and tell it to rescan its folders, respectively. Click on “Rescan” to force MiniDLNA to start indexing the files on the hard drive.

You should now be able to open something like Windows Media Player, and see an entry for “RPHS: minidlna” in the list on the left:


Drilling down into this entry will show you the media that it has indexed so far. If your external drive has a lot of media on it, then it might be a while before it’s all done being indexed. You can configure MiniDLNA to automatically rescan for new files periodically by uncommenting the “inotify” and “notify_interval” settings in the config file. It should rescan for media roughly every 15 minutes with the default settings.

I am not a MiniDLNA expert, by any means, so you might want to look elsewhere for more configuration information. MiniDLNA has recently changed names to become “ReadyMedia”, but does not seem to be ready for use on the Raspberry Pi at the time I’m writing this.

What’s next?

In the next post, we’ll add a BitTorrent server for downloading things from the internet.

Posted in Computers and Internet, Home Server, Raspberry Pi | Tagged | Leave a comment

Raspberry Pi Home Server: Part 6, Sharing Files With Samba

Now that we have the Raspberry Pi up and running, and remotely accessible in lots of different ways, it’s about time it started doing something useful around the house. Its first task will be to share files from an external hard drive. For this example, I’m using a drive formatted as NTFS. Fat32 drives don’t generally hold enough to be really useful as file servers. There are many other formats that Linux and Windows both understand, such as exfat, but adding NTFS support is easy, and it works just fine.

Install NTFS support

Log in to the Raspberry Pi as the “pi” user, and type the following command.

sudo apt-get install ntfs-3g ntfs-config

This will install or update the base NTFS support, as well as some extras that assist in mitigating the differences in how permissions are handled between Windows and Linux.

Mount your drive

Don’t plug your drive in just yet. You’re going to use the power of the desktop and Webmin to make the next few tasks a little easier. Start up the desktop by typing “startx” at the command line. Once the desktop is up and running, plug in your external drive. You should get a pop-up indicating that a removable drive has been inserted, and asking you what to do about it. Cancel out of the dialog, and open Webmin from your primary computer. You could use Webmin directly from the local desktop as well, but you’ll get much better performance running it from an external browser. The Raspberry Pi is good at a lot of things. Running browsers isn’t one of them.

Note: If your power supply isn’t strong enough, it’s possible that plugging in a new USB device might suck up too much power, “browning-out” the Raspberry Pi, and causing it to restart. If this happens, leave the device plugged in, and catch back up to this point. You may not get the prompt, but hopefully everything else should be the same.

From Webmin, go to System –> Disk and Network Filesystems. You should see a list similar to this:


Find the row that corresponds to your external drive. It has most likely been mounted as /media/NAME, where NAME is whatever name was assigned to the drive when it was formatted. In this picture, it’s the yellow-highlighted row, and the device is called “NTFS-8GB”. The important part is the “Location” column. Here, my drive is identified as “SCSI device A partition 1”. Linux has some throwback moments, and its insistence on thinking of USB drives as SCSI (Small Computer System Interface) devices, is quaint. Write this location down, you’ll need it in a little while.

The /media/NAME location is okay, but the /media folder is really meant for removable things like CDs and DVDs. This being a USB drive, it is technically removable, but you’re going to want to treat it as more of a permanent part of your setup.

Get back to a command line, and unmount the drive from its current location like this:

sudo umount /media/NAME


The drive is now dismounted, which will allow you to remount it in a more suitable location. Go back to Webmin, and pick “Windows NT Filesystem (ntfs)” from the drop-down list at the top of the page.


Click the “Add mount” button. On the next page, type “/mnt/external” in the “Mounted as” textbox. If you want to call your drive something different than “external”, that’s fine, just remember to substitute that name in the upcoming steps. I’ll be using “external” for the remainder of this series, though.

Make sure “Save and mount at boot” is selected so that the drive will always appear in the same place. “Mount now?” should be selected as well so that you won’t have to reboot to see it work. Click the radio button next to “Disk”, and pick the location that you wrote down earlier from the drop-down list.


Leave the other options at their defaults, and click the “Create” button to create the mount point. You will be returned to the “Disk and Network Filesystems” list, and you should see your drive added to the list as /mnt/external.


From the command line, you should now be able to see the contents of the drive by typing “ls /mnt/external”. “ls” stands for “list”, and is the Linux equivalent of “dir” in Windows.

Share your drive

The next step is to share the drive so that other computers on the local network can use it. The “Samba” package will do this in a way that Windows computers on the network will understand. Install Samba as follows:

sudo apt-get install samba samba-common-bin

When the installation is complete, you’ll set up the pi user in Samba’s password file, and grant ownership of the new drive to the pi user. Once again, you don’t have to use the same password as the pi user, but it’s probably easier if you do. Go ahead and set up your own individual account as well, using the user name you created back in Post #1.

sudo smbpasswd –a pi
sudo smbpasswd –a USERNAME
sudo chown pi:pi -R /media/External

Set share permissions

Just for fun, we’ll use Webmin again to do this part. Get to a browser on your primary computer (or the Pi, if you like waiting), and navigate to the Raspberry Pi by address or name, port 10000.

There is a Samba administration module, which should be listed under the “Un-used Modules” section. Since you’ve just installed Samba, it would be nice if this module weren’t hidden like this. Click “Refresh Modules” near the bottom of the left menu, and Webmin will go through its inventory, and figure out which modules are actually unused. This can take a little while, so be patient. When it is finished, the “Samba Windows File Sharing” module should have moved to the “Servers” section at the top. You’ll notice that the modules for “Apache Webserver” and “MySQL Database Server” have moved up as well since those services were installed earlier in this series.

Click on the “Samba Windows File Sharing” module, and then on the “Windows Networking” icon under “Global Configuration”. Change “Workgroup” to match your home network if it is different (it’s probably just “WORKGROUP”, though, unless you specifically changed it). Select “Be a WINS server”, and set “Security” to “User level”.


Click “Save” to save the settings and return to the main Samba page. Click on the “Create a new file share” link near the top of the page. Give the new share a name. I called mine “external” to avoid confusion, and type “/mnt/external” (or whatever you called your mount point) in the “Directory to share” textbox. Your screen should look like this:


Click “Create” to create the share, and you will be taken back to the main Samba page. Your new share should now appear in the list. Click on it to go to the “Edit File Share” page. From here, click the “Security and Access Control” icon.

Set “Writeable” to “Yes”, and type “users” in the “Valid users” textbox.


Click “Save” to save your settings and return to the “Edit File Share” form. Click “File Permissions”. Set “Force Unix group” to “users”, and click “Save”.


Click the “Return to share list” link at the bottom of the page to return to the main Samba page. Click on the “Restart Samba Servers” button near the bottom of the page. You should now be able to view the share from other computers on your network. You’ll get prompted for a user name and password the first time you try to connect to them. Just give it the name and password you set up for yourself earlier, and you should be fine.



I am not a Linux security expert, and somewhere someone is screaming at me for doing it all wrong. I’m sorry, it’s nothing personal, it’s just the extent of my knowledge on the subject. We’re talking about a home network, here, and there is no central authority for user identities. There’s no Domain server that can keep everything in sync, so I’m relying on Linux’s view of the world to control what it’s sharing.

If anyone wants to correct me, or show me what I’m doing wrong, I’d be happy to update this post with better information.

What’s next?

In the next post, we’ll get a media server up and running so that you can stream music and movies all over your house from the hard drive we just attached to the Raspberry Pi.

Posted in Computers and Internet, Home Server, Raspberry Pi | Tagged | Leave a comment

Raspberry Pi Home Server: Part 5, Remote Desktop

So far in this series, we’ve set up the Raspberry Pi for remote login via SSH, and for web administration through Webmin. Sometimes, though, you just want to see a desktop, and that’s not easy when the computer you’re trying to see has no monitor, keyboard, or mouse.

You can easily add remote desktop ability to the Raspberry Pi pretty at this point through a program call X11VNC. There are other VNC (Virtual Network Computing) packages out there, but this one has worked pretty painlessly in my experience.

Installing X11VNC

Type the following to install the X11VNC package.

sudo apt-get install x11vnc

That’s it, a single apt package, and X11VNC is installed.

Configuring X11VNC

There’s a bit of configuration to be done before your remote desktop will be usable. Firstly, if you haven’t run the desktop while logged in as “pi” already, you’ll want to do that now. You’ll need a certain folder that get created automatically by the X desktop when it is first run. So, if you haven’t run the desktop yet, do that now by typing the following:


Exit the desktop by clicking on the red “power” icon in the lower-right corner, and then clicking “Logout”.

You’ll need to establish a password used to secure the remote desktop connection itself.

x11vnc –storepasswd

You will be prompted to assign a VNC password. This doesn’t have to be the same password as your regular password, but you may want to keep the passwords in sync so you’ll have fewer to remember.

Next, create a folder to hold the X11VNC desktop configuration file.

mkdir /home/pi/.config/autostart


Note: If you get an error that a folder doesn’t exist, it’s probably because you didn’t run the desktop at least once while logged in as “pi”. See the first configuration step above and try again after having started the desktop at least once.

Create and edit a new desktop configuration file by typing the following:

nano /home/pi/.config/autostart/x11vnc.desktop

Copy the following lines into the new file. Without going into too much detail, you are specifying that x11vnc should start running whenever the x desktop is shown.

[Desktop Entry]
Exec=x11vnc -forever -usepw -display :0 -ultrafilexfer

Close nano, saving your changes, and reboot the Raspberry Pi to force it to pick up on the changes.

sudo reboot

To test this out, log back in as “pi”, and start up the desktop by typing “startx” at the command prompt. If you still have the Raspberry Pi hooked up to a monitor, it should now show the X desktop.

Open your favorite VNC viewer application. I have used both TightVNC and UltraVNC. Which one you prefer is a personal choice. Connect to the Raspberry Pi by IP address or by name (RPHS), and you should be prompted for the password you created above. Type in the password, and you should be looking at a remote desktop that mirrors what’s currently on your monitor.

The real magic is that you can start the desktop remotely via SSH. This is how you’ll get to a remote desktop once the Raspberry Pi goes “headless” (loses its monitor). You’ll log in via SSH and start up the desktop by typing “startx”. The command prompt will show something like this:


Then you connect your VNC viewer, and you’re all set to go.


Remember to log out of the desktop when you are done so the server doesn’t waste CPU cycles running a desktop that no-one is looking at. At that point, the command prompt in the SSH window will wake back up, and you can log out of the Raspberry Pi completely.



I’ve sometimes had problems with the remote desktop only working once per reboot. Once I’ve logged out of the desktop, it doesn’t seem to want to connect again until I reboot. I’m not sure why, but if I figure it out, I’ll update this post. For now, I just reboot the pi when the remote desktop doesn’t work.

Other users?

If you want to log on to a remote desktop session as a user other than “pi”, you’ll need to repeat the configuration steps (starting the desktop once, creating the autostart file, etc.) for each user. Make sure to SSH in as the user whose desktop you want to see, and manually start up the desktop in the same way as you did for “pi”.

I have not personally done this, since the only reason I would want to see the remote desktop would be to do administrative tasks, which I always perform as “pi” anyway.

What’s next?

That’s it for all the different ways we can remotely connect and administer the server. In the next post, we’ll start putting the Raspberry Pi to work sharing files on the internal network.

Posted in Computers and Internet, Home Server, Raspberry Pi | Tagged | Leave a comment

Raspberry Pi Home Server: Part 4, Web Administration

SSH is a simple way to remotely log in to your machine’s command-line interface, but that’s not always the most convenient way to work. There is a wonderful web administration system called Webmin that can handle a lot of the “magic” of system configuration. Webmin modules exist for a lot of the features we’ll be adding to the Raspberry Pi in this series. It’s also pretty easy to install, so let’s get started.

The LAMP stack

LAMP stands for “Linux, Apache, MySQL, and PHP”, and it’s the technology stack on whish a lot of projects in the Linux world are built.

  • Linux is the OS, of course, the bottom layer of the stack.
  • Apache is a web server that runs on Linux.
  • MySQL is a database that applications can use to store their stuff.
  • PHP is a web programming technology used to write web applications.

Through the magic of the Advanced Packaging Tool (APT), you could just install Webmin, and the other components would come along for the ride, but you’d lose some control over exactly which versions it would pick, and where’s the fun in that? I’ve had a little better luck making sure I have a solid LAMP stack before installing any applications on top of it.


This part was taken care of in previous posts. Log in to the Raspberry Pi as the “pi” user, and get to a command prompt.


To install the next layer of the stack, the Apache web server, version 2, type the following command, answering “Y” when prompted to confirm.

sudo apt-get install apache2


If everything went well, you should now have a working web server. You can test this by opening a browser from another computer on your network, and navigating to the address of the Raspberry Pi. You should see a generic “It Works!” message.



Next up is the database where applications will store their information. Type the following to install MySQL

sudo apt-get install mysql-server-5.5

You’ll be prompted multiple times during the install to provide a password for the root user. It should look like this:


This is not the same “root” as Linux itself. This is a MySQL account that will own the server. Whatever password you assign, make sure you write it down somewhere, or put it in a password safe program. You will eventually need it. Since I’m not exposing MySQL through my firewall, I just left the password blank. I know… I’m a bad person.

When the installation has completed, check to see that MySQL is working by typing the following:

mysql –uroot -p

This says to start the MySQL command-line interface, and log in as the user “root”, prompting for the root password. Again, this is the MySQL root user, not the Linux root user. To get a list of databases on the new MySQL server, type “show databases;” (don’t forget the semicolon). You should see a list similar to this:


Note: If you do somehow forget the semicolon (even though I specifically mentioned it), you can always type a single semicolon on a line by itself and press enter to complete the command.

Type “exit” to get out of the MySQL command line and back to the regular Linux command line. Now that MySQL is installed, there is some security configuration that needs to be done. Fortunately, a script exists that will take care of it for you. Type the following to run the script that will lock down the MySQL installation, providing the password you chose above when prompted.


If you didn’t assign the root user a password, then just hit enter when prompted for it, and “n” when prompted to set one.


So far you have the L, A, and M layers installed. Last up, you need PHP. Actually, you need a few different PHP components. Install them all in one shot by passing all of their names to apt-get at once like this:

sudo apt-get install php5 php5-mysql php5-gd

This installation will take a little while. I don’t have a simple test for you to verify the PHP installation, but you’ll know if it works soon enough.


Now that you have a working LAMP stack, it’s time to install the first application on top of it. Webmin can do a lot of the jobs you’d normally do from the command line, but in a much friendlier way.

You can’t just install Webmin through apt-get like the other software packages so far because apt-get doesn’t know about it, or at least not yet. There are several approaches to a Webmin installation, but I’ve found that the easiest is to simply teach apt-get where to get the packages it needs. Add the Webmin repositories to apt-get’s list of sources like this:

sudo nano /etc/apt/sources.list

When the editor appears, add the following two lines to the end of the file:

deb http://download.webmin.com/download/repository sarge contrib
http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib

Note: Your browser may wrap these lines, but make sure they go in the sources.list as two lines like this:


Ctrl-X-Y-Enter to exit nano, saving the file. Next you’ll need to import the signing key that verifies the packages coming from the new repository. These next few commands need to be run as the actual root user of the machine. This is the first time this series has done this, so I’ll break it down for you. Type the following to temporarily become the root user:

sudo su

Your command prompt will change, losing all of its color, and becoming more sinister, dark, and dangerous looking like this:


You are now operating as the root user of the machine. The root user can do pretty much anything. Unlike the Windows world, Linux users try to spend as little time in “God-mode” as possible. Type the following commands to import the signing key:

cd /root
apt-key add jcameron-key.asc

That last “exit” tells the system that you want to stop being the root user now, and go back to being “pi”. The final result should look like this:


There’s one last step before installing Webmin. apt-get needs to update its list of available packages, taking the newly-added repository into account.

sudo apt-get update

Note: You may or may not see an error during this process. I presume that’s why the Webmin folks had you add two repositories, in case one of them is down. If you get an error, try the next steps anyway. If it still fails, double-check that you got the repository addresses exactly right, and try again.

Now that apt-get knows where to get Webmin, you can install it just like you have everything else so far.

sudo apt-get install webmin

When the installation is complete, you can test it by opening a browser, and navigating to the IP address of your server, but specifying https and port 10000 rather than the default http port of 80. If you forget the “https” part, you’ll see a friendly page that offers to redirect you. Either way, you’ll probably also get a warning about the site not having a valid certificate, which it doesn’t. Proceed to the page anyway, and the result should look like this:


Log in as “pi”, and you’ll see the main Webmin interface, which looks like this:


Poke around a bit, and see what Webmin is all about. You can monitor storage and memory usage from here, be notified about updates, apply them, manage user accounts, and a lot more. Look inside the “Un-used Modules” section to see all the things that Webmin could be doing, if you had those packages installed.


Actually, that whole LAMP stack we just installed? Webmin doesn’t really use it. Webmin is built on top of the miniserv web server. It doesn’t use MySql either. I still install it this way because I like to get the basics in and working before I start putting actual, functional software in place. I think putting the LAMP stack in before Webmin just makes sense, and it doesn’t hurt anything. If you wanted to keep things really thin, and you know that none of the other software you’re going to install needs it, you could skip the LAMP stack installation.

What’s next?

In the next post, we’ll add the ability to remote desktop into the Raspberry Pi.

Posted in Computers and Internet, Home Server, Raspberry Pi | Tagged | Leave a comment