How to Make a Raspberry Pi Apache Server: Apache Raspberry Pi Server Installation

The Raspberry Pi is a versatile single-board computer. Because of its small footprint and low power consumption, the Pi makes an ideal web server. You can run Nginx, WordPress, or Drupal on the Raspberry Pi. Similarly, you may create a Raspberry Pi Apache web server as well. Check out this Apache Raspberry Pi server installation!

What is Apache? 

Apache is an incredibly prominent web server. Developed by the Apache Software Foundation, it's an open-source server which serves roughly 37% of the top million websites, and 43% of all websites. It's a cross-platform HTTP server which can send HTML files via HTTP. With additional resources such as PHP, you can use Apache to serve dynamic pages with languages like PHP. 

What You Need to Make an Apache Raspberry Pi Web Server

Making an Apache web server with Raspberry Pi is fairly simple as well as economical. You'll only need the Raspberry Pi, a microSD card, power supply, and Linux-based distribution. A case is optional, but recommended.

What you'll need for a Raspberry Pi Apache Web Server:

Total cost: $35+. You can pick up a kit with Raspberry Pi board, case, power supply, and microSD card for around $50 or a standalone Raspberry Pi board for $35. I suggest opting for a Raspberry Pi 3 or Raspberry Pi 3 B+.

How to Install Apache on Raspberry Pi

First, begin by installing Apache. You'll want to run a system update first:



sudo apt-get update

Now, install Apache:



sudo apt-get install apache2 -y

With Apache installed on the Raspberry Pi, test the web server. Under the web folder, Apache places a test HTML file. You can view your newly loaded Apache web server at http://localhost/ or the Pi's IP address: http://[Raspberry Pi IP address]/

You may find your Raspberry Pi's IP address using:



hostname -I

While Apache by default creates its own default web page, you may also change this. The default HTML file is found at: /var/www/html/index.html

The default file is located in /var/www/html/ and named index.html. It's owned by root. If you'd like to edit index.html, switch the owner to pi or your custom user:



sudo chown pi: index.html

Simply edit this file, then save it and refresh to see your changes. You can add your custom HTML to this file which will serve as a website from your Apache server.

With Apache running on the Raspberry Pi, you may wish to install PHP since Apache can work with PHP files as well. You'll need to install PHP using:



sudo apt-get install php libapache2-mod-php -y

Remove index.html:



sudo rm index.html

Generate index.php:



sudo nano index.php

Alternately, use the graphical editor Leafpad:



sudo leafpad index.php

In index.php, add some PHP content that your Raspberry Pi Apache web server can serve up:



<?php echo "hello world"; ?>

Save this file and refresh your web browser. You'll see "hello world" or whatever content you added. Alternatively, you can add in dynamic content:



<?php echo date('Y-m-d H:i:s'); ?>

How to Make a Raspberry Pi Apache Server: Final Thoughts

Apache is an incredible open-source HTTP server. When used with languages such as PHP, it becomes even more robust and capable. Try taking your Raspberry Pi web server to the next level with a WordPress installation which requires Apache, MySQL, and PHP. Alternatively, you may spin up a Raspberry Pi media server with the likes of Plex and Emby.

What servers are you running on your Raspberry Pi? 

Leave your feedback...