Computer Engineering Student & IEEE Student Branch Chair
Kyle's Blog :Return to Blog
The Raspberry Pi Part IV: Setting up a Simple Server
At this point in the series, you’ve set up Arch Linux ARM on your Raspberry Pi and you are ready to turn it into something. In this article, you’ll set up a Raspberry Pi as a simple local network server that can serve up web pages and act as an FTP server. This article will only explore setting up the server for use on local networks, not through the internet.
If you haven’t already set up the “ sudo ” software and a separate non-root account on your Raspberry Pi, and you plan to have it accessible to the public on a network, I would recommend you do so. You don’t want people to have root access to your Raspberry Pi over the network; they could seriously mess with your setup or steal your files. There are plenty of good resources online for setting up sudo. A setup guide is available here for Debian. We’re using Arch Linux ARM, but the process is mostly the same (note: you have to use pacman on Arch instead of apt-get to install the software).
Also, if you’re not familiar with command-line text editors like vi or nano, you can find many quick references online. One such reference for Vi is located here.
You’ll need to define a hostname that you will use to refer to your Raspberry Pi Server. You’ll want to edit your hostname configuration file, located at /etc/hostname, using any text editor. For example you can use:
You’ll then want to change the file to contain the name by which you want your Raspberry Pi known. In this example, my Raspberry Pi will be known as “webpi”. Any time you see the name “webpi” for the remainder of this article it should be replaced with whatever you’ve decided to call your server.
Once you edit the hostname, you should also edit the hosts file to let the Raspberry Pi know that it should refer to itself with that name. This time we want to edit /etc/hosts .
You want to add 127.0.0.1 and ::1 as webpi.
Do so by inserting the lines reading:
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost.localdomain localhost webpi
To ensure your setup is complete, restart your Raspberry Pi, and then attempt to ping your hostname locally using the command ping webpi.
Note: Depending on the quality of your router, you may be able to skip this step. Try pinging webpi before editing your host file on your client machines
Now, get your local ip address by running the “ ifconfig ” command. It will most likely be of the form 192.168.. if you’re using a local home network. Make note of the ip address.
If that is successful, hop onto another computer on the local network and attempt to ping the local IP address of the Raspberry Pi that you have noted down. If it works and you get a response, add that IP address to your hosts file on the machine you’d like to access the server from.
If you’re using Windows, you want to edit C:/windows/system32/etc/hosts, and on Linux you want to edit /etc/hosts. Add the line:
Try to ping again by using the “ ping webpi ” command. Hopefully it will work.
If you’re stuck on this step, have a look at your router’s settings to make sure it isn’t interfering.
Now that we can access our Raspberry Pi on the network, we only need to setup a webserver to be able to serve web pages. A very common webserver is Apache. Install Apache on your Raspberry Pi by using pacman:
pacman -S apache
Before we start the webserver, we may want to configure Apache. To do so we must write the configuration files that Apache will use to run the server. Navigate to /etc/httpd/conf. This is the folder that Apache stores it’s configuration files. We’ll want to edit httpd.conf, which is the main configuration file for Apache. The default settings will usually work for most applications. If you want you can go through and change settings as desired. For example, you may want the DocumentRoot (the folder the web server points to when serving files to a client) to be pointed to a different folder.
Once that is completed, you can run httpd . This will start the HTTP Daemon which will serve web pages up to clients. To ensure it’s working, hop on another computer on your local network and enter webpi into the URL bar. You should get a page titled: “Index Of /.”
At this point, we have a basic functional web server. If you haven’t changed the DocumentRoot of Apache then putting the following HTML into an HTML file somewhere in the folder /srv/http will make that webpage accessible through a browser by navigating to:
1 2 3 4 5 6
You’ve now set up a simple web server that you can use to make pages accessible to anyone on the network. While this isn’t useful on it’s own, it allows you to set up a numerous amount of web applications. There is a ton of open source stuff online, everything from open source scheduling software to project management tools. Having these applications available for free from any computer on your local network is a definite asset. (That being said, for many of these tools you will need to install a full Web Server Stack. For more information see: http://en.wikipedia.org/wiki/LAMP_(software_bundle))
Setting up an FTP Server
You may also want to set up an FTP server to allow you to easily upload and download files from your Raspberry Pi. After setting up FTP access to your Pi on the local network, you can use it as a central storage location in your home or workplace. Attaching an external USB hard-drive to your Raspberry Pi can allow you to store a lot of files in a way that’s easily accessible to anyone that has access.
The easiest way to set up an FTP server is to install OpenSSH. Do so using
pacman -S openssh
Restart your Raspberry Pi and you should now be able to access your Pi’s filesystem using any FTP client. One graphical client is FileZilla . You can connect to your Pi using the following credentials:
hostname: <Your Pi’s Hostname or local IP Address> login: <Your Pi login> password: <Your Pi password> port: 22
If everything is working the login should work, and you’ll be able to upload and download files to and from your Raspberry Pi.
Configuring the Services to Autostart
Last but not least, make sure that your server services are configured to automatically start when the Pi is powered on (this way you don’t have to turn them on manually every time the power goes out). In order to do that, use the following command:
systemctl enable httpd.service
systemctl enable sshd.service
The previous two commands tell Arch to enable httpd and sshd , our web and SSH/FTP servers, as system services, and they should now automatically start on boot.
Now you’ve turned a Raspberry Pi with Arch Linux ARM into a local network server that you can use to store information, data files, and more. Check back on EEWeb in the future to start learning how to develop some cool applications for a Raspberry Pi.