Вы находитесь на странице: 1из 7

HOSTING A WEB SERVER ON

RASPBERRY PI
WEB SERVER
A web server is a computer system that processes requests via HTTP, the basic network protocol
used to distribute information on the World Wide Web.
The primary function of a web server is to store, process and deliver web pages to clients. The
communication between client and server takes place using the Hypertext Transfer Protocol
(HTTP). Pages delivered are most frequently HTML documents, which may include images,
style sheets and scripts in addition to text content.Any computer can be turned into a Web server
by installing server software and connecting the machine to the Internet.
A user agent, commonly a web browser or web crawler, initiates communication by making a
request for a specific resource using HTTP and the server responds with the content of that
resource or an error message if unable to do so.

APACHE
Apache is a freely available Web server that is distributed under an "open source" license.
There are actually two "apache" web servers. Apache is shorthand for the Apache Software
Foundation which is one of the largest if not the largest free and open source software
organizations.
They have two web servers that they have developed. By nomenclature "Apache" is Apache
HTTP Server (sometimes also called Apache httpd - after the name of the process). The other
"Apache" server is Apache Tomcat - which most people just call Tomcat. I'm assuming you are
asking about Apache HTTP.
Apache HTTP has been around since 1995 and is the dominant web server in the world. As of
June 2013 - Apache HTTP is estimated to serve ~55% of all websites.

WHY APACHE?
- A very long history of reliability and performance.
- Mass adoption means there is a LOT of documentation out there and it is very easy to get help
with any trouble you might run in to.
- It is free and commercial friendly - no licensing fees or costs.
- It will run on pretty much any OS (Linux, Windows and MacOS)

- It is actively maintained.
- It is one of the most feature rich web servers available.

Creating Raspberry Pi Web Server using PHP


1. First we will need install the apache2 package:
sudo apt-get install apache2 -y

2. To check that it is working we should be able to enter the Pis IP address. If you dont
know the IP you can enter the following line
hostname -I

3. Browse to the IP address in a browser and we should be able to get the default page.
4. Now youre able to edit this basic file by simply entering the following command.
sudo nano /var/www/index.html

5. You can now add as many new webpages as you want in the www folder and they will be
viewable from the browser.
6. This is a very basic server and is great if you just want to learn HTML, JS or CSS but if
youre after PHP (Used for dynamic web pages) then read on.
7. To install PHP we will need to first get the PHP package so download the PHP5 module
for apache. To do this enter the following:
sudo apt-get install php5 libapache2-mod-php5 -y

8. Now we can place php files in the www and they will be processed and displayed. For an
example lets make a file called example.php
sudo nano /var/www/example.php

9. In this file add the following:


<?php
echo "Today's date is ".date('Y-m-d H:i:s');
?>

We have a fully working Apache2 + PHP Raspberry Pi Web Server working. Now
youre able to have mix of HTML and PHP files all in the www folder(You can have
normal HTML outside the <?php ?> tags).

Installing Raspberry Pi WordPress


WordPress is a content management system/blogging software that is used by over 60 million
websites. Amongst the top 10 million websites on the web 23.3% of these use WordPress.
It is very easy to install & learn,the basics making it a great way to launch your very own website
or blog. Installing Raspberry Pi WordPress on to the web server is dead easy and can be done in
just a few steps detailed below.
1. Now we have already installed PHP but we will also need MySQL and the MYSQL PHP
packages.
sudo apt-get install mysql-server php5-mysql -y

2. We will need to now download and extract the WordPress package that we can easily
download. To do this do the following commands:
cd /var/www
sudo chown pi: .
rm *
wget http://wordpress.org/latest.tar.gz
tar xzf latest.tar.gz
mv wordpress/* ./
rm -rf wordpress latest.tar.gz
sudo chown -R -f www-data:www-data /var/www

3. Now thats installed we will need to setup a database to connect to. Now we could install
PHPMyAdmin for database management but instead we will do it via command line.First
we need to use the mysql command to login, use the p flag for the password and u for
the username. Leave no space between the flag and required text. write
mysql -uroot -ppassword

4. Now lets create a database for this tutorial lets call it WordPress.
create database wordpress;

5. You should now see a success statement that looks something like the following:
Query OK, 1 row affected (0.00)

6. Now lets exit out of MySQL prompt by pressing Ctrl + D

7. Now in a browser go to the Pis IP address and you should be presented with a WordPress
setup screen. Fill in the relevant information such as:
o Database Name: wordpress
o User Name: root
o Password: (Password you created at the MYSQL setup)
o Database Host: localhost
o Table Prefex: wp_

APPLICATION
Controlling an LED using Web Server

1)Connect the circuit as shown in the diagram above

2)In pi prompt type the following


sudo nano pinon.php
In the php window type the below lines
<?php
system ( "gpio mode 24 out" );
system ( "gpio write 24 1" );
?>

Save it to the file

sudo nano pinoff.php


<?php

system ( "gpio mode 24 out" );


system ( "gpio write 24 0" );
?>

save it to the file


3)In the web browser enter
(pi_address)/pinon.php or (pi_address)/pinoff.php to switch on/off the LED respectively

Вам также может понравиться