Use Raspberry Pi as PHP server
Raspi can serve as a local or Internet server. It sends HTML pages to the browser or executes remote scripts.
I recommend installing a new version of Raspbian called Pixel, which makes it easier to set up the entire system using the GUI.
Install Classic Apache/PHP Server
PHP here is an option, you can use Apache with any type of language, including JavaScript.
Install Apache
Because raspi is connected to the Internet, type:
sudo apt-get install apache2 -y
Install PHP (optional):
sudo apt-get install php5 libapache2-mod-php5 -y
PHP 7 is not available in the current version (11/2016) of Raspbian (or even Debian), it could be installed, but it would be too difficult for a simple demonstration .
Now we check if PHP works, enter:
php -v
It should display "PHP 5.6."
Now we will place the file available to the remote client.
Go to the directory containing the public directory:
cd /var/www
There you will find a public directory for Apache that is html. But this is one of the delights of Linux, you have to have access to content. Enter:
sudo chown pi: www
Now you have access rights to place files in/var/www/html.
Now you need to delete index.html, which is already in the directory, or give it a different name.
Create the index.php file in a text editor from the command line. Go to/var/www/html and type:
sudo leafpad index.php
Using sudo will save you from the hell of access rights that will be encountered with the editor used from the graphical interface.
Minimal script as index file content to make sure everything works:
<?php echo date("Y-m-d : Serveur en ligne..."; ?>
To access Pi, you need the IP address of the device. It is displayed when the mouse hovers over the network icon:
eth0: Configured nnn.nnn.nnn.nnn/nn
From a browser on another computer connected to the Internet, enter the IP address of the print:
http://nnn.nnn.n.nn
And then you will see the date and the message "Online server...."
So you don't need to run Apache on a rasp.
In the next session, you will be on the command line, to restore the graphics mode, if necessary, you will need to run raspi-config.