Raspberry Pi as an Apache server, a simple how-to

Fatah Nur Alam Majid
2 min readMar 14, 2017

Okay in this post I would like to tell you some setup to make a little device called Raspberry Pi running and serving you as a web server. In this post, web server I mean is an Apache web server. Though this setup I’d like to write already have an official documentation here. You can choose either to read this post or read the official one, but I’ll tell you that this setup is really the same way as the official documentation explains.

First things first, here is what we’ll gonna need for the setup:

  1. Raspberry Pi with Raspbian Jessie Lite, up and running.
  2. Internet connection (make sure your Pi is connected to the internet).
  3. Terminal (either SSH to the Pi or actual terminal on the Pi itself with monitor of course).

Okay let’s get started..

First, you may want to make sure that your Pi is up and you’re connected to it (if you’re using SSH). Also check for the Pi connectivity, make sure you can access the Debian repo from your Pi.

Second, you may want to install Apache on your Pi. To know how to do that you can execute this command:

pi@raspberrypi:~$ sudo apt-get install apache2

You can check whether your Apache is installed and running by typing the Pi’s IP from other computer’s​ browser (in the same network). If you see the Apache Debian default page, it means that your Apache is successfully installed on your Pi.

Note: You can also execute command below to check if the Apache service is running on your Pi.

pi@raspberrypi:~$ sudo systemctl status apache2

Third, change the ownership of the HTML directory. This step can be done by executing this command:

pi@raspberrypi:~$ sudo chown -R pi: /var/www/html/

After completed, you can edit the HTML directory and the files inside whenever you want. No need sudo for editing them again..

Fourth, install PHP on your Pi. When I was writing this post, the newest version of PHP is PHP5, thus you can install them by executing this command:

pi@raspberrypi:~$ sudo apt-get install php5

Wait until the installation complete, then you may want to check it whether the PHP is running. You can first make a backup of the default index file (index.html located at /var/www/html/index.html), and then you can make a new PHP index file for testing. Type:

pi@raspberrypi:~$ echo “<?php phpinfo(); ?>” > /var/www/html/index.php

To make a new PHP index file for testing. After that, you can check them by typing the Pi’s IP address from someone else’s computer (in the same network of course). If you get the PHP information page, this means you are successfully install PHP on your Pi.

Finally our Pi is ready to use..

This tutorial is very very simple, and I hope you enjoy it. Thanks..

--

--

Fatah Nur Alam Majid

Tech hobbyist, Learn from scratch, Learning the hard way, Just want to share anything