Wednesday, July 30, 2014

Raspberry-Pi Web Serveur

SETTING AN APACHE WEB SERVER ON A RASPBERRY PI

Apache is a web server application you can install on the Raspberry Pi to allow it to serve web pages.

On its own, Apache can serve HTML files over HTTP, and with additional modules can serve dynamic web pages using scripting languages such as PHP.

INSTALL APACHE
First install the apache2 package by typing the following command in to the Terminal:
sudo apt-get install apache2 -y

TEST THE WEB SERVER:

By default, Apache puts a test HTML file in the web folder. This default web page is served when you browse to http://localhost/ on the Pi itself, or http://192.168.1.10 (whatever the Pi's IP address is) from another computer on the network. To find the Pi's IP address, type 
hostname -I at the command line Browse to the default web page either on the Pi or from another computer on the network and you should see the following:





Great This means you have Apache working!





CHANGING THE DEFAULT WEB PAGE

This default web page is just a HTML file on the filesystem. It is located at /var/www/index.html. navigate to this directory in the Terminal and have a look at what's inside:
cd /var/www
ls -al
Try editing this file (index.html) and refreshing the browser to see the web page change.

YOUR OWN WEBSITE


If you know HTML you can put your own HTML files and other assets in this directory and serve them as a website on your local network.

ADDITIONAL - INSTALL PHP

To allow your Apache server to process PHP files, you'll need to install PHP5 and the PHP5 module for Apache. Type the following command to install these:
sudo apt-get install php5 libapache2-mod-php5 -y
Now move the index.html file to index.php:
sudo mv index.html index.php
and edit the file with nano:
sudo nano index.php
to put some PHP content in it:
<?php echo "hello world";
Now save and refresh your browser. You should see "hello world". This is not dynamic but still served by PHP. Try something dynamic:
<?php echo date('Y-m-d H:i:s');
or show your PHP info:
<?php phpinfo();

FURTHER - WORDPRESS

Now you have Apache and PHP installed you can progress to setting up a WordPress site on your Pi. Continue to WordPress usage.

No comments:

Post a Comment