How to Make a Raspberry Pi Web Server

If you are looking for a way to make a cheap web server, primarily to be used as a testing environment or to store files, then the Raspberry Pi is perfect for you. What is a Raspberry Pi? It is an inexpensive mini computer, perfect for basic functions. This guide will show you how to take a new Raspberry Pi and turn it in to a web server. Please note that for this article, we will be working in Windows.

Installing the Operating System

Obtain a copy of the Raspberry Pi OS (Operating System) from the link in the sources section.

There are a few different distributions available, but for this article, we will be using the “Raspbian” version.

Extract the image to the SD card.

To do this, we need a tool called the Win32 Disc Imager. A link for this is also available in the sources section. Now open the tool, navigate to the drive letter that your SD card is in, select the location of the Raspberry Pi OS image, and select burn. Wait for it to finish.

Open the SD card in Windows Explorer.

Just create a file with the name . This is a security update introduced since Raspbian Jessie.

Eject the SD card, and place it into your Raspberry Pi, then plug in the rest of the cords, being sure to plug in the mini USB last.

Log in once the operating system loads up.

The default username is “pi”, and the default password is “raspberry”. Newer versions of Raspbian have auto-login enabled by default.

Start by changing the password.

From the command line type:

You can also change your password by typing sudo raspi-config and selecting Change User Password or going to the System Configuration.

Enter your new password and then confirm it.

Please note, the cursor will not move when typing passwords but you are entering text.

Updating Software

Get started with updates.

Because you are running a fresh version of Debian, you will need to do some housecleaning, updating, and installing. First, we are going to update the clock, update our sources, then upgrade any pre-installed packages. Type the following at the command line (press return/enter after each line):

Set the date and time.

From the command line type (replace parts as necessary):

Updating Firmware

Install Hexxeh’s RPI update tool to help keep Raspberry Pi up to date.

To do this, run the following commands (press return/enter after each line):

Configuring SSH

Set up SSH so that we can do everything else from a different computer.

To do this, first note the IP address of the Raspberry Pi

  • You should see something like this:
  • What appears is the IP address of your Raspberry Pi.

Enable SSH and reboot (press return/enter after each line):

Unplug the cords for your USB keyboard and your monitor.

These are no longer necessary, as everything else will be done over SSH.

Download an SSH client like PuTTy (www.putty.org) which can be downloaded for free from Google and connect to the IP address of your Raspberry Pi logging in with the username “pi” and the password you set earlier.

Installing the Web Server

Install Apache and PHP.

To do this, execute the following commands:

Restart the service:

Enter the I.P.

address of your Raspberry Pi into your web browser. You should see a simple page that says “It Works!”

Installing MySQL

Install MySQL.

To do this, install a few packages with the following command:

Setting Up FTP

Install FTP to allow transferring files to and from your Raspberry Pi.

Take ownership of the web root:

Install vsftpd:

Edit your vsftpd.conf file:

Make the following changes:

  • anonymous_enable=YES to anonymous_enable=NO
  • Uncomment local_enable=YES and write_enable=YES by deleting the # symbol in front of each line
  • then go to the bottom of the file and add force_dot_files=YES.

Save and exit the file by pressing CTRL-O, CTRL-X.

Restart vsftpd:

Create a shortcut from the Pi user’s home folder to /var/www:

You can now FTP using the Pi user and access the /var/www folder via a shortcut that should appear on login.

Tips

  • It’s not necessary to install an FTP server if you have the SSH server installed. You can use an application such as WinSCP to connect via SCP which is safer and prevents the need to open up another port on your Raspberry Pi.
  • If you get an error message saying: “wget: command not found”, run “sudo apt-get install wget”

Leave a Comment