kaspencer
Posts: 86
Joined: Wed Mar 07, 2012 11:37 pm
Location: UK, England, Wiltshire

How to set up your Pi as your web server

Sun Dec 02, 2012 3:06 pm

Greetings all ...

I have prepared an extensive document which explains exactly how to set up your Raspberry Pi as a web server, including securing a directory by username and password, analysing statistics via Webalizer and making your site available in the Internet at large by using a DNS service.

The document has been prepared using some information on this site, but most of it as a result of my own work with the Pi, and my web work generally.

The document can be downloaded, or just read, here:
http://my-music.mine.nu/images/rpi_rasp ... _setup.pdf.

Maybe the admins might make it a sticky post if they like it. Others, just please let me know of any problems, and whether it is useful.

Regards

Kenneth Spencer
2xRPi 1, 2xRPi 2, 2xRPi4.
KODI: on RPi 2.
Webserver: on RPi 2.
PDC & fileserver: 4TB disc +RiscOS Pi on RPi 2 + 4.
Book: All about your computer - http://goo.gl/ZQf7c7

bgirardot
Posts: 518
Joined: Wed Oct 10, 2012 6:20 am
Location: Switzerland

Re: How to set up your Pi as your web server

Sun Dec 02, 2012 3:47 pm

I think it is good.

Isn't ServerName in a virtual host usually a full host.domain.tld name? I am not familiar with seeing them as just one word.

kaspencer
Posts: 86
Joined: Wed Mar 07, 2012 11:37 pm
Location: UK, England, Wiltshire

Re: How to set up your Pi as your web server

Sun Dec 02, 2012 4:31 pm

Thanks BG ...

I have seen it as both, but the reason why I have given it a server-only name rather than the fully qualified domain name was because it is most likely that the beginner user has no domain name and so the server name is the FQDN.
I do take your point, which is essentially one of good practice, so, even though what is set out in the document works perfectly, I think I may well add an amendment to the servername.conf file at the stage when the user has selected a domain and subdomain. (That is what is in the document works perfectly e&oe!).

Best wishes

Ken
2xRPi 1, 2xRPi 2, 2xRPi4.
KODI: on RPi 2.
Webserver: on RPi 2.
PDC & fileserver: 4TB disc +RiscOS Pi on RPi 2 + 4.
Book: All about your computer - http://goo.gl/ZQf7c7

bgirardot
Posts: 518
Joined: Wed Oct 10, 2012 6:20 am
Location: Switzerland

Re: How to set up your Pi as your web server

Mon Dec 03, 2012 5:52 am

On another thread someone was having problems installing apache2, the apt-get install process failed.

A couple of folks mentioned that you should always do:

sudo apt-get update && sudo apt-get upgrade

before installing packages to help prevent issues with following apt-get install commands.

You might want to add those two commands as the first step to installing the rest of it.

plugwash
Forum Moderator
Forum Moderator
Posts: 3650
Joined: Wed Dec 28, 2011 11:45 pm

Re: How to set up your Pi as your web server

Mon Dec 03, 2012 6:54 pm

First comment: I really see no need for this to be a PDF, an ordinary web page would have been just fine and less of a pain to read.

Second comment: the standard Pi setup of a locked out root account and a Pi account with sudo privilages shouldn't cause any problems. If you preffer to log in directly as root then fine but it's really not a requirement.

Third comment, you should generally run apt-get update at the begging of any installation setup. Apt-get upgrade can be run when it suits you (it's a good idea to keep your system up to date but it's not critical to do it at the same time as installing software unless your system is horriblly outdated)/

Fourth comment, for some reason you seem to think a ssh client relies on a FTP server. It doesn't, you also seem to think using FTP is a good idea, I would argue that generally it isn't unless you have special requirements.

kaspencer
Posts: 86
Joined: Wed Mar 07, 2012 11:37 pm
Location: UK, England, Wiltshire

Re: How to set up your Pi as your web server

Mon Dec 03, 2012 8:08 pm

Thanks Pl...sh ...

It's a PDF to allow easy printing - there's a lot to follow if reading from the screen only. A web page would be less printer-friendly and I'm sure I'd have requests to make it a PDF.

I agree that it isn't a requirement to log in as root, and that it doesn't cause any problems, but I prefer to do that so as to avoid repeatedly the need to SUDO ...

Third comment ... no problem with that.

Fourth comment ... I'm not sure why it comes over that way. It wasn't intended but there we are!

Thanks BG ... that's a good idea ... I'll do that when I next update the document.

All the best

Kenneth Spencer
2xRPi 1, 2xRPi 2, 2xRPi4.
KODI: on RPi 2.
Webserver: on RPi 2.
PDC & fileserver: 4TB disc +RiscOS Pi on RPi 2 + 4.
Book: All about your computer - http://goo.gl/ZQf7c7


kaspencer
Posts: 86
Joined: Wed Mar 07, 2012 11:37 pm
Location: UK, England, Wiltshire

Re: How to set up your Pi as your web server

Tue Dec 04, 2012 12:20 am

Thanks Saj.

There's usually more than one way to skin a cat! And oftem they'll all work.

All the best,

Ken.
2xRPi 1, 2xRPi 2, 2xRPi4.
KODI: on RPi 2.
Webserver: on RPi 2.
PDC & fileserver: 4TB disc +RiscOS Pi on RPi 2 + 4.
Book: All about your computer - http://goo.gl/ZQf7c7

Xanii
Posts: 1
Joined: Wed Dec 05, 2012 12:45 pm

Re: How to set up your Pi as your web server

Wed Dec 05, 2012 1:38 pm

Excellent document. Thanks for this.

kaspencer
Posts: 86
Joined: Wed Mar 07, 2012 11:37 pm
Location: UK, England, Wiltshire

Re: How to set up your Pi as your web server

Wed Dec 05, 2012 5:41 pm

Glad you liked it, Xan.

It seems quite popular as it is getting about 120 downloads a day!

Ken
2xRPi 1, 2xRPi 2, 2xRPi4.
KODI: on RPi 2.
Webserver: on RPi 2.
PDC & fileserver: 4TB disc +RiscOS Pi on RPi 2 + 4.
Book: All about your computer - http://goo.gl/ZQf7c7

idries
Posts: 1
Joined: Fri Dec 14, 2012 1:15 pm

Re: How to set up your Pi as your web server

Fri Dec 14, 2012 1:18 pm

Thanks, great tutorial. But i did it yesterday and today I turned my Pi on and when I tried to access the page the Pi is serving it would not work.

Any help would be greatly appreciated!

User avatar
richiepp
Posts: 140
Joined: Wed Dec 19, 2012 4:56 pm

Re: How to set up your Pi as your web server

Wed Dec 19, 2012 5:24 pm

Thanks Ken, this is an awesome guide! And I actually like it in pdf format ;)

I've worked with LAMP servers for years but never administered one, this is cool.

As I work through the tutorial I'm getting stuck on the phpmyadmin step. I followed your directions exactly as you describe in the tutorial but for some reason the index page won't render. I've quadruple checked my php ini file and it matches the tutorial. When I pull up localhost/phpmyadmin/index.php the page is completely blank and doesn't have any content in the html code.

I just reinstalled phpmyadmin and I'm getting the same behavior. My error log tells me it's a 500 266, I have a vague understanding of the 500 error but not the 266. I also notice that I get the same behavior on all php files in the localhost/phpmyadmin directory, none of the are executing. I am however able to access the html files like localhost/phpmyadmin/Documentation.html which tells me the redirect is functioning as it should.

I've been rebooting as a I go along but nothing seems to work.

I went ahead in the tutorial and installed Webmin and got it working. I also installed webalizer but it seems to have a similar php problem. If I had to guess the solution likes in the php.ini file but don't have a clue what to change.

Please help!

Thanks
Rich

User avatar
richiepp
Posts: 140
Joined: Wed Dec 19, 2012 4:56 pm

Re: How to set up your Pi as your web server

Thu Dec 20, 2012 2:34 am

OK, after a lot of searching I found the solution which is detailed here

http://sourceforge.net/projects/phpmyad ... ic/5387764

kaspencer
Posts: 86
Joined: Wed Mar 07, 2012 11:37 pm
Location: UK, England, Wiltshire

Re: How to set up your Pi as your web server

Fri Dec 21, 2012 10:54 am

Thanks for the posts Rich ... and I'm glad you liked the tutorials.

Regarding the problem - I haven't encountered the reported issue during my researches, and I have set up quite a number of LAMP servers on various platforms over the years - but more on Intel architecture. I
I'm glad that you found the answer, but I think I had better leave any comments to others because I haven't had to deal with it myself.

All the best!

Ken
2xRPi 1, 2xRPi 2, 2xRPi4.
KODI: on RPi 2.
Webserver: on RPi 2.
PDC & fileserver: 4TB disc +RiscOS Pi on RPi 2 + 4.
Book: All about your computer - http://goo.gl/ZQf7c7

lindasy2
Posts: 3
Joined: Sun Dec 30, 2012 3:22 am

Re: How to set up your Pi as your web server

Sun Dec 30, 2012 3:25 am

Very extensive and helpful though it could do with a screenshot or two

Thanks for the guide!

kaspencer
Posts: 86
Joined: Wed Mar 07, 2012 11:37 pm
Location: UK, England, Wiltshire

Re: How to set up your Pi as your web server

Sun Dec 30, 2012 11:38 am

Thanks Lindasy ... I'm glad you found it helpful.

I'll consider putting in some screenshots, as I agree that they could be helpful.

One other point worth noting: if anyone has tried to follow the instructions word-for-word, (and as there have been hundreds upon hundreds of downloads of this document, some people must have done) you may come across a problem with the oursites.conf file. Unfortunately, in the document that was online for most of the time, the closing tag for each the two instances of <VirtualHost> did not contain a forward stroke character ("/") ("slash" for our American friends). I have now corrected this error in the online document.

Thanks again (and a Happy New Year too)

Ken
2xRPi 1, 2xRPi 2, 2xRPi4.
KODI: on RPi 2.
Webserver: on RPi 2.
PDC & fileserver: 4TB disc +RiscOS Pi on RPi 2 + 4.
Book: All about your computer - http://goo.gl/ZQf7c7

lindasy2
Posts: 3
Joined: Sun Dec 30, 2012 3:22 am

Re: How to set up your Pi as your web server

Mon Dec 31, 2012 6:14 am

Just a question but , how would you go about installing python on a lamp server?

kaspencer
Posts: 86
Joined: Wed Mar 07, 2012 11:37 pm
Location: UK, England, Wiltshire

Re: How to set up your Pi as your web server

Mon Dec 31, 2012 9:30 am

Deleted - see next post ...
Last edited by kaspencer on Mon Dec 31, 2012 9:35 am, edited 1 time in total.
2xRPi 1, 2xRPi 2, 2xRPi4.
KODI: on RPi 2.
Webserver: on RPi 2.
PDC & fileserver: 4TB disc +RiscOS Pi on RPi 2 + 4.
Book: All about your computer - http://goo.gl/ZQf7c7

kaspencer
Posts: 86
Joined: Wed Mar 07, 2012 11:37 pm
Location: UK, England, Wiltshire

Re: How to set up your Pi as your web server

Mon Dec 31, 2012 9:33 am

Thanks Lindasy ...

I haven't explicitly installed Python on the webserver. However, this is because as far as I can say Python is installed by default with Raspbian Wheezy.

If you type:
python
at a terminal window or at a remote login via PuTTy or the like, you will see the response:
Python 2.7.3xxx
Information etc.


Then tap [Ctrl]+D to leave Python.

I have little experience of programming on any Linux platform (and least of all in Python) - a bit of C on Unix years ago - but I hope soon to investigate that aspect. Having said that, I have written lots of commercial software in C (originally for DOS and later for Windows and some for RiscOS - A440/1 and RiscPC), so it will be very tempting to stick with what I know!

All the best

Ken
2xRPi 1, 2xRPi 2, 2xRPi4.
KODI: on RPi 2.
Webserver: on RPi 2.
PDC & fileserver: 4TB disc +RiscOS Pi on RPi 2 + 4.
Book: All about your computer - http://goo.gl/ZQf7c7

PhillyNJ
Posts: 112
Joined: Sat Dec 29, 2012 4:07 am

Re: How to set up your Pi as your web server

Mon Dec 31, 2012 12:31 pm

Cool post. Whats the chance on putting this in the wiki?

kaspencer
Posts: 86
Joined: Wed Mar 07, 2012 11:37 pm
Location: UK, England, Wiltshire

Re: How to set up your Pi as your web server

Mon Dec 31, 2012 5:55 pm

Thanks for the comment Phil ...

I'd be perfectly happy for it to go onto the wiki, but I suppose it's only the admins who can do that! I have no idea how they decide these things though.

Happy New Year to you!

Ken
2xRPi 1, 2xRPi 2, 2xRPi4.
KODI: on RPi 2.
Webserver: on RPi 2.
PDC & fileserver: 4TB disc +RiscOS Pi on RPi 2 + 4.
Book: All about your computer - http://goo.gl/ZQf7c7

PhillyNJ
Posts: 112
Joined: Sat Dec 29, 2012 4:07 am

Re: How to set up your Pi as your web server

Mon Dec 31, 2012 7:38 pm

Hi Ken,

You can add pages to the wiki. Just apply for an account. Takes about a day for the approval. And Happy New Year to you too :D

lindasy2
Posts: 3
Joined: Sun Dec 30, 2012 3:22 am

Re: How to set up your Pi as your web server

Tue Jan 01, 2013 5:23 am

Just noticed but their seems to be a type in the apc install command, shouldnt't their be a - hyphen between build and essentials

BobCochran
Posts: 27
Joined: Sat Dec 29, 2012 2:51 am
Location: Greenbelt, Maryland, USA

Re: How to set up your Pi as your web server

Tue Jan 01, 2013 6:16 am

I disagree that FTP is essential to running a web server. It is a security risk and should not be used at all unless the person running the server is very experienced in web development, has a background in firewall administration, and is capable of applying strict access controls. You have to open a number of ports for FTP to work properly, and each port being opened increases the attack surface on the server. It makes you a sitting duck for every attacker on the Internet.

Configuration for FTP is a nightmare. Another burden the inexperienced don't need.

In Section A4 you write:

"You will use proftpd later on to transfer your website files to the newly configured web server."

This is unnecessary. You can transfer website files securely using scp (secure copy...part of the ssh distribution.) instead of FTP. Putty is quite capable of doing secure copies as well from the Windows side. With modern use of Bittorrent, http/https, and wget as download tools, ftp isn't really necessary any more. If you have administrative and physical access to the web server you don't need FTP to begin with. From the perspective of Internet users, only a select few would be developing web content, and these people are often not the ones who put the content on the server. For one- or two-person Mom and Pop websites, scp'ing the content to a staging area and then logging in to the server over ssh is safer than allowing direct FTP uploads of content to the server. Users wanting to download content can do it over http or https. Many large enterprises disallow or very strictly control the use of FTP on the corporate network, and they have good reason.

A public (Internet-facing) web server is going to be attacked within a few seconds of port 80 being opened, and any other open ports such as those for ftp and email will be similarly attacked...mercilessly...until something breaks. I don't really see the need for FTP here as a result. "FTP" is not a part of the traditional Linux/Apache/MySQL/PHP (LAMP) server.

Respectfully

Bob

BobCochran
Posts: 27
Joined: Sat Dec 29, 2012 2:51 am
Location: Greenbelt, Maryland, USA

Re: How to set up your Pi as your web server

Tue Jan 01, 2013 7:10 am

Now I come to the final part of the guide, Section C1 "Copy your Website Files". I continue to have difficulty understanding why you would need to install an FTP server on the Raspian web server.

Anyone can copy an entire website, anywhere in the world, using the web browser's capability to save complete web pages. For example Firefox has a File...Save Page As... choice which will capture all the files from a web page one is surfing. It is a slow but safe way to download and transfer content from one web server to another.

Source code for script files may not be downloadable in the above way. Configuration files such as httpd.conf will likewise not be downloadable. That is not such a problem: if one maintains a website on a hosting service then surely all the script and configuration files are duplicated on a totally separate test machine that the site creator has some form of access to -- the server machine that was used to test the website to begin with. One does make a backup copy of expensively developed and valuable content, right? Just in case the hosting company goes belly up and leaves the site owner flapping in the breeze? One can copy from that development machine to the Raspian machine rather than over FTP between the hosting provider and the Raspian machine. It can more easily be done over scp or even rsync.

One could even keep a github repository for the entire website and git clone it to a new server as needed. Git doesn't use or need FTP.

All in all, I think instructions to install FTP should be removed from your How To guide. It is a great guide, but FTP is a real threat to the inexperienced webmaster.

Respectfully,

Bob

Return to “Beginners”