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.

Raspberry Pi 3 B+

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.

Check if your Apache server is running

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:

 http://localhost 

However, if you are using SSH, use your Raspberry Pi’s IP address from your PC’s browser (for example, http://123.456.789.0 ). You should see confirmation that Apache is installed.

Apache test screen

Your Raspberry Pi is now configured as the main web server. All you have to do now is add pages!

FTP Setup on Raspberry Pi

Although you can check in your browser that your Pi is running as a web server, the page provided will be very simple. This is a typical index.php placeholder file that you will have to replace with your own PHP or HTML document.

Start by creating a www directory and installing the FTP software:

 sudo chown -R pi /var/www sudo apt install vsftpd 

With the FTP application vsftpd (Very Secure FTP Daemon) installed, you will need to make some configuration changes. First, open the config file in nano…

 sudo nano /etc/vsftpd.conf 

… And make the following changes to permissions and security:

First change anonymous_enable = YES to anonymous_enable = NO

Then uncomment the following lines (by removing the # symbol)

 #local_enable=YES #write_enable=YES 

This includes the settings that strings apply to. Finally add this line to the end of the file:

 force_dot_files=YES 

Configure vsftpd to enable FTP access to your Pi web server

This will display server files that start with «.», such as the important .htaccess file.

Click ctrl+X, to save and exit by confirming with Y and Enter .

Finally, restart FTP with:

 sudo service vsftpd restart 

Using the standard FTP desktop, you will be able to connect to your Raspberry Pi. Upload files to /var/www/html .

HTML is not enough? Raspberry Pi also supports lamp!

Raspberry Pi is not only capable of serving basic HTML pages. LAMP server configuration can be set if you want MySQL with PHP support. Just follow the instructions above to install and configure Apache, then add the MySQL installation and then PHP.

The following packages install MySQL and the required PHP component:

 sudo apt install mysql-server php-mysql -y 

Once this is installed, you need to restart Apache:

 sudo service apache2 restart 

Then install PHP itself with:

 sudo apt install php -y 

Restart Apache again using the above command. Your LAMP server is installed and ready to set up web applications and websites based on a PHP database.

As with any web server project, you must determine if the Pi will fit your needs. Although WordPress can be configured to run on a Raspberry Pi, adding a lot of plugins and daily updates will make it extremely slow.

The website you plan to run on Raspberry Pi should be light in terms of resources and software requirements. If necessary, you can use a database based solution, you should limit the number of pages that can be viewed.

Do you want to go further? Check out our guide to hosting a WordPress site on Raspberry Pi Of course, there are good reasons to use managed WordPress hosting for your website.

Security and technical considerations

When using a Raspberry Pi as a web server for anything that resembles a popular website, you’re unlikely to get anything approaching production speed.

However, there are ways to improve performance, such as configuring the server software on a USB hard drive rather than an SD card to reduce degradation from regular read/write processes. It is also possible to use your device’s RAM to temporarily store read/write files. This is something you may want to change when deciding how you are going to use your very small web server.

While it’s fine for setting up a database-driven PHP test site, the online duties of the Raspberry Pi are probably best suited for a small collection of static pages.

Please note that if you plan to expose your Raspberry Pi as a web server connected to the Internet, you will need to set up a router with a static IP address.

Finally, take the time to change your Raspberry Pi’s default password. This can be done on the command line via SSH using:

 passwd 

You will be prompted to enter and confirm a new password. As a result, anyone familiar with Raspbian will not be able to access the server side of your web page.

Host your own Raspberry Pi website!

Test site running on Raspberry Pi

The potential for using the Raspberry Pi as a web server is significant. In fact, you won’t be able to host a website as big as . However, with a battery and a mobile internet dongle, you can host a compact website from anywhere in the world.

Remember, all you have to do is:

After setting up a static IP address or dynamic DNS service, your website is ready. And if you don’t want it to be accessed from the internet, just host your home intranet. ! If you decide to look for a third party service, check out the list of the best web hosting services.

Похожие записи