2. What Is Raspberry Pi
• Credit-Card sized computer
• Developed in U.K by Raspberry Pi foundation in 2009.
• Project Initiated By Initiated by Eben Upton.
• Based on Broadcom chips.
• Supported by UCCL and Broadcom.
• Affordable
• Runs LINUX. Microsoft is developing Windows 10 for
newer boards.
• Consumes less than 5W of Power
• Supports Full HD Video Output (1080p), Multiple USB
Ports , etc
8. Making a web server using Raspberry pi
What are the equipments required to do
this project?
1.Raspberry Pi 2/B+
2. Wi-Fi router with access to internet
3. Wi-Fi dongle for Raspberry Pi or LAN
cable.
Here is the project map
9. STEP 1: Installing Apache, PHP and MySQL for your Raspberry Pi web server
1. Before we start, make sure your Raspberry Pi is up to date. For this the code in
terminal(as we are using Linux 16.04 OS) “sudo apt-get update”
2. we will start installing all the packages necessary for our raspberry pi web
server. For this purpose we need to get into the root of our system by using “sudo
bash” command.
3. Now lets install ‘Apache’ the main component of the project. For that, use the
following command, “apt-get install apache2 apache2-doc apache2-utils”
4. After this, it is time for PHP to get into our pi, “apt-get install libapache2-mod-
php5 php5 php-pear php5-xcache”
5. Now we should install the package for database connectivity, “apt-get install
php5-mysql”
6. Now we can use install the MySQL server which stores everything, our database
for the raspberry pi web server, “apt-get install mysql-server mysql-client”
7. During this installation, you will be asked for a password for the server. Enter a
password that you will remember. That’s it! You have completed the first step!
Now reboot the pi.
10. STEP 2: Testing the installed packages on our Raspberry Pi
For testing the presence of the installed server
and database. Type ‘localhost’ or ‘127.0.0.1’ in
the pi’s web browser. If you have ssh’d into it,
type the pi’s ip address in your browser. Now
you should see a page saying ‘It works!’.
Location of the webpage which is shown in
picture is named as index.html file in the
‘/var/www’ directory.
Now, for testing mysql on your raspberry
pi, open up LXTerminal and type as
follows, “sudo mysql -uroot -p”
11. STEP 3: Installing phpMyAdmin for your Raspberry Pi web server
phpMyAdmin is a free and open source
tool written in PHP intended to handle
the administration of MySQL with the
use of a web browser. This makes it
easier to control the database. So, to
install it for your raspberry pi web server,
you can use the following commands.
Open the terminal and let’s start with,”
sudo apt-get install phpmyadmin”
& Choose apache2.
Next, we will need to configure
the database phpmyAdmin
should use. For that you should
select Yes when asked
12. After this, you will be asked for an administrative password. Type in the password of
your MySQL database you installed earlier. Next, you will be asked for a custom
password for phpMyAdmin. I typed in the same password of MySQL, as it will be easier
to remember. If you wish, you can have another password also.
Now, we need to combine apache with phpMyAdmin. For that, you should edit the
apache2.conf file. For that, type the following in the terminal,” sudo nano
/etc/apache2/apache2.conf”
At the end of this file (navigate using Ctrl+V), add a line, ”Include
/etc/phpmyadmin/apache.conf”
Now restart the server using, “sudo /etc/init.d/apache2 restart”
Now, check out the link in your web browser: <pi’s ip address>/phpmyadmin or
localhost/phpmyadmin in your pi. You should see the same page in the next slide.
STEP 3: Installing phpMyAdmin for your Raspberry Pi web server
13. STEP 3: Installing phpMyAdmin for your Raspberry Pi web server
As the username, you can type in ‘root’ and
as the password, you can type in the
password you gave for the MySQL Server.
Now, you can have your own site by
customizing the index.html or by inserting
customized html file and renaming it as
index.html in the www folder. You can put
images, videos or whatever you want in the
www folder and access it in your Local
Area Network(LAN). Now that you also
have a database of your own and you can
maintain the site with it. So we can call it
your ‘Server’, a Raspberry Pi web server.
14. STEP 4: Give your Raspberry Pi a static IP address
Now, this is not possible to access the server from another network. User can only
access your server within the local Network. What we are going to do now is that we
are going to make our server available worldwide.
In this step, the IP Address of the pi is set to DHCP. We need to change that into a
static IP address. For that we need to edit a file in our pi.
Now edit the network interfaces. It is located in /etc/network/interfaces. For this in
the terminal type, “sudo nano /etc/network/interfaces”
The highlighted part, which
is iface eth0 inet
dhcp should be changed
to: iface eth0 inet static
15. STEP 4: Give your Raspberry Pi a static IP address
Now put the numbers in the network interface file,
numbers will change by the user.
address: It is the inet address, you got from ifconfig
command. You can give any number starting with
192.168.1.xxx. The xxx can be replaced with any
number. It is better you have it between 2 and 100.
Choosing a higher number is recommended since when
you have a lower number it may result in clash of IP
addresses. Two devices might have the same address.
That is the reason I gave it a higher number.
Netmask: It is the Mask address in the “ifconfig”
command.
Network: It is the Destination address you got from the
“netstat -nr “command.
Broadcast: It is the Bcast address you got from the
“ifconfig” command.
Gateway: It is the gateway address you got from the
netstat -nr command.
“Sh”
16. STEP 4: Give your Raspberry Pi a static IP address
Edting iface file now, press Ctrl+X to
save it and press y.
After this reboot your pi and check
the ifconfig command.
If inet address shows your new IP
Address its confirmed that the server
got a static IP address.
17. STEP 5: Finishing tasks.
First, we need to sign up for an account in www.no-ip.com. This service is for free.
What Dynamic DNS does is simple. Our ISP (Internet Service Provider) gives us an External IP
address, that is random. No-IP.com changes our IP Address into a URL. We also configure this in
our Router which will be shown soon. So, whenever our modem gets a new IP, it sends it to No-
IP.com by which they connect the new IP Address and our static URL for our Raspberry Pi web
server. The URL never changes but the IP does.
After account creation, you should activate your account using the e-mail sent by No-IP.com. You
can sign in to your account after the activation of the same. You can see your new URL in the
submenu Hostnames under Dynamic DNS Menu.
You can check your URL by clicking on it.
As your Raspberry Pi Web Server is just
set up, you can see the It Works! Page.
18. Everything is done. User can access it with just one URL. Accessible to the whole
World! All the best with your Server! User can make amazing websites easily using
the templates and styling using css available on the internet.
As the website has new domain name in the addressbar it will show the website
name instead of showing the static ip address of the server.
STEP 5: Finishing tasks.