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:
This says to start the MySQL command-line interface, and log in as the user “root”. 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
deb 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:
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:
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.
In the next post, we’ll add the ability to remote desktop into the Raspberry Pi.