How to Install Raspberry Pi Web Server [Guide]

The Raspberry Pi is not just a small board computer, it’s a handyman board that can do just about anything. Want to set up Pi-hole on Raspberry Pi to block ads and trackers on your entire home network? Yes, it does. 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 cost-effective way to build a personal web server. If you are interested, follow this simple guide and turn your Raspberry Pi into a web server in no time.

Install Raspberry Pi Web Server (2021)

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

  • Install Apache Web Server on Raspberry Pi

1. First, make sure you flash it. Raspberry Pi OS with Desktop User interface on SD card. If you’re new to all this, follow our guide on how to remotely set up the Raspberry Pi. However, if you have an external monitor, things will be much smoother.

2. Once Raspbian OS boots up, open Terminal and run the following command. Update Raspbian OS to the latest version.

sudo apt-get update && sudo apt-get upgrade -y

3. Next, we need Install Apache web server on Raspberry Pi. Run the following command in terminal.

sudo apt install apache2 -y

Install Raspberry Pi Web Server (2021)

4. Once installed Apache web server will be live. Just open browser on Raspberry Pi and enter localhost or 127.0.0.1and press enter to access the web server. It should load Apache’s HTML page.

Install Raspberry Pi Web Server (2021)

5. You can also directly enter the Raspberry Pi’s IP address in a browser to access the web server. To run hostname -I In the terminal and you will find the IP address of your RPi.

In relation :  How to Make Memories Slideshows in Photos in iOS 10

Install Raspberry Pi Web Server (2021)

6. Enter the IP address in the browser, there it is. Actually, you can Use IP address on any device on your local Wi-Fi network and you will be able to access the web server. For example, I can easily access the Raspberry Pi’s web server from my Chromebook.

Install Raspberry Pi Web Server (2021)

7. FYI, all web server files /var/www/html/ Location. So you can change directory to this location and view all files. Here are the commands to run.

cd /var/www/html/
ls -al

Install Raspberry Pi Web Server (2021)

8. As you can see in the screenshot above, index.html owner of the file root. So, before you change anything, you need to change the owner to: pi (joyful). run the following command for change ownership.

sudo chown pi: index.html
ls -al

As you can see in the screenshot below, pi now owns the web server. You can also use the same format to change the ownership of folders like below. html and www.

change ownership

9. Now go ahead and open the file via Terminal or File Manager. I use File Manager for easier access. Set route to “var -> www -> HTML”Click, right-click the “index.html” file and select “Text Editor”.

raspberry

10. Now, if I make any changes to the header and save it, it will immediately reflect on the web server. You will see the updated title. open the web server in a browser window. This step verifies that your Raspberry Pi web server is working fine.

Install Raspberry Pi Web Server (2021)

  • Install PHP on Raspberry Pi

If you want to test your web pages on Raspberry Pi, simply installing the web server won’t cut it. You also need to install PHP to have it. solution like XAMPP on Raspberry Pi. It allows you to test dynamic web pages on your Raspberry Pi. Here’s how to do it.

1. Run the following command to install. Latest version of PHP on your Raspberry Pi.

sudo apt install php libapache2-mod-php -y

Install PHP on raspberry pi

2. Then, the same var/www/html/ directory and Generate PHP file using a text editor.

Install PHP on raspberry pi

3. Next, open the file with a text editor and Enter PHP code you want to add. For example, I’ve included PHP code that outputs a simple expression.

Install PHP on raspberry pi

  • Testing FileZilla on Raspberry Pi

After installing Apache web server and PHP on the Raspberry Pi, it’s finally time to test if we can transfer our existing web assets to the RPi web server. popular FTP client FileZilla. You can also use other FTP clients such as WinSCP if you wish. Here are the steps to follow.

In relation :  How to Use Instagram for Mac Without Restrictions

1. Install FileZilla (free) on another computer connected to the same Wi-Fi network.

2. Next, go to “Start Menu -> Preferences -> Raspberry Pi Configuration” on Raspberry Pi. Here go to “Interfaces” and Enable “SSH”.

Testing FileZilla on a raspberry pi

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

note: If you changed the password of Raspberry Pi during installation, enter the new password.

Testing FileZilla on a raspberry pi

4. You will connect to your Raspberry Pi’s web server. Now you can import all your HTML, CSS and PHP assets directly to Raspberry Pi and keep your web development running smoothly.

Testing FileZilla on a raspberry pi

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

So you can set up a web server on Raspberry Pi. All the tools needed to run a web server are available on the Debian-based Raspbian OS, so there are no issues. Even if you are a beginner, you can follow the step-by-step instructions above and turn the RPi card into a web server in no time. Anyway, that’s it for us. If you have any questions, let us know in the comment section below.