11) Install Apache2 onto a Raspberry Pi

<-- Previous    Next –>

Installing the Web Server Apache onto a Raspberry Pi should be straight forward. This assumes that you have set up a hostname for the Raspberry Pi and that it is connected to your local network.

Log onto your Raspberry Pi using a Terminal and type:

sudo apt update

This will update your installation.

Install Apache 2

To install Apache:

sudo apt-get install apache2 -y

Test the web server

By default, Apache puts a test HTML file in the web folder that you will be able to view from your Pi or another computer on your network.

Open the Apache default web page on your Raspberry Pi using a web browser on the Raspberry Pi and entering http://localhost.

You should see the Apache2 Debian default Page.

Try using the hostname of the Raspberry Pi in place of localhost. For example, my hostname is webserver so suing http://webserver should still see the same default page.

Now if you go to one of your computers on your network and enter in the url address of the hostname in a web browser such as http://webserver, that should also display the default page. Or alternatively, use the IP address of the Raspberyy Pi for example

To find the IP address of your Raspberry Pi, enter the following in a terminal:

hostname -I

Changing the default web page

The default web page is just a HTML file on the file system. It is located at /var/www/html/index.html.

To change this file:

sudo nano /var/www/html/index.html

will allow you to edit the file.

Note that to restart Apache at any time enter:

sudo service apache2 restart

This will set up a web server at /var/www/html

Enable .htaccess on the folder

An extra step is to enable .htaccess files.  These are file that you place on your web site and give you the ability to make configuration changes on a directory by directory bases.

To enable htaccess files you must modify the config of Apache:

sudo nano /etc/apache2/apache2.conf

You’ll see a line like the following near <Directory /var/www/html/> for your web folder:

“AllowOverride None” – change this to “AllowOverride ALL”

Then hold the Ctrl+X key, then press Y and press Return.

Now restart Apache with:

sudo service apache2 restart

<-- Previous    Next –>