This article demonstrates how to make a lightweight web server for the home using Raspberry Pi 3 and Python 3 IDE.
Pi can even handle a web server; so if you want to launch your own website with a proper back-end, you can easily do it. This web server is used to get a small amount of traffic and for development purposes.
I used the following equipment for this Raspberry Pi web server article.
Set up Wifi on Raspberry Pi.
First, the Raspberry Pi must be connected to your desktop. Then, connect your wi-fi on your Pi or connect your ethernet. After that, open the terminal of your Operating System using the following code.
After that, open the terminal box and enter your default PI name and password.
- Username (pi)
- Password (raspberry)
The connection is successful.
Step 3
Next, update the Raspberry Pi. So, install the latest packages. You can do that using the following commands.
- sudo apt-get update
- sudo apt-get upgrade
or
- sudo apt-get update && upgrade
Step 4
Next, we will need to install the Apache web server. Just use the following commands.
- sudo apt-get install apache2 -y
If you don't know the IP address, you can enter the following command line.
Open Browser, Enter IP address in the browser, and you should get an Apache instruction page.
Step 6
Now, we are going to edit this simple page entering the following command.
- sudo nano /var/www/html/index.html
After that, open index.html editing page. Just replace the following HTML codes. You can add new web pages as you want, in the www folder and view from the browser.
- <html>
- <body>
- <h1>Hi This is Ravishankar</h1>
- </body>
- </html>
Next, open the browser, enter the IP address (192.168.8.101) in a browser, and you get your HTML page.
This is a basic server but if you are using PHP for the dynamic website, then read on. To install the PHP package, let's download PHP5 module for Apache.
- sudo apt-get install php5 libapache2-mod-php5 -y
Now, create a new file and edit this example page entering the following command. After that, open and edit the file. In this file, add the following PHP code.
- sudo nano /var/www/html/example.php
PHP Code
- <?php
- echo "Today's date is ".date('Y-m-d H:i:s');
- ?>
Next, open Browser, Enter IP address + Page Name in a browser, and you get your PHP page. The index page is a default page so IP address is only needed, but additionally, we can add the new web page to need for the page name (192.168.8.101/example.php).
Finally, we have successfully created a Mini Web Server using Raspberry Pi.