How to Set Up a Raspberry Pi Web Server [Guide]

Raspberry Pi is not only a small board computer but a tinker card that can do almost anything and everything. Do you want toset up Pi-hole on Raspberry Pito block ads and trackers from your entire home network? Yes, it does that. Do you want to set up a Raspberry Pi web server for web development and local file transfer? Well, it does that too. In fact, using a Raspberry Pi is a great and affordable way to build a personal web server. So if you are interested, follow this simple guide and turn your Raspberry Pi into a web server in no time.

Set Up a Raspberry Pi Web Server

Set Up a Raspberry Pi Web Server

To set up a Raspberry Pi web server, you first need to install a web server. There are two popular web servers: Apache and Nginx. But in this tutorial, we will use Apache because it’s reliable and easier to use. Apart from that, we will also install PHP so that you can host dynamic webpages on your Raspberry Pi. Now having said all of that, let’s jump to the steps.

Install Apache Web Server on Raspberry Pi

  1. First off, make sure you have flashedRaspberry Pi OS with desktopUI on the SD card. If you are new to all this, follow our guide onhow to set up Raspberry Pi remotely. That said, if you have an external monitor, things will be much smoother.

  2. Once Raspbian OS boots up, open the Terminal and run the below command toupdate Raspbian OSto the latest version.

  3. Next, we need toinstall the Apache web serveron Raspberry Pi. Run the below command in the Terminal.

  4. Once installed, the Apache web server will be live. Just open the browser on Raspberry Pi and enterlocalhostor127.0.0.1, and hit enter to access the web server. It should load Apache’s HTML page.

  5. You can also directly enter the IP address of Raspberry Pi in a browser to access the web server. Runhostname -Iin the Terminal, and you will find the IP address of your RPi.

  6. Enter the IP address in the browser, and there you have it. In fact, you canuse the IP address on any deviceon your local Wi-Fi network, and you will be able to access the web server. For example, I am able to access Raspberry Pi’s web server from my Chromebook with ease.

  7. For your information, all web server files are saved in/var/www/html/location. So you can change the directory to this location and view all the files. Here are the commands to run.

  8. As you can see in the screenshot above, theindex.htmlfile is owned byroot. So before modifying anything, you need to change the owner topi(you). Run the below command tochange the ownership.

As you can see in the screenshot below,piis now the owner of the web server. You can also use the same format to change the ownership of folders such ashtmlandwww.

  1. Now, go ahead and open the file through the Terminal or File Manager. I am using the File Manager for easier access. Navigate to“var -> www -> HTML”, right-click on the “index.html” file, and choose “Text Editor”.

  2. Now, if I make any changes to the title and save it, then they will reflect on the web server right away. You will see the updated title when youopen the web server in a browserwindow. This step confirms that your Raspberry Pi web server is working well.

Install PHP on Raspberry Pi

If you want to test your web pages on Raspberry Pi, installing just the webserver won’t cut it. You also need to install PHP to have asolution like XAMPPon Raspberry Pi. It will allow you to test dynamic web pages on your Raspberry Pi. Here is how to go about it.

  1. Run the below command to install thelatest version of PHPon your Raspberry Pi.

  2. Next, move to the samevar/www/html/directory andcreate a PHPfile using a text editor.

  3. Next, open the file with a text editor andenter the PHP codeyou want to add. For example, I have added the PHP code that outputs a simple statement.

Testing FileZilla on Raspberry Pi

Once we have set up Apache web server and PHP on Raspberry Pi, it’s finally time to test if we can transfer our existing web assets to the RPi web server with thepopular FTP client FileZilla. You can also use otherFTP clients like WinSCPif you wish. Here are the steps to follow.

  1. InstallFileZilla(Free) on another PC connected to the same Wi-Fi network.

  2. Next, on Raspberry Pi, navigate to the “Start Menu -> Preferences -> Raspberry Pi Configuration” section. Here, move to “Interfaces” andenable “SSH”.

  3. On FileZilla, open “File menu -> Site Manager” and add a “New Site”. Here,choose “SFTP”as the protocol and enter the IP address of Raspberry Pi’s web server in the “Host” field. Keep the “Port” field blank. After that, enter the default credentials:pias the username andraspberryas the password. Now, click on “Connect”.

Note: If you changed the password of Raspberry Pi during the setup, then enter the new password.

  1. You will connect to your Raspberry Pi’s web server. Now, you cantransfer all your HTML, CSS, and PHP assetsdirectly to Raspberry Pi and get your web development underway without any hassle.

Turn Your Raspberry Pi into a Web Server in a Few Easy Steps

Turn Your Raspberry Pi into a Web Server in a Few Easy Steps

So that is how you can set up a web server on Raspberry Pi. All the tools required to get a web server running are available on the Debian-based Raspbian OS, so there is no problem at all. Even if you are a beginner, you can follow the step-by-step instructions above and turn the RPi board into a web server in no time. Anyway, that is all from us. If you have any questions, let us know in the comment section below.

Arjun Sha

Passionate about Windows, ChromeOS, Android, security and privacy issues. Have a penchant to solve everyday computing problems.

Add new comment

Name

Email ID

Δ