Apache web server: Build a local HTML server with a Raspberry Pi
By Russell Barnes. Posted
Create your own Intranet web server using Apache and a Raspberry Pi
Advertisement
Christmas is coming – keep Santa on the right track with our Raspberry Pi gift guide!
If you want to get to grips with how the web works, one of the most entertaining ways to learn is to build your own local intranet Apache web server to display simple – or even complex – internal websites.
A Raspberry Pi is an ideal Apache web server for small websites that don’t require the capacity or server-side processing power of a more powerful computer, and it’s an ideal development environment if you’re to use HTML.
It can host a personal blog or to-do list, keep a web-based calendar for the household, hold your family photo albums, or simply host a website you’re developing before you’re ready to share it with the world.
See also: Samba: Set up a Raspberry Pi as a File Sever for your local network
Set up Apache Web Server on a Raspberry Pi

Much of the world wide web is built on LAMP – Linux, Apache, MySQL, PHP – often with a content management system (CMS) on top to make it easy to create complex websites with little knowledge of HTML or PHP.
This tutorial will take you through the basics of getting your server’s environment set up. We don’t go as far as installing a CMS, but by the end of the following steps, your Pi will be ready to immediately display ordinary ‘flat’ HTML webpages. If you add the optional step of installing the MySQL database back end and PHP interpreter, you should be all set to install and configure most CMSs by following the instructions they supply.
STEP-01: Install the OS
Hook up the keyboard and mouse to the Pi and connect it to an HDMI monitor. Copy NOOBS to a FAT32-formatted micro SD card; insert it and power up the Pi. Opt to install Raspbian with the PIXEL window manager. This will take a few minutes.
See also: Beginner's Guide to NOOBs
STEP-02: Check the network address
Once the Pi has rebooted, open a Terminal window and run:
ifconfig
Make a note of the ‘inet addr’ value for eth0. This will be the IP address of your web server. It’s a good idea to assign the Pi a static DHCP reservation on your router so the Pi will keep that address permanently.
STEP-03: Update your Pi and install Apache
Run the following commands in the Terminal to make sure Raspbian is up to date. Adding -y to the end of apt-get commands instructs the program to automatically answer yes to any questions rather than waiting for you to type Y or N.
sudo apt-get update sudo apt-get upgrade -y
Once this is complete, it’s time to install your new Apache web server:
sudo apt-get install apache2 -y
Apache is the main piece of software you need to serve webpages to client PCs.
STEP-04: Add PHP and MySQL (optional)
Many websites use content management systems, such as WordPress. These require PHP and MySQL, so if you want to experiment with CMS-driven sites further down the line, this is an ideal time to add the software you’ll need to render them. You can install both at once using the following command:
sudo apt-get install php5 mysql-server -y
Chose a strong password for the MySQL ‘root’ user and note it down somewhere safe.
STEP-05: Test Apache
Open your web browser of choice, either on the Pi or on another PC on your local network, and enter the IP address from step 2 into the address bar. You should see the Apache 2 Debian default page, with a red banner and the words ‘It Works!’ across it.
STEP-06: Start building your site

Your website’s files are located in the /var/www/html
directory. Run the following to make this folder accessible to the default user, pi.
sudo chown -R pi /var/www/html
Delete the index.html file found there and upload your new intranet site to that folder. Your new site should now be accessible from your local network on the address you used in step 5.
Your Pi is an ideal environment for web development, so you can simply drop the HTML files you’re working on into your web server directory. If you want to experiment with more advanced options, you can enable FTP and SSH for remote access to your web server from other computers on your local network. You can also install a CMS such as WordPress, which you’ll be able to access from a browser on your local network to create content-rich websites.
While this is strictly a local web server project, the same software and processes go into an internet-facing server, although that will require firewall configuration and extra security measures that are beyond the scope of this tutorial.
Russell runs Raspberry Pi Press, which includes The MagPi, Hello World, HackSpace magazine, and book projects. He’s a massive sci-fi bore.
Subscribe to Raspberry Pi Official Magazine
Save up to 37% off the cover price and get a FREE Raspberry Pi Pico 2 W with a subscription to Raspberry Pi Official Magazine.
More articles
Christmas Gift Guide in Raspberry Pi Official Magazine 160
There’s a ton of great stuff in issue 160, including the incredible motion scanner, inspired by the film Aliens. It’s beautiful, it uses Raspberry Pi technology and makes a satisfying ping sound, and the best thing about it is that it actually works, thanks to a DreamHAT+ radar board. Yes, you too can join the […]
Read more →
Win a Raspberry Pi 500+ and Raspberry Pi Monitor!
Fancy getting the most powerful Raspberry Pi desktop setup? Raspberry Pi 500+ and Raspberry Pi monitor pair perfectly together for a portable – and fixed – desktop computer, powered by Raspberry Pi. We have a set to give away, and you can enter below. A Raspberry Pi 500+ & Raspberry Pi Monitor
Read more →
All right all right!! Artificial Intelligence, Hollywood style
When we get AI right, odds on it’ll be thanks to small firms, motivated individuals, and Raspberry Pi
Read more →
Sign up to the newsletter
Get every issue delivered directly to your inbox and keep up to date with the latest news, offers, events, and more.