Setting up Apache web server in Raspberry Pi using python

Learn to create and using Apache web server in Raspberry Pi. Apache is one of the most popular web server application used in Raspberry Pi to server web pages. Apache is able to serve HTML files over an HTTP connection. To serve dynamic web pages, languages such as PHP and JS is used. So, let’s start.

Step 1: Install Apache in Raspberry Pi

Start Terminal window in Raspberry Pi and install Apache2 by entering below given command.
sudo apt-get install apache2 -y

Step 2: Testing Apache web server.

By default, Apache has test HTML file in the web folder. This page will be served at localhost on Raspberry Pi and will be accessed through following ways.

  1. http://localhost/
  2. http://"ip address of your Raspberry Pi"/

Step 3: Build Advanced Webpage

Follow below-given steps to build Apache web server in Raspberry Pi.

  1. Change default page located at “/var/www/html/index.html”
  2. To edit this file, you need to change ownership to your username. Assuming your username is Pi, use following code to change ownership.
    sudo chown pi: index.html
  3. Change contents of “index.html” to your preferred HTML content and save the file. For testing purpose, you can use HTML contents form this page. HTML content is in step 3 of the page.
  4. For using PHP, you must save the file as “index.php”
  5. To see changes take place, go to the browser and reload the page.

Using Apache server you can view your web pages on another computer connected to the same network.

For basic hardware information about Raspberry PI 3, Click here.

Leave a Reply