Making Raspberry Pi as Webserver

In this exercise you are going to learn how to make your Raspberry Pi as webserver and use it accordingly.Before getting into the installation of these packages we need to update our pi from the terminal using the command, sudo apt-get update, sudo apt-get upgrade, Then we need to install all the related packages simultaneously by running the following command.

Raspberry Pi Web Application

88 Views, 17 Nov 2017 12:31 pm

Description

Aim: In this exercise you are going to learn how to make your Raspberry Pi as webserver and use it accordingly.
Hardware Requirements:
  • Raspberry Pi 3B
  • USB Keyboard
  • USB Mouse
  • VGA TO HDMI cable
  • Raspberry PI’s power cable
STEPS INVOLVED:
Step-1: Installing PHP, Apache onto your Raspberry-Pi:
  • Before getting into the installation of these packages we need to update our  pi from the terminal using the command :  
  • sudo apt-get update
  • sudo apt-get upgrade
  • Then we need to install all the related packages simultaneously by running the following command
  • sudo apt-get install apache2  php5  libapache2-mod-php5
  • We are all familiar with sudo apt-get install ,here apache2 is the name of the web server and  php5 libapache2-mod-php5 for the installation of PHP.
  • If there are any dependencies that are not installed then Raspberry-Pi will suggest you some requirements.
  • Agree for that to be installed and your apache Web Server will be installed.
  • Then restart your server with following command:
  • sudo service apache2 restart

 
Step-2: Testing the Installed Packages on your Pi:
  • From the Raspberry Pi’s desktop start the Epiphany Web Browser and enter either 10.1.1.8 (or 127.0.1.1 which is the address that the Pi can ‘see’ internally (called the  local host address)) into the URL bar at the top.
We can see the following image on your Pi’s Display:

 
STEP-3: Remove Permissions for appearance of above web page according to our own requirement:
  • This can be easily achieved by giving the following command 
  • sudo nano /var/www/index.html
  • We make  the ‘www-data’ group and user the owner of the /var/www directory with the following command:
  • sudo  chown  www-data: www-data /var/www
  • Then we allow the ‘www-data’ group permission to write to the directory  with the following command:
  • sudo chmod  775  /var/www
  • Then we add the ‘pi’ user to the ‘www-data’ group with the following command:
  • sudo usermod –a –G www-data pi
  • This change in permissions are best enacted by rebooting the Raspberry Pi with the command
  • sudo reboot
STEP-4: Creating a database for storage of data:
  • Firstly ,we install  MYSQL with the following command:
  • sudo apt-get install mysql-server
  • You will be prompted to the following window:

 
  • Give a password for access to your database.
  • Once this installation is complete, we will install a couple more packages that we will use in the future when we integrate PHP and Python with MySQL. We do it with the following command:
  • sudo apt-get install mysql-client  php5-mysql  python-mysqldb
  • Now we install PhpMyadmin on your pi with the following commands: 
  • sudo  apt-get install phpmyadmin   
  • After typing that command we receive the following window on your Pi
 

  • Select apache2 and click on then you will get the following window

 
  • Click on yes and you will be asked for a password for your PhPMyAdmin  give the password in the window as shown below

 
  • Then you will be asked for the password you gave for MYSQL as shown in the window below:


  • Once finished, we need to edit the Apache web server configuration to access phpMyAdmin. To do this execute the following command :
  • sudo nano /etc/apache2/apache2.conf
  • Get to the bottom of the file by pressing ctrl-v a few times  an d then type the following 
  • Include  /etc/phpmyadmin/apche.conf
  • Then restart your apache2 service with the following command
  • sudo apache2 restart
  • Then open the browser and give your  Pi’s ip address followed by /phpadmin your phpmyadmin is ready for use

 
Conclusion: Hence, our  Raspberry Pi Web-Server is ready for use 


Latest IOT Projects
IoT Bootcamp From Sept 2
IoT Analytics Bootcamp From Aug 5
MQTT and CoAP Training From Aug 29
ThingWorx Training From Aug 24
Communication Protocols Training Coming Soon
IOT Development Kits
IoT Bootcamp From Sept 2
IoT Analytics Bootcamp From Aug 5
MQTT and CoAP Training From Aug 29
ThingWorx Training From Aug 24
Communication Protocols Training Coming Soon
Adds Here Adds Here Adds Here

TESTIMONIALS

Sowmya Kambampati
KONY India Pvt Ltd, as a Associate Software Engineer
Ratings :
Review:

I am very thank full to you all for giving such a great training and opportunity to explore my ideas in the stream of IoT, started with a 2 week workshop, very well Hands-on session ever had before...

Poorna prudhvi
Associate Software Engineer in mroads Pvt Ltd
Ratings :
Review:

I interned at smart bridge it's on a mission to become the power House of IOT.The work here is innovative and colleagues are very friendly.i would definitely recommend smart bridge to be a part of you..

P. Sai Teja
System engineer in IBM
Ratings :
Review:

I have done my project and Iot training at Smart Bridge Technologies based on which I got placed in IBM as a system engineer. I am very thankful that i have found my way to build my career further. Th..

Revathi Dhage.
Intern
Ratings :
Review:

The Project was developed in time, and it was appreciated .Many small details were covered well, and proved to be distinguishing points to the project.The concerned mentor, Sandeep Doodigani, has been..