Instructables

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.
 
Remove these adsRemove these ads by Signing Up

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)

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-Disk-Imager.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.
dale3h1 year ago
Just wanted to share my experience with this Instructable. Everything went smoothly until it was time to connect to MySQL from a remote machine on the same network. So here's how to fix that:

1. Grant access to your remote machine using: GRANT ALL ON *.* TO 'root'@'192.168.1.%' IDENTIFIED BY 'your_password_here'; (I used 192.168.1.% so that any computer on my network can connect to it)
2. Go into the my.cnf file (sudo nano /etc/mysql/my.cnf) file and look for "bind-address" and comment this out (put a # in front of the line)
3. Reload MySQL config (service mysql reload)
4. Restart MySQL server (service mysql restart)

Hope this helps, and thank you for the great Instructable :)
drcurzon (author)  dale3h1 year ago
Hi there,
Thanks for posting this to help others :)
Daniel
aykutcanturk made it!7 days ago

hey, I made it.

only I didnt changed

"#pi:x;1000:1000:Raspberry Pi User,,,:home/pi:/bin/bash"

line, actually I took the # sign back because if you dont "pi" user disappears. php my admin and everything worked well. I set the permissions though, thru filezilla, to 777 for very file and folder under phpmyadmin directory I created. this is my first raspberry pi device and this is my first experiment. I cannot believe its too fast.

thanks for instructions.

photo.JPG
15nhalstead17 days ago
Step 10 installing my php admin I got stuck where do I put the files and I made a folder and it is named admin and I put the files in there and I entered the URL that you have and it says can not find.


Also I can not use the host name to access it I set my host as 'RasoberryPiServer' I went to the net fear configuration in the router and it is reading the host name but when I go to use it as a URL like rasoberrypiserver/admin/..... It does not work!


Do I have to activate things??

Help please. Email me 'email.technology.4@gmail.com
jriach1 month ago
Really great instructable, thank you!
I'm new to this and hope this doesn't sound like a silly question but you mentioned needing to set permissions to access phpMyAdmin from my laptop and I'm getting the error 'you don't have permission to do this'.
Could someone shed a little light on this please?

Thank you!

Jamie
PeterJTK1 month ago

you must have done something that is not in this tutorial in order to address the pi by its hostname. what is missing.?

solved:

hardcoding in

WINDOWS\system32\drivers\etc\hosts

append

192.168.0.XXX myhostname

Top demais meu favorito
techieeb141 month ago

I am still having issues with your instructables. Could it be that I am using the newest version of Raspian?

drcurzon (author)  techieeb141 month ago
Hi there. I would hazard a guess tht yes - it is as this instructable was written with a (much) older version.
I'll update this soon with newer instructions.
I would like it to be soon seeing as this is for a project I don't have a lot of time for.
techieeb141 month ago

I am having trouble following your directions on making the RaspberryPi web server.

I can't run "mv boot_enable_ssh.rc boot.rc" because there is no such directory.

What did you do inbetween 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.

Some personal help would be greatly appreciated.

PeterJTK1 month ago

Daniel, thanks for your reply to my last question.

Here you creating a new usergroup how does this solve the problem.? must the install be run again once the new usergroup is created.?

I also find the syntax strange in "sudo usermod -g www-data www-data". if I understand the Linux synopsis correctly the first instance of "www-data" defines our new usergroup as the initial login group... but I don't understand the purpose of the second one.?

PeterJTK1 month ago

I will be attempting this in a week or so when my Pi arrives, I may have afew questions about various things as I am new to the Pi, Linux, SSH... anyway this seems like a good tutorial to work from. I'm trying to understand as much as possible of what is going on in advance so without further ado; the question: why is it necessary to toggle the interface state.? and why halt.? could the system just be rebooted instead of toggling and stopping.?

drcurzon (author)  PeterJTK1 month ago
Hi there.
If I understand your question correctly, then yes - you could just reboot it. I can't remember why I said to restart the interface then shutdown.

This needs updating soon - if you can wait a week or so I'll update this to work with the newest image.
Thanks and good luck, Dan.
Squidyman2 months ago

on "sudo apt-get install apache2 php5 libapache2-mod-php5" It fails to fetch saying mirror is unavailable. What mirror do you recommend that still works with this instructable? Thanks

Nevermind. I randomly tried sudo apt-get update and that fixed the problem. I don't know why it didn't work before I tried installing Apache. Cool instructable! Could you create a tutorial on other servers given that this article points out that others are better at handling tasks. http://www.jeremymorgan.com/blog/programming/raspberry-pi-web-server-comparison/

Skwurlito2 months ago
Asides from Pwnie Express (Raspberry Pwn) for Raspberry Pi being a debian exclusive (I prefer Raspbian), this doesn't seem cost effective. Between $35&$45 for a RasPi and if you go to adafruit.com it's $12 for the wireless dongle. From there you can program the auto-audits yourself. For mere pocket change you can get a 3AA holder, a small circuit board, a genereric micro usb cable and a few transistors and make a portable battery, all from you local Radio Shack. My way sounds like more fun and it'll fit in your pocket. I believe at one point i saw a pdf on this but the program hadn't been released.
Skwurlito2 months ago
Asides from Pwnie Express (Raspberry Pwn) for Raspberry Pi being a debian exclusive (I prefer Raspbian), this doesn't seem cost effective. Between $35&$45 for a RasPi and if you go to adafruit.com it's $12 for the wireless dongle. From there you can program the auto-audits yourself. For mere pocket change you can get a 3AA holder, a small circuit board, a genereric micro usb cable and a few transistors and make a portable battery, all from you local Radio Shack. My way sounds like more fun and it'll fit in your pocket. I believe at one point i saw a pdf on this but the program hadn't been released.
Ah-che2 months ago

Please Help .. After this step my default user PI cant log into X server or log but not with my desktop and programs ...... Why we must change the default path of main user ?

aautuori2 months ago

Hi

When i type: sudo chown -R pi/var/www
There is written missing operand after <pi/var/www>

How can i fix it ?

lolol789 aautuori2 months ago

Type:

sudo chown -R pi /var/www

You need a space between pi and /var

aautuori lolol7892 months ago

Thanks a lot

Cheng-Yu3 months ago

Hi Guys,

If you use the Raspberry Pi to tv, with usb keyboard, you can login and then on LX Terminal you can type "nano /etc/passwd" then enter.

Now look for pi:x;1000:1000:Raspberry Pi User,,,:home/pi:/bin/bash

And take out the #

Then U Would be able to log in again:)

haunted.haunt3 months ago
Hello I just tried going through most of the steps but when I disconnected from the root SSL and tried to connect to the pi user again, it says invalid login. I then tried to login to the root user and I got the same message. I know I did not mess up the passwords. How do I get into my pi now?
no es necesario hacer los pasos de "At the moment you will need .." en adelante, con abrir el archivo /etc/vsftpd.conf y descomentar local_umask=022, con eso basta
buteman7 months ago
Anyone having to use the ip address of the raspi needs to edit the /etc/hosts file on a Linux computer.

>>> On The Computer You Are Connecting from. <<<

No idea where the file is on Windows machines as I haven't used Windows for over 15 years so maybe someone else can add that info.

You can use any name for it. Suppose you want to call it pi and the raspi is at the address 192.168.3.30 then add the following line to /etc/hosts:

[code] 192.168.3.30 pi [/code]

To do it do:

[code] sudo nano /etc/hosts [/code]

add the line then press control and x then y and enter key.
To prove it works then from the terminal program

[code] ping pi [/code]

will work.
acheong87 buteman4 months ago
On Windows, it's here: C:\Windows\System32\drivers\etc\hosts.
good call. location is the same on a mac. Easiest to use terminal and use the same commands that you post.
nerd74734 months ago
really cool my friend at school was wanting to make a server
itsleif5 months ago
I followed the steps, all works fine, but now I cannot log in any more. After restart the pi user login does not work and the new password does not work either. I also tried the root user with both passwords the old and the new, nothing works.

No I cannot log in my pi any more :( I cannot change the password file either because my mac does not mount the linux partition...

how can login again?
hamcircuit1 year ago
I tried adding that and I still just get a blank page still.
drcurzon (author)  hamcircuit1 year ago
try:
sudo apt-get install phpmyadmin

WAIT FOR IT TO INSTALL

nano /etc/apache2/apache2.conf

AT THE END OF THAT FILE TYPE

#Include phpmyadmin
Include /etc/phpmyadmin/apache.conf

SAVE THE FILE THEN

service apache2 restart

then navigate to:
http://HOSTNAME HERE/phpmyadmin

Let me know how it goes, Dan.
sdobbie drcurzon8 months ago
I tried this and it doesn't work.
don't forget to use sudo before "nano" and "service"
adamant6286 months ago
I already had ssh set up and I'm running on wifi now, so that may explain my problem:

ifdown eth0
ifdown: interface eth0 not configured

ifup eth0 works though
of course right after I post, I tried ifdown after using ifup and it worked.
knick0078 months ago
Hi
I don't understand what to do with PHPmyadmin where did you put it on your raspberry pi?
Thanks
northbynate8 months ago
If you're having trouble logging into the ftp server and can't get the ssh hostname trick to work try: "sudo apt-get install avahi-daemon". After that use yourhostname.local to log in with ssh and in ftp.
northbynate8 months ago
Try "ssh raspberrypi.local". or "ssh XXXXXX.local" where XXXXXX is your hostname.

If that doesn't work install avahi by typing "sudo apt-get install avahi-daemon" when directly logged into the pi.

Then try the ssh'ing into hostname.local again.

Here's a link to a few other intro tips:
http://makezine.com/2012/12/25/ten-raspberry-pi-tips/
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!