Setting up Raspberry Pi as a Webserver using Apache

In this tutorial we will be installing Apache2 webserver on Raspberry Pi 2 board running Debian based Wheezy OS. There are many reasons of installing and running Raspberry as a webserver. Many use this as a standalone web hosting space glued to one’s intranet for catering to normal webservices or for informative purposes. I have installed Apache2 and running Raspberry as a webserver mainly to run CGI (Common Gateway Interface) scripts so that we can gain access to GPIO pins remotely. I will be writing the tutorial on how to configure and run CGI scripts in my next tutorials and also on how to control the Raspberry GPIO pins over Internet remotely. Now continuing to our current topic on setting up Raspberry Pi as a webserver, we will be using very popular Apache webserver.

Apache is one of the most popular webserver currently in used by millions of people around the world. It is developed and maintained by open source community under the flagship Apache Software Foundation.

Steps to Install Apache Webserver on Raspberry Pi 2 Board

Power-up your Raspberry Pi board with internet connectivity active. Note that I have been following Raspberry Pi 2 Board with Debian based OS Wheezy installed for this tutorial. Before following the Apache installation process run the following two commands in your terminal. This is mainly to make the current OS installation updated and all the Apps installed to be upgraded to latest version, this will help for any version conflict issues etc. during installation.

  • sudo apt-get update
  • sudo apt-get upgrade

Running above two commands will take quite some time depending upon the internet speed as this will download and install lots of installed packages.

Next runt the following command to download and install Apache webserver

sudo apt-get install apache2

Raspberry Pi Apache Installation 01

Type in “Y” and press Enter to continue the installation process. Once installed you will get the following screen.

Raspberry Pi Apache Installation 02

Now to check if the currently installed webserver is working or not. Just open up your browser and type in the machines IP address. To check for the current IP address your Raspberry is using type in the ifconfig command in the terminal and this will show your current IP.

Raspberry Pi Apache Installation 03

If everything goes well your web browser will show up the default webpage with message as “It works!” as shown below:

Raspberry Pi Apache Installation 04

This completes your installation process with a check if the webserver is installed and working.

Changing The Default Directory of Apache2 webserver in Raspberry Wheezy

No you need to know the Raspberry directory wherein the default webpage is hosted so that you can work in to change the same and use it upon your needs to host different webpage. The default webpage index.html will lie in the /var/WWW/ directory of your Wheezy Installation. Whatever changes you make in this directory will be reflected in the hosted webpage.

 Raspberry Pi Apache Installation 05

You can change the default directory used by webserver from /var/WWW/ to whatever you like by changing the entry in the default configuration file which you can find in the /etc/apache2/sites-available/ directory. Just change the entry of /var/WWW/ to whatever directory you like and now this will become your default location for hosting WebPages.

Raspberry Pi Apache Installation 06

 

Raspberry Pi Apache Installation 07

Starting , Stopping or Restarting Apache2 webserver in Raspberry Wheezy

Anytime you can start, stop or restart the Apache webserver by running the following commands in the terminal.

  • sudo service apache2 restart
  • sudo service apache2 start
  • sudo service apache2 stop

This completes our tutorial on installing and running Apache webserver on Raspberry Pi. Now next you can install PHP & MySQL to completely utilize the features of webhosting. PHP is one of the most popular server side scripting language and MySQL is the database which you require while hosting. I have not explained this as we will be using webserver installation to run the CGI script to gain control of the Raspberry GPIO. My next tutorial to follow will explain this GPIO control over internet in detail.

Add a Comment

Your email address will not be published. Required fields are marked *