Start |
You are here: Start » Webserver

APACHE Home Webserver

Raspy as Home Webserver

A home webserver does not need to be a large computer.
Your Raspberry Pi can do the job ... as my Raspy does.

Raspy's Website

Website creation for Raspy: Web2Date 8.0 (w2d). You can use any other program
Size: 140 MB+ & Backup storage 377 MB+
Website upload: WinSCP 5.1.4 (very fast on the local LAN)


Pre-requisites

Apache

Static IP address or DynDNS server, SSH Access (Pi).
The ability to host and serve webpages as a web server, and the software we’re going to install is called Apache. Your web server will sit on your local network and be available to the rest of the world via the Internet.

APT-GET
Apt-get is a command you’re going to be seeing a lot of. We use it to install applications on your Pi. You can think of it like an App Store, except you have to know the name of the app you want to download first, rather than browse through a list. Don’t worry though, in this tutorial you’ll be shown exactly what you need to download and why we’re downloading it.

Before We Get Started
This tutorial is going to take some time. Somewhere between 10-20 minutes, depending on your network connection as you’ll be downloading software from the Internet straight on to your Pi. So be prepared to be patient.
Also, you should probably update the existing software on your Pi first before carrying out the rest of the installations. You can do this by typing the following:

sudo apt-get update
This is the equivalent of running Software Update on your Mac or Microsoft Update on Windows, and can also take some time. You can read this command as 'Hi there, I’m the superuser here, please do go and get any updates for my pi. Thanks!'


Configuration

Step 1: SSH

ssh pi@192.168.1.x

(again, where 192.168.1.x will be your own IP address). If you haven’t connected before, you’ll be asked if you want to add your Pi’s address to your list of ‘known hosts‘. Go ahead and press Y to continue. You’ll be asked to put in your password – remember that, by default, SSH will not show you your password as you type it in.


Step 2: Apache

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

We’re installing three things here, but doing them all at once: apache2, which is the webserver software; php5, which is a scripting language for developing web sites; and libapache2-mod-php5, a module that allows the PHP language to talk with the Apache webserver. We could write out three commands like this:

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

..but putting it all into one command saves us a little bit of time.


Step 3: MySQL

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

As with the previous command, we’re rolling three installations into one: mysql-server, which is free database server software that powers an enormous chunk of the web; mysql-client, again part of MySQL – this allows you to interface with your MySQL database; and php5-mysql, which enables the PHP scripting language we installed in step 2 to talk to MySQL.



Step 4: Restart Apache

sudo apachectl restart

You might see this written differently across the web – ‘sudo service apache2 restart’ – for example, but in essence, both commands are the same. We’re telling the apache web server that it needs to restart once we’ve finished installing all this extra functionality over the top of it. Notice that we don’t need to actually restart the Pi – just the Apache service.


Step 5: Creating phpinfo.php
We could test the web server out right now – in fact, it’s pretty much ready to go if all you want to do is serve HTML files – but before that we’re just going to make sure that our installation of PHP went okay. We’re going to do that by creating a file called phpinfo.php and insert some code in there that should display information about our PHP installation when we connect to the web server.

sudo nano /var/www/phpinfo.php

sudo you know. nano is a text editor, similar to TextEdit on a Mac or NotePad in Windows, only when you run it, it won’t open up in a nice graphical window. nano runs inside the Terminal window and looks like this:


Instead of a menu system along the top of the screen, you’ll notice that all the commands are at the bottom of the screen and can be used by pressing the Ctrl button (that’s what the ^ means) and the appropriate letter. So ^G brings up the Help menu for example. What you may not see is a ‘Save’ function. In nano you save by exiting first with ^X, then confirm that you want to save your changes by pressing Y. This only works on files that you have permission to edit, which is why we run sudo when we run this command.
The /var/www/ is the path to your web server on the Pi, and where all your files and webpages will live. phpinfo.php is the file that we’re editing. Once of the nice touches about nano is that it actually creates the file for us as we type it in. Prior to typing the above command in, the phpinfo.php file didn’t exist – and now it does!
Enter the following code into your phpinfo.php file:

<?php phpinfo(); ?>

and then exit your file, confirming that you want to save the changes.
The ‘<?php ?>’ part of the code above is an opening and closing tag, meaning that whatever we put inbeween, we want the computer to do for us. the phpinfo(); is a function that outputs information about the PHP configuration on your web server.

Step 6: Testing the Web Server
Here’s the part where you can test out everything works by opening up a web browser and typing in the IP address of your Pi followed by a / and the phpinfo.php filename:

http://192.168.1.x/phpinfo.php

If everything’s gone correctly, you should see a page like this:


and if you do – congratulations! You’ve just installed and set up your very own web server on your Pi.

Step 7: Creating index.html
While PHP might be a little daunting to get started with, you could still easily have a go at creating standard HTML pages. The first file a web browser will look at when pointed at a web server is (usually) called index.html. You can try this by using Terminal and typing the following:

sudo nano /var/www/index.html to create your very first file.

_________________________________________________


Addition from HB9CZV:

For a more extensiv web presentation, you need a web design program. I use web2date 8.0 (a Germany product).
The webpage is designed locally. The project elements are pages, sections and elements.

web2date generates html code, which must be transferred by an FTP program to the Apache server on the Raspberry Pi (path: var/www/).

Remark: I did not yet manage to upload the html-code by the w2d-internal FTP program. So I am using WinSCP to do that. It only takes seconds.

WinSCP to upload html code

Tip: Check the Read rights in the www folder !

Router NETGEAR

Register here for a Dyn (former DynDNS) account:
https://account.dyn.com/

Choose a host name (as a radio amateur your call sign is a good choice).

Configure your router to send packets to Dyn on a regular basis:
Example: NETGEAR WNDR3700v2
Each router is different to configure !