Apache2 Web Server On Raspberry Pi

HOLD THE PRESS! Don't buy until Feb 11th 2015 - Upgraded to 900Mhz Quad Core and 1GB RAM

From the last Post, I have the base Raspbian install with some added apps and services like SSH, Vim, Samba, Rdesktop, Tightvncserver now, so will look at setting up Apache2 as an insecure web server as a first step.

I expect this to follow a similar procedure as for Mint, with the more secure default settings such as requiring knowledge to add conf file lines rather than having them in as defaults that just require amendment, but let's see...

I'm SSH'd in to the Pi already, so first I need to install Apache2 as root:

root@raspberrypi:/home/stevee# apt-get install apache2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common libapr1
libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap ssl-cert
Suggested packages:
apache2-doc apache2-suexec apache2-suexec-custom openssl-blacklist
The following NEW packages will be installed:
apache2 apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common
libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap ssl-cert
0 upgraded, 10 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,355 kB of archives.
After this operation, 4,929 kB of additional disk space will be used.
Do you want to continue [Y/n]?

Hmm...that's not good...

Err http://mirrordirector.raspbian.org/raspbian/ wheezy/main apache2.2-bin armhf 2.2.22-13+deb7u3
404 Not Found
Err http://mirrordirector.raspbian.org/raspbian/ wheezy/main apache2-utils armhf 2.2.22-13+deb7u3
404 Not Found
Err http://mirrordirector.raspbian.org/raspbian/ wheezy/main apache2.2-common armhf 2.2.22-13+deb7u3
404 Not Found
Err http://mirrordirector.raspbian.org/raspbian/ wheezy/main apache2-mpm-worker armhf 2.2.22-13+deb7u3
404 Not Found
Err http://mirrordirector.raspbian.org/raspbian/ wheezy/main apache2 armhf 2.2.22-13+deb7u3
404 Not Found
Failed to fetch http://mirrordirector.raspbian.org/raspbian/pool/main/a/apache2/apache2.2-bin_2.2.22-13+deb7u3_armhf.deb 404 Not Found
Failed to fetch http://mirrordirector.raspbian.org/raspbian/pool/main/a/apache2/apache2-utils_2.2.22-13+deb7u3_armhf.deb 404 Not Found
Failed to fetch http://mirrordirector.raspbian.org/raspbian/pool/main/a/apache2/apache2.2-common_2.2.22-13+deb7u3_armhf.deb 404 Not Found
Failed to fetch http://mirrordirector.raspbian.org/raspbian/pool/main/a/apache2/apache2-mpm-worker_2.2.22-13+deb7u3_armhf.deb 404 Not Found
Failed to fetch http://mirrordirector.raspbian.org/raspbian/pool/main/a/apache2/apache2_2.2.22-13+deb7u3_armhf.deb 404 Not Found
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

After an update, all looks OK.

The following extra packages will be installed:
apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common libapr1
libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap ssl-cert
Suggested packages:
apache2-doc apache2-suexec apache2-suexec-custom openssl-blacklist
The following NEW packages will be installed:
apache2 apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common
libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap ssl-cert
0 upgraded, 10 newly installed, 0 to remove and 30 not upgraded.
Need to get 1,139 kB/1,360 kB of archives.
After this operation, 4,936 kB of additional disk space will be used.
Do you want to continue [Y/n]?

......Setting up apache2-mpm-worker (2.2.22-13+deb7u4) ...
[....] Starting web server: apache2apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
. ok
Setting up apache2 (2.2.22-13+deb7u4) ...
Setting up ssl-cert (1.0.32) ...

Looking in

vi /etc/apache2/sites-available/default

you see the section:

<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Change the name and location of your default site page e.g. index.html, and default folder as required, or just place your website docs in the default = /var/www but be aware that user access is folder and file permissions dependent.

For testing, I will place a copy of my www.stevepedwards.com index page here for now. First, I'll have to download a copy of it from there using wget.

I cd into /var/www first then DL the file:

root@raspberrypi:/home/stevee# cd /var/www

root@raspberrypi:/var/www# wget www.stevepedwards.com/index.html
--2015-01-26 16:58:15-- http://www.stevepedwards.com/index.html
Resolving www.stevepedwards.com (www.stevepedwards.com)... 173.254.28.64
Connecting to www.stevepedwards.com (www.stevepedwards.com)|173.254.28.64|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7676 (7.5K) [text/html]
Saving to: `index.html.1'

100%[===================================================================================================================>] 7,676 --.-K/s in 0.003s

2015-01-26 16:58:16 (2.20 MB/s) - `index.html.1' saved [7676/7676]

[===================================================================================================================>] 7,676 --.-K/s in 0.008s

As there is the default index file already, mine is renamed, so I check the permissions before I delete/move the original to replace it with my version:

root@raspberrypi:/var/www# ls -als
total 20
4 drwxr-xr-x 2 root root 4096 Jan 26 16:58 .
4 drwxr-xr-x 12 root root 4096 Jan 26 16:16 ..
4 -rw-r--r-- 1 root root 177 Jan 26 16:16 index.html
8 -rw-r--r-- 1 root root 7676 Nov 20 23:59 index.html.1

The permission are the same, as this folder belongs to root at this stage.

Also, its worth noting that the http service is active, as shown by nmap:

root@raspberrypi:/home/stevee# nmap 127.0.0.1

Starting Nmap 6.00 ( http://nmap.org ) at 2015-01-26 16:33 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00017s latency).
Not shown: 996 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
139/tcp open netbios-ssn
445/tcp open microsoft-ds

So what does an access attempt show in a browser when accessing the IP directly?

The Pi address is:

root@raspberrypi:/home/stevee# ifconfig
eth0 Link encap:Ethernet HWaddr b8:27:eb:73:a8:a5
inet addr:192.168.1.99 Bcast:192.168.1.255 Mask:255.255.255.0

Apache2Def

 

The web server works, now its just about displaying the desired page, by renaming the original and mine:

root@raspberrypi:/var/www# mv -v index.html index.html.bak
`index.html' -> `index.html.bak'

root@raspberrypi:/var/www# mv -v index.html.1 index.html
`index.html.1' -> `index.html'

Now, my page should be viewable in the browser by refreshing the page with F5:

Apache2Def2.jpg

That's it for now. Obviously, all the other files such as pics, CSS files etc. would have to be present in /var/www or elsewhere, for your default page to work correctly also.

I'll look at securing the web server access in the next Post, but you can get an overview or try it on my old pages here:

http://stevepedwards.com/Apache2_Info.html

Comments are closed.

Post Navigation