You are on page 1of 14

Food

Living

Outside

Play

Technology

Workshop

Raspberry Pi Web Server


by drcurzon on June 3, 2012 Table of Contents Raspberry Pi Web Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Intro: Raspberry Pi Web Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Step 1: You will Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Step 2: Format SD Card . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Step 3: Allow SSH connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Step 4: Change Hostname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Step 5: SSH Login . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Step 6: Change default password (IMPORTANT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Step 7: Install Apache with PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 2 3 4 5 6 8 8

Step 8: Install MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Step 9: Install an FTP server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Step 10: Installing phpMyAdmin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Step 11: Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

http://www.instructables.com/id/Raspberry-Pi-Web-Server/

Intro: Raspberry Pi Web Server


Hi there, This is my first Instructable so all criticisms and comments are welcome. This will show you how to set up a simple wired web server on your Raspberry Pi, with PHP and MySql. The Raspberry Pi is a good choice for a webserver that will not recieve too much traffic, such as a testing server, or small intranet, as it doesn;t get too hot (so is nice and quiet), and only uses around 5 Watts of power (costing 3.50 a year where I am if it's running 24/7) In the future I might add how to set up a wireless server. If you have any problems, post them in the comments, or PM me - I'm happy to help.

Image Notes 1. Raspberry Pi 2. Power Cable 3. Network Cable

Image Notes 1. Web page hosted on Raspberry Pi

Step 1: You will Need


To create a simple web server, you will need: 1. A power supply (Micro USB) 2. A network cable 3. A HDMI cable (or Component cable) as well as a screen and USB keyboard 3. A Raspberry Pi 4. An SD card (2GB or more) 5. An SD card reader for your computer 6. Win32DiskImager (For Windows) or dd (for Unix) 7. The Raspberry Pi Debian Image 8. PuTTY (For Windows) or any other SSH client 9. Around an hour of free time You can download the software from the following locations: http://www.softpedia.com/get/CD-DVD-Tools/Data-CD-DVD-Burning/Win32-Disk-Imager.shtml (for Win32DiskImager) http://downloads.raspberrypi.org/download.php?file=/images/debian/6/debian6-19-04-2012/debian6-19-04-2012.zip (Debian Image) http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html (for PuTTY)

Image Notes 1. PuTTY Download Page

http://www.instructables.com/id/Raspberry-Pi-Web-Server/

Image Notes 1. USB Keyboard 2. Power Cable 3. Network Cable 4. HDMI Cable 5. Raspberry Pi 6. SD Card (2GB or more)

Image Notes 1. Raspberry Pi Downloads Page

Step 2: Format SD Card


Firstly, you need to install the Debian image onto an SD card (2GB or more). (The image can be downloaded from http://downloads.raspberrypi.org/download.php?file=/images/debian/6/debian6-19-04-2012/debian6-19-04-2012.zip ) You can do this using the Win23DiskImager tool for Windows (downloaded from http://www.softpedia.com/get/CD-DVD-Tools/Data-CD-DVD-Burning/Win32-DiskImager.shtml ) Insert your SD card. Once you have downloaded the above, Extract the Debian image, and the Imaging tool, then run Win32DiskImager. Ignore the error that you will see. Select the Image file (debian6-19-04-2012) and your SD card, then click "Write", it will ask you to confirm, click "Yes". Then enjoy a break, as it usually takes a couple of minutes to write. Once the write process has finished, you can remove the SD card, then the fun begins.

Image Notes 1. Downloaded Files Debian Image PuTTY Win32DiskImager

Image Notes 1. Extracted Debian Image 2. Extracted Win32DiskImager

http://www.instructables.com/id/Raspberry-Pi-Web-Server/

Image Notes 1. Ignore the error (Click OK)

Image Notes 1. Run Win32DiskImager

Image Notes 1. Select the Debian Image

Image Notes 1. Selected Image 2. Selected SD Card 3. Click the "Write" Button

Step 3: Allow SSH connections


Now plug the HDMI cable into your Raspberry Pi and your monitor, then add the power cable and SD card, as well as the USB Keyboard. When you first turn on your Raspberry Pi, the boot up might take a while, but be patient. It will also reboot itself once, this is normal. Login with the following information when prompted: Username: pi Password: raspberry Type in the following without the quote marks: "sudo -i " [Return / Enter key] "cd /boot " [Return / Enter key] "mv boot_enable_ssh.rc boot.rc " [Return / Enter key] "reboot " [Return / Enter key] This will restart your raspberry pi.

Image Notes 1. Username: pi Password: raspberry

Image Notes 1. sudo -i

http://www.instructables.com/id/Raspberry-Pi-Web-Server/

Image Notes 1. mv boot_enable_ssh.rc boot.rc Image Notes 1. cd /boot

Image Notes 1. reboot

Step 4: Change Hostname


Now that SSH is enabled, you want to change the hostname so you can connect to it more easily. Login to your raspberry pi with the username pi and password raspberry . Type in the following without the quote marks: "sudo -i " [Return / Enter key] "nano /etc/dhcp/dhclient.conf " [Return / Enter key] Now look for the line "#send host-name "xxxxxx"; " (on mine, xxxxxx is andare.fugue.com ), and remove the "# " symbol from in front of it. Now hold the Ctrl key and press "x " to save the changes. You will be asked to save changes, just type "y " then hit the Return / Enter key. Then type "hostname xxxxxx " where "xxxxxx " is what you want to call your server (I chose "raspberryPi " to make it easy). Please Note that you cannot have any spaces in the hostname. Finally for this step, type in "ifdown eth0 " and hit Return / Enter. Once that has finished, type "ifup eth0 " and hit Return / Enter. Now type "halt " and hit Return / Enter.

Image Notes 1. nano /etc/dhcp/dhclient.conf

Image Notes 1. Remove the "#" symbol from here

Image Notes 1. This one. :D

http://www.instructables.com/id/Raspberry-Pi-Web-Server/

Image Notes 1. Should now look like this

Image Notes 1. with no "#" symbol at the start of the line. Now press the Ctrl key and the "x" key, then release the Ctrl key and press "y" when prompted. Finally press the Enter key.

Image Notes 1. hostname raspberryPi You can replace raspberryPi with anything you want the server to be called (spaces aren't allowed) 2. hostname raspberryPi You can change raspberryPi to be anything you want your server to be called (No spaces).

Image Notes 1. ifdown eth0

Image Notes 1. ifup eth0

Image Notes 1. halt

Step 5: SSH Login


Once your Raspberry Pi has halted, you can disconnect it from the monitor as it is no longer needed. Plug your Raspberry Pi's power connection in, as well as the network cable into your switch, or hub / router. Wait a minute or so, then run your SSH client. (I used PuTTY). Type your hostname into the hostname box, and use port 22. (The hostname is the one you set earlier). Then click "Open ". As this is the first time you have connected to your Raspberry Pi via SSH, you will get a security warning. Click "Yes " to continue. Now you can login to your Raspberry Pi with the username: pi and password: raspberry . Since SSH is working, you no longer need to worry about plugging in a monitor, or keyboard, so you Raspberry Pi can be placed anywhere where there are power and network connections available.

http://www.instructables.com/id/Raspberry-Pi-Web-Server/

Image Notes 1. Raspberry Pi with power and network connections

Image Notes 1. Hostname that you set earlier, and port 22. 2. Click here

Image Notes 1. First time security warning, just click "yes"

Image Notes 1. login with: username: pi password: raspberry

Image Notes 1. All logged in and working

http://www.instructables.com/id/Raspberry-Pi-Web-Server/

Step 6: Change default password (IMPORTANT)


Ok, so SSH is working, and you have access to your Raspberry Pi, but it's now accessible by anyone on your network. To change the default password, start an SSH session (step 5), and login, then type "sudo -i ", hit Return / Enter, then type "passwd pi " and hit Return / Enter. Then you can type in your new password, it will ask you to confirm the password.

Image Notes 1. sudo -i [Return / Enter] passwd pi

Image Notes 1. Type in your password Confirm it

Step 7: Install Apache with PHP


Again, either start an SSH session, or continue if you're already in one. Type in "sudo apt-get upate " Once this is complete, you may recieve an error, just run the same command again to resolve this. Then type "sudo apt-get install apache2 php5 libapache2-mod-php5 " It will say "Do you want to continue", just press "y " and hit Return / Enter. Wait for this to finish (as it may take a while). When it is finished, you may have noticed that there was an error, to solve this, type "sudo groupadd www-data ", then " sudo usermod -g www-data www-data ". Now restart apache with "sudo service apache2 restart ". This time there should be no errors. If you now start a web browser on your computer, and type your hostname into the address bar, you will get the apache installed page. To enable htaccess files you must modify the config files, like so: Type "sudo nano /etc/apache2/sites-enabled/000-default " and hit Return / Enter. You'll see a line like the following: "AllowOverride None " - change this to "AllowOverride ALL ". (see image for more detail) Then hold the Ctrl button and press the "x " key, then press "y " when prompted and hit Return / Enter. Now restart apache with "sudo service apache2 restart ".

Image Notes 1. sudo apt-get update

Image Notes 1. You may get this error, just run apt-get update again.

http://www.instructables.com/id/Raspberry-Pi-Web-Server/

Image Notes 1. All better

Image Notes 1. sudo apt-get install apache2 php5 libapache2-mod-php5

Image Notes 1. sudo groupadd www-data

Image Notes 1. sudo usermod -g www-data www-data

Image Notes 1. sudo nano /etc/apache2/sites-enabled/000-default

Image Notes 1. Change this one

http://www.instructables.com/id/Raspberry-Pi-Web-Server/

Image Notes 1. To this

Image Notes 1. sudo service apache2 restart

Image Notes 1. Your web server is running :D

Step 8: Install MySQL


Again, either start an SSH session, or continue if you're already in one. Type in "sudo apt-get install mysql-server mysql-client php5-mysql " and hit Return / Enter. You will be asked "Do you want to continue?", press the "y " key, then Return / Enter. This will take a while to download and install, but a screen will appear asking you to set "New password for the MySQL "root" user ", enter a password, then confirm it. Again, wait a while, then you're done.

Image Notes 1. apt-get install mysql-server mysql-client php5-mysql

Image Notes 1. Enter, then confirm, a password

http://www.instructables.com/id/Raspberry-Pi-Web-Server/

Image Notes 1. Complete

Step 9: Install an FTP server


For this I chose to use vsftp, as it's pretty simple to set up. Again, either start an SSH session, or continue if you're already in one. Type in "sudo chown -R pi /var/www " <-- IMPORTANT (otherwise you won't be able to upload anything) Type in "sudo apt-get install vsftpd " and hit Return / Enter Now type in "sudo nano /etc/vsftpd.conf " and hit Return / Enter Search through the file and change the following lines: anonymous_enable=YES Change To anonymous_enable=NO #local_enable=YES Change To local_enable=YES #write_enable=YES Change To write_enable=YES Also, add a line to the bottom of the file: force_dot_files=YES Then hold the Ctrl key and press "x ", then "y ", then the Return / Enter key. Now restart the FTP server with "sudo servce vsftpd restart " At the moment you will need to change the directory every time you login by FTP, to solve this: Type: "sudo -i " "passwd root " Type in any password (this is only temporary) "exit " "exit " Start a new SSH session Username: root Password (the one you just set) "nano /etc/passwd " find the line "pi:x;1000:1000:Raspberry Pi User,,,:home/pi:/bin/bash " and change it to "#pi:x;1000:1000:Raspberry Pi User,,,:home/pi:/bin/bash ". Then hold the Ctrl key and press "x ", then release Ctrl and press "y " then hit Return / Enter. "usermod -d /var/www pi " Now close the SSH session, and start a new one with username: pi and your password, and type the following: "sudo -i " "usermod -L root " "exit " Now you are able to connect to your Raspberry Pi with an FTP client, using the following information: Host: (Hostname you set - I used raspberryPi) Username: pi Password: (Password you set previously) Port: 21

http://www.instructables.com/id/Raspberry-Pi-Web-Server/

Image Notes 1. sudo apt-get install vsftpd

Image Notes 1. Install complete

Image Notes 1. Edit the vsftpd.conf file

Image Notes 1. sudo service vsftpd restart

Image Notes 1. This user here, Add a # in front of the line

Image Notes 1. Now you can connect to your Raspberry Pi

http://www.instructables.com/id/Raspberry-Pi-Web-Server/

Step 10: Installing phpMyAdmin


Installing phpMyAdmin is a simple task. 1. Go to http://www.phpmyadmin.net 2. Download the zip file 3. Extract it to a folder 4. Upload the extracted files to your server (you may need to set permissions) For the last point, start your FTP client, then connect to your Raspberry Pi, copy the files across and you're done. Now navigate to where you installed phpMyAdmin (for me it's http://raspberryPi/admin ) You can login with the information: Username: root Password: What you set earlier (in step 8)

Image Notes 1. phpMyAdmin download Image Notes 1. Extracted files

Image Notes 1. Location you copied to 2. Login with root, and the password you set

http://www.instructables.com/id/Raspberry-Pi-Web-Server/

Image Notes 1. phpMyAdmin dashboard

Step 11: Overview


Now you have a Raspberry Pi server consuming around 5 Watts (very economical :D) Installed on your server is: - SSH - Apache web server - PHP5 - MySQL server - VSFTP FTP server - phpMyAdmin For the future, a firewall is recommended. (I may do an instructable on this soon) I may also add a wireless dongle to make it a wireless server that just requires a power connection (or battery) making a completely portable server. I hope this serves to help some people, and all criticisms are welcome. If you have any problems, post them in the comments, or PM me - I'm happy to help. Daniel.

Related Instructables
Using a computer without a hard drive. by Computothought Installing a new virtual host in the Apache Web server by Tarek_Loubani Linux (Knoppix ) via USB on HP tc4400 Tablet PC by erckgillis

Make a Server Out Of An Old PC by Seski

Get Started in PHP by gnoseon

Introduction to installing web apps. by Computothought

http://www.instructables.com/id/Raspberry-Pi-Web-Server/

You might also like