Need to launch a website but can’t afford hosting costs?
You can use this link to get a special discount on InMotion Hosting.
Or you can try turning your Raspberry Pi into a web server that is more than capable of running basic web server software. Best of all, its setup is simple.
Why Host a Website on a Raspberry Pi?
There are several good reasons to set up a Raspberry Pi as a web server.
- Hosting is expensive
- Your desktop computer is too expensive to work all day
- Raspberry Pi has a very low energy footprint
- Pi can be configured as a portable device
- Potential to beat censorship
Whatever your motivation for choosing to host your website on a Raspberry Pi, it can be set up in minutes. What’s more, you can use any version of Pi, even Pi Zero. If the device can be connected to the Internet, you can host a website on it.
Raspberry Pi Web Server Hardware Setup
Start with a reliable power supply for your Raspberry Pi. A high quality SD card should be running the latest version of your preferred Raspberry Pi distribution.
The steps and screenshots in this guide are for setting up your Raspberry Pi web server with Raspbian Stretch.
As with most servers, you will need to access the Raspberry Pi web server using SSH. On Linux and macOS, you can do this through the terminal. On Windows, use PowerShell to connect via SSH. or install a third party tool.
Setting up a wireless network and SSH
While you can use your Raspberry Pi as a web server with just a keyboard and monitor, remote access is easier.
The best way to do this is to enable SSH on the Pi and set up the wireless network beforehand. If you’re using an existing Raspberry Pi installation, you’ve probably already done both. Are you starting over? You can set up SSH and wireless while your SD card is still in your PC.
Make sure your SD card is visible in your computer’s file manager and a directory is selected /boot/ . (On Windows, this is the only part of the SD card that is readable.)
Then in the /boot/ directory window right click in an empty space and select » New»>»Text Document» . Name the document ssh trying to remove the .TXT file extension. When the Pi boots up, it will detect the ssh file and enable this feature.
In order to connect via SSH, you need to first enable your wireless network. To do this, create another file, this time calling it wpa_supplicant.conf . Remove the TXT extension again. Open the file, copy and paste the following:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev network={ ssid="YOUR_NETWORK_NAME" psk="YOUR_PASSKEY" key_mgmt=WPA-PSK }
After pasting, edit the values to display the network name (SSID) and password (PSK). Save the file, then safely remove the SD card. After replacing in Raspberry Pi, boot up. You should be able to SSH into your Raspberry Pi using the Pi’s IP address. To find out, check your router’s admin screen (see the device’s documentation) or briefly plug in a keyboard and display.
With SSH installed, you can remotely connect to the Raspberry Pi web server at any time.
Setting Up Your Raspberry Pi as a Web Server
Before you can upload HTML pages to your Raspberry Pi, you need to set up the server and its software. To do this, install Apache and PHP. This will allow you to serve pages written in HTML and PHP.
Start by updating Raspbian:
sudo apt update sudo apt upgrade
Then install Apache and related libraries by typing:
sudo apt install apache2 -y
Then check that Apache is running:
sudo service apache2 status
If the server displays «active (running)» in green text, everything is fine.
If the server is down, start it with:
sudo service apache2 start
At this point, you can access your Raspberry Pi’s web server from a browser.
If the browser is installed on your Raspberry Pi, go to this URL in the address bar: