How to set up a Raspberry Pi web server [Guide]

Rate this post

The Raspberry Pi isn’t just a small board computer, it’s a tinkering card that can do almost anything. Would you like to set up a Pi-hole on your Raspberry Pi to block ads and trackers from your entire home network? Yes I will. Would you like to set up a Raspberry Pi web server for web development and local file transfer? Well, that’s also the case. In fact, using the Raspberry Pi is a great and affordable way to build a personal web server. Therefore, if you are interested, follow this brief guide to turn your Raspberry Pi into a web server right away.

Raspberry Pi Web Server Setup (2021)

To set up the Raspberry Pi web server, you must first install the web server. There are two popular web servers, Apache and Nginx. However, this tutorial uses Apache, which is reliable and easy to use. Separately, install PHP to allow the Raspberry Pi to host dynamic web pages. Now let’s move on to the procedure.

  • Install Apache Web Server on Raspberry Pi

1. First, make sure you have flushed Raspberry Pi OS with desktop SD card UI. If you’re new to all of this, follow the guide on how to set up your Raspberry Pi remotely. That said, things get much smoother with an external monitor.

2. When the Raspbian OS boots, open a terminal and execute the following command Update Raspbian OS To the latest version.

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

Raspberry Pi Web Server Setup (2021)

3. Next, you need to do the following: Install Apache web server For raspberry pie. Execute the following command in the terminal.

sudo apt install apache2 -y

Raspberry Pi Web Server Setup (2021)

4. Once installed, the Apache web server will run. Just open a browser on your Raspberry Pi and type localhost Or 127.0.0.1, Press Enter to access the web server. You need to load the Apache HTML page.

Raspberry Pi Web Server Setup (2021)

5. You can also access the web server by entering the Raspberry Pi’s IP address directly in your browser.Run hostname -I It is in the terminal and displays the IP address of the RPi.

Raspberry Pi Web Server Setup (2021)

6. Enter the IP address in your browser and the IP address will be displayed.In fact, you can Use an IP address on any device You will be able to access the web server on your local Wi-Fi network. For example, you can easily access the Raspberry Pi web server from your Chromebook.

Raspberry Pi Web Server Setup (2021)

7. For reference, all web server files are saved in /var/www/html/ Location. Therefore, you can change the directory to this location to see all the files. The command to execute is:

cd /var/www/html/
ls -al

Raspberry Pi Web Server Setup (2021)

8. As you can see in the screenshot above index.html The file is owned by root.. Therefore, before you change anything, you need to change the owner as follows: pi (You are).Execute the following command Change ownership..

sudo chown pi: index.html
ls -al

As you can see in the screenshot below pi I am currently the owner of the web server. You can also use the same format to change ownership of folders such as: html And www..

Change ownership

9. Then open the file from your terminal or file manager. I’m using a file manager for easy access.invite “Var-> www-> HTML”, Right-click on the “index.html” file and select “Text Editor”.

Raspberry

10. Now, when you make changes to the title and save it, it will be immediately reflected on the web server.The updated title is displayed Open a web server in your browser window. This step verifies that the Raspberry Pi web server is working properly.

Raspberry Pi Web Server Setup (2021)

  • Install PHP on Raspberry Pi

When testing a web page on a Raspberry Pi, installing just the web server does not cut it.Also install PHP Solutions like XAMPP For raspberry pie. This allows you to test dynamic web pages on your Raspberry Pi. Here’s how.

1. Execute the following command Latest version of PHP For your Raspberry Pi.

sudo apt install php libapache2-mod-php -y

Install PHP on Raspberry Pi

2. Then move to the same location var/www/html/ Directory and Create PHP File using a text editor.

Install PHP on Raspberry Pi

3. Next, open the file with a text editor and Please enter the PHP code I want to add it. For example, I added PHP code that outputs a simple statement.

Install PHP on Raspberry Pi

  • Testing FileZilla on Raspberry Pi

After setting up the Apache web server and PHP on the Raspberry Pi, the final step is to test if you can transfer your 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. To follow these steps:

1. Installation FileZilla (Free) Another PC connected to the same Wi-Fi network.

2. Next, with Raspberry Pi[スタートメニュー]->[設定]->[RaspberryPiの構成]Go to the section. Now go to “Interface” and Enable “SSH”..

Test FileZilla on Raspberry Pi

3. In FileZilla, open “File Menu-> Site Manager” and add “New Site”. Here, Select “SFTP” As a protocol, enter the IP address of the Raspberry Pi web server in the Host field. Leave the Port field blank. Then enter the default credentials. pi As a user name raspberry As a password. Then click Connect.

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

Test FileZilla on Raspberry Pi

4. Connect to the Raspberry Pi web server.Now you can Transfer all HTML, CSS, and PHP assets Get direct access to your Raspberry Pi and get started with web development without hassle.

Test FileZilla on Raspberry Pi

Turn your Raspberry Pi into a web server with a few simple steps

Here’s how to set up a web server on your Raspberry Pi. All the tools needed to run a web server are available on the Debian-based Raspbian OS, so it’s perfectly fine. Even if you are a beginner, you can quickly turn your RPi board into a web server by following the steps above. Anyway, it’s all from us. If you have any questions, please let us know in the comments section below.