L.A.M.P.Server is built with
PHP. The OS of Raspberry Pi, Raspian, is a Linux system. Below is a simple instruction to install the three packages that lay foundation of a LAMP server. It is rather straight forward to install and set up an
apacheweb server on a Raspberry Pi.
$ apt-get install apache2Once the installation is done. On any system within your LAN, bring up a browser and enter the address of the unit, i.e. the static IP given in a previous post as follows:
http://192.168.1.80The browser will display an apache default home page as shown. If the unit is intended to host a single site and all webpages static html, place these webpages in the folder:
/var/www/htmland the web site is good to go. With apache, the Raspberry Pi is able to host multiple sites as described later.
PHP, the Hypertext Pre-processor, is a powerful scripting language and it can be seen as a dynamic html generator at the server-end. Some other scripting languages, such as java script, produces dynamic effects on a webpage at the browser-end. In other words, the browser receives all information required for the effects to be shown at the browser end with java script; whereas with Php, the browser can only receive the resulting information dynamically generated by the server. Confidential data used to generate the html page is completely inaccessible at the browser-end. To use PHP, first install the PHP and its apache-library. At the time of this blog, Php 7.0 is the latest release available for Raspian.
$ apt-get install php7.0 libapache2-mod-php php7.0-mbstringThe add-on package
php7.0-mbstringis useful for handling string containing multiple-bytes characters. Once the installation is completed, go to the default folder mentioned in the previous post. First rename the
$ cd /var/www/html $ mv index.html index-apache.htmlThen create a file named
index.phpin the same folder containing the following script.
<?php echo "Php is working.";?>Issue a command
php -fand the result will show right on the screen.
$ php -f index.php Php is working.Otherwise, refresh the browser showing the default page of apache. The browser will display the message below.
Php is working.If replaced with the following script,
<?php echo date("Y-m-d H:i:s");?>The browser or the terminal will show the current system time whenever this page is visited or refreshed. The browser shows the contents generated by the php upon the reception of the request at the server site. There are a couple of MySQL servers available for Raspberry Pi. This site installs MariaDB as follows:
$ apt-get install mariadb-server mariadb-client php7.0-mysql phpmyadminA popular interface
phymyadminis also installed for database administration. During the installation, a couple configuration steps are needed for beginners below: