Using the Raspberry Pi as a PHP server
The raspi may be used as a local or Internet server. It send HTML pages to a browser or execute remotely scripts.
I would recommend installing the new version of Raspbian named Pixel, this makes it possible to configure the whole system with the GUI, so more easily.
Installing a classic Apache/PHP server
With raspi 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 (nor even Debian), it would be possible to install it, but it would be too complicated for a simple demonstration.
We now check that PHP is working, type:
This should display "PHP 5.6".
We will now place a file accessible to a remote client.
Go to the directory containing the public directory:
There is here the public directory for Apache which is html. But, it's one of the charms of Linux, you need to be able to access content. Type:
sudo chown pi: www
You now have access rights to place files in /var/www/html.
You must now delete index.html which is already in the directory or give it a different name.
Create the index.php file with the text editor from the command line. From /var/www/html type:
sudo leafpad index.php
The use of sudo will avoid the hell of access rights that will be encountered with the editor used from the GUI.
A minimal script as contents of the index file to verify that everything works:
<?php echo date("Y-m-d : Server online..."; ?>
To access the Pi, you need the IP address of the device. It appears when you move the mouse over the network icon:
eth0: Configured nnn.nnn.nnn.nnn/nn
From the browser on another computer connected to the Internet, type the IP of the raspi:
Then you will see the date and the message "Server online...".
So no need to start Apache on the raspi.
At the next session, you will be on the command line, you will have to run raspi-config to restore the graphic mode if necessary.