Raspberry Pi_Eng_24.4.2 Installing PHP and Connection Tool to MySQL


Published Book on Amazon


All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2


출판된 한글판 도서


최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상)
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하)


Original Book Contents


24.4.2  Installing PHP and Connection Tool to MySQL

 

When installing PHP on Raspberry Pi, use the following command:

 

sudo   apt-get   install   php5

 

If PHP is installed, the configurations of existing Apache are automatically adjusted so that PHP can integrate with Apache.

 

In order to construct various dynamic web pages, PHP should utilize various informations in the database. For this, PHP must be able to access MySQL database to perform the necessary tasks. To do this, the following additional programs must be installed.

 

sudo   apt-get   install   php5-mysql

 

Through this program, PHP can access a specific database in MySQL, refer to the data, send dynamic HTML created with these data to Apache so that it can be displayed as a web page.

 

The framework for overall relationship between each component is shown below.

 


If a web browser calls a specific web site in an Apache web server, it calls the linked HTML file. If the HTML file has a part that requires PHP processing, it calls PHP. PHP, if necessary, calls MySQL database, refers to various data inside database, create dynamic HTML, and integrate it with existing static HTML so that it can be processed.

 

Apache is originally supposed to use "index.html" in "/var/www/" folder as the default web page when a user accesses the web site. If PHP is installed, the processing method is slightly modified. If there is "index.html" file in "/var/www/" folder, it is used. If the file does not exist, then it will find "index.php" file and display a basic web page based on the contents of that file..

 

If PHP installation is compelte, let's check if PHP is working properly. First, create a text file with the following content. The meaning of this file is to execute a function called "phpinfo ()" in PHP and then make the result into HTML. Save this file as "/var/www/ index.php".

 

<?php

   phpinfo();

?>

 

Then open your web browser and type "http://<IP address>/index.php" and run it. Then, if the following screen appears, it means that PHP is working normally. If you go down the screen, you will see that MySQL informations are also displayed.


Figure 24‑9 PHP info