How To Make A Raspberry Pi Web Server

https://www.youtube.com/watch?v=WgcNBjIJNYs

The Raspberry Pi is an amazing $35 mini-computer. And in this video, I’ll show you how to set it up as a fully functioning web server.

What is a Raspberry Pi

The Raspberry Pi is a revolutionary mini-computing system that is super cheap. It’s based on the ARM processor, and can be powered through USB (5v) and has all of the standard functionality of regular computers.

Raspberry Pi

There are two types of Raspberry Pi Models: Model A ($25) and Model B ($35). Both models have 256mb of RAM, HDMI and Composite video connections, audio connections, USB power input, USB port output, and SD card input. Model B adds an ethernet port (for network connections) and an extra USB port, which is what makes it more expensive.

Since the Raspberry Pi is in such high demand, attaining one is kind of difficult. At the time of writing this wiki, you can only sign up to be notified when more Raspberry Pi devices are available. You can sign up at Alliedelec (North America only), RS-Online (everyone), or Element14 (everyone).

 

How To Set Up A Raspberry Pi

Raspberry Pi Box

When you first receive a Raspberry Pi, it’s basically just a circuit board in a box. Obviously to run it as a computer, you need some necessary hardware peripherals first. Here’s the list of parts you will need to run it for the first time:

  1. A USB keyboard
  2. An HDMI or Composite cable
  3. A TV or Monitor that is HDMI or Composite capable
  4. A micro-usb power cable
  5. A 2gb or larger SD card (by default, the operating system can only access 2GB)
  6. A network cable (if you want to connect to the network)

Installing the Operating System

Before you can use the Raspberry pi, you have to install the Raspberry Pi Operating System on to the SD card. Don’t worry, it’s not as difficult as it sounds. If you have Windows (you can find Linux and Mac instructions here, there are only 2 things you need to download

Win32DiskImager

  1. The Raspberry Pi Operating System (I chose the “Debian Squeeze” version)
  2. Win32DiskImager (The binary version)

Unzip the Debian Squeeze file that you downloaded. It should produce an ISO file. Now insert your SD card into the computer that you downloaded the files to. Open up Win32DiskImager and for the Device, choose the drive letter of you your SD card. Then click on the folder icon to browser to the Debian Squeeze ISO file that you downloaded. Lastly, click “Write” to write the image file to your SD card. It can take a few minutes to write the files.

Running For the First Time

Once the SD card has been prepped, stick it into your Raspberry Pi. Now you can start plugging in all of your other hardware peripherals, making sure to plug in the micro-usb cable last, since it provides the power.

Raspberry Pi Connections

Once power has been provided, you should start seeing the loading screen for the Raspberry Pi OS on your monitor. The first time, it will take a few minutes to completely load. All other times, it should load pretty fast. You’ll know when it’s through loading because you will see a line that says “raspberry pi login:”. The defaul login name is pi. And the default password is raspberry.

You should now be at a line that says pi@raspberrypi:~$. This means you can start entering in commands. For those of you that are used to a desktop environment, I know this isn’t what you had in mind. So if you prefer a desktop environment, you can type

startx

This will load the desktop environment. From here you can plug in a mouse and use it like you would a normal computer GUI.

 

Initial Software Setup

It’s good practice to update the software and software repositories when you first set up your Raspberry Pi. It’s also important to update the system clock via the internet, since the Raspberry Pi does not have real-time clock. So here’s a list of initial commands to get your system updated:

Configure Time

sudo dpkg-reconfigure tzdata

Update software packages

sudo apt-get update

Update Debian

sudo apt-get upgrade

Updating Firmware

NOTE: If you are running the latest Raspbian hard float release, this update tool will prevent your pi from booting. Only use this if you have Debian squeeze
To keep the Raspberry Pi firmware up-to-date, you have to install a program called Hexxeh’s RPI update tool through Git-hub. Here’s the process

Install certificate authority certificates

sudo apt-get install ca-certificates

Install Git (required to run Hexxeh)

sudo apt-get install git-core

Download Hexxeh’s RPI update tool

sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update && chmod +x /usr/bin/rpi-update

Update the firmware

sudo rpi-update

Reboot

sudo shutdown -r now

 

Setting Up SSH and Remote Connections

You will not have to do this step if you have downloaded Raspbian or Debian Wheezy – SSH should be enabled by default. If it is not enabled, follow these instructions:

To start out, type this then hit enter:

sudo raspi-config

You will now see a screen with a few options. Use the arrows keys to navigate to the SSH option. This will take you to another screen that asks you “Would you like the SSH server enabled or disabled?” Choose the <Enable> option with your arrow keys and hit enter. Select okay, and hit enter. Now, back at the raspi-config screen, navigate to <Finish> and hit enter. You should now be able to use SSH with your Pi!

An ideal setup of Raspberry Pi would be to control it remotely. This can be done through an SSH connection, but by default SSH connections are disabled. Before we enable it, the screen should have the IP address of the Raspberry Pi listed (ex. 192.168.2.37). Write down that IP address as we will need it for the SSH connection. Ok, To enable SSH, simply run this command:

sudo mv /boot/boot_enable_ssh.rc /boot/boot.rc

sudo shutdown -r now

Once the Raspberry Pi reboots, you can now unplug the keyboard and the monitor connections from the Raspberry Pi, as we will no longer need them for the rest of this tutorial.

Putty Window

On a remote Windows machine, in order to connect to the Raspberry Pi, you will need to download Putty, a Windows SSH client. Once it’s downloaded, start it up and type in the Raspberry Pi’s IP address that you wrote down earlier in the Host Name (or IP address) field. Then just click “open”. If it’s your first time connecting, Putty will ask you to store a key authentication, so click “Yes”. Now you should see a login screen where you can log in using your Raspberry Pi login credentials.

Changing the Password

For obvious security reasons, it’s recommended to change the default password to a secure password of your own. After you have logged into your pi account, to change the password, type:

sudo passwd pi

Now you should be prompted to enter in a new password. Once you’ve typed in your password and hit enter, you’ll then be prompted to repeat your password. After typing it in again and hitting enter, you will have successfully changed your password.

Installing the Server

In order to use the Raspberry Pi as a web server, you have to install all the necessary server software components. If you just want a simple HTML server, you can just install that server software (Apache or Cherokee). If you want MySQL and PHP support on your server, you have to install those components separately as well.

Apache Server

Apache server software is the most widely used server software. However, it is a little bit more bloated than the Cherokee server software. If you want a more traditional experience, you can install Apache. Otherwise, you can skip to the Cherokee Server section and install Cherokee. Here’s how to install Apache:

Install Apache with PHP

sudo apt-get install apache2 php5 libapache2-mod-php5

When it asks if you want to continue, press y

Resolve installation error

sudo groupadd www-data

sudo usermod -g www-data www-data

Restart Apache

sudo service apache2 restart

Now if you open up a web browser and type in your Raspberry Pi’s IP address, you should be pull up a the test page for your server!

Cherokee Server

If you want a lighter web server, then Cherokee is better than Apache. And considering the limited resources of the Raspberry Pi, lighter is better. Here’s how to install it:

Prevent install errors

sudo addgroup www-data

Install Cherokee

sudo apt-get install cherokee

Install PHP

sudo apt-get install php5-cgi

Edit the PHP config file

sudo nano /etc/php5/cgi/php.ini

Hit ctrl+W and search for cgi.fix_pathinfo=1, remove the ; form the front of the line
Hit ctrl+X to exit, y to save and enter to confirm

Restart Cherokee

/etc/init.d/cherokee restart

Now if you open up a web browser and type in your Raspberry Pi’s IP address, you should be pull up a the test page for your server!

Installing MySQL

Installing MySQL is pretty simple. You basically just install these packages:

sudo apt-get install mysql-server mysql-client php5-mysql

When it asks if you want to continue, press y

It will eventually prompt you for a new root user password, so create a strong password and continue until the installation is through.

Installing FTP

FTP is not only a great way to remotely add/change files on your website, but it’s also a great way to transfer files to your Raspberry Pi. This is important for installing PHP MyAdmin in the next step. These instructions are for the Apache server install.

Take ownership of the WWW Apache folder

sudo chown -R pi /var/www

Install VSFTP

sudo apt-get install vsftpd

Edit the FTP configuration file

sudo nano /etc/vsftpd.conf

Hit ctrl+W and search for anonymous_enable=YES, and change it to anonymous_enable=NO
Remove the # from in front of local_enable=YES
Remove the # from in front of write_enable=YES
Skip to the bottom of the file and add force_dot_files=YES
Hit ctrl+X to exit, y to save and enter to confirm

Restart VSFTP

sudo service vsftpd restart

Change the root users password

sudo passwd root

Create a new password and then exit out of Putty

exit

Restart Putty and log in as root with the new password
Edit the password configuration file

sudo nano /etc/passwd

Find the line pi:x;1000:1000:Raspberry Pi User,,,:home/pi:/bin/bash and add a # sign to the beginning of it.
Hit ctrl+X to exit, y to save and enter to confirm
Add the pi user as a mod and exit out of the Putty

sudo usermod -d /var/www pi

exit

Restart Putty and log in as pi
Give mod rights to root and exit

sudo usermod -L root

exit

Now your FTP server should be up and running. You can test it out by logging into it with any FTP client such as FileZilla or WinSCP. Use the IP address from your Raspberry Pi that you wrote down earlier, port 22, your Raspberry Pi username (pi), and your password.

Installing PHP MyAdmin

To better manage MySQL databases, it’s often preferred to use the PHP MyAdmin program. So here’s how you can install it:

  1. Download PHP MyAdmin
  2. Extract the zip file to a folder
  3. Using your FTP client upload the extracted PHP MyAdmin files to your web server.

To access PHP MyAdmin, in a web browser type in your Raspberry Pi’s IP address and then add /admin to the end of it (ex. 192.168.2.37/admin). Then you can log in using the root username and password that you created for your MySQL installation.

 

Raspberry Pi – http://www.raspberrypi.org
Raspberry Pi Disk Image – http://www.raspberrypi.org/downloads
Win32DiskImager – https://launchpad.net/win32-image-writer
Putty – http://www.chiark.greenend.org.uk/~sgtatham/putty/

Website Tutorials – http://www.youtube.com/playlist?list=PL6291918FE7103470
Port Forwarding Tutorial – http://www.youtube.com/watch?v=1DSDbvtVIaA

Help support my channel: http://www.patreon.com/tinkernut Follow Tinkernut! Google + Facebook Twitter

13 thoughts on “How To Make A Raspberry Pi Web Server

  1. Charlie says:

    Great tutorial, But it goes fast. A write up with this , for just the steps involved, would be great.

    Would love to see, more videos on Raspberry Pi.

    How about a small video of using a Raspberry Pi for downloading AND Uploading Torrents.
    How about a small video of using a Raspberry Pi for updating DDNS servers like No-Ip in the background.

    Thanks for this Tutorial.

    regards

  2. Peacy says:

    Hey Gigafide,

    So I have a thought and don’t know if it’s possible but maybe you could find a way to make some sort of security webcam out of this? with a web server to check the webcam?

  3. Pingback: Making a Web Server from a Raspberry Pi | Drupelets Ballet

  4. Robert Delphion says:

    This is an excellent tutorial, and your speaking voice is very clear, but I’m a novice with this and couldn’t follow the steps. Did you write them up? Or could you please.

  5. John Lord says:

    I’m curious. How on EARTH did you delete the user pi in the tutorial at 05:21 in the tutorial, and then at 05:28 enter the usermod command WITHOUT getting the message: “usermod: user ‘pi’ does not exist” ?? There MUST be a user pi line in your /etc/passwd file that has NOT been commented out, but what does that line look like?
    I found the reason for the message at this forum post here:
    http://www.raspberrypi.org/phpBB3/viewtopic.php?f=36&t=17830
    I also found information about the usermod and useradd commands at this link
    http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/
    but was not sure what to do next.
    I’m very carefully following the tutorial video to create a second new web server sdcard for my RPi to see what happened when I made my first one. I somehow got the first one working around 3am one night with a fuzzy brain solution I cannot remember. My own /etc/passwd file has the original pi line commented out and has these two lines at the end:
    ftp:x:107:110:ftp daemon,,,:/srv/ftp:/bin/false
    pi:x:1001:110::/var/www:/bin/sh
    but I have no memory of how I did that (completely without understanding WHAT the heck I did! lol!)
    I’d love to know the simple answer to achieve the working solution with simple useradd or usermod commands that do NOT respond complaining that the user named pi doesn’t exist. My brain is completely blank about whatever I did that fixed my problem the first time around, though I obviously added a user named pi back in to the passwd file somehow.
    *** a short time after posting the original comment, I figured out an easy solution (apparently not the one I used the first time that I do not remember how I did.) ***
    This time, I simply ignored the step about commenting out the pi user.
    Then the usermod -d /var/www pi command worked fine, and the resulting server configuration also works just fine. No new steps. Just don’t comment out the pi user line in /etc/passwd and the usermod -d command changes the default directory on that just fine. My put and get commands in psftp also work just fine.

  6. авиабилеты в Румынию says:

    What’s Going down i’m new to this, I stumbled upon this I’ve discovered It absolutely useful and it has helped me out loads. I am hoping to contribute & aid other customers like its aided me. Great job.

  7. Pingback: yellow october

Leave a Reply