Raspberry Pi – Using it as Web Server and for PHP

There is a whole lot of cool stuff which can be done with the Raspberry Pi and it would be amazing to control this stuff by your browser / mobile phone / … The easiest way to do this is setting up a web server on the RaspPi and use PHP to execute interesting things.

Installing the Web Server

Here the simple steps to get an Apache web server running.

# Just update to make sure we have all the stuff we need
sudo apt-get update
# Now install Apache
sudo apt-get install apache2
# Starting Apache manually - just for reference
sudo service apache2 start
# Autostart of Apache - should be already the default
sudo insserv apache2

Installing PHP on Raspberry Pi

The easiest way for testing is creating the file phpinfo.php in the directory /var/www/ and opening it up in the web browser.

The phpinfo.php file:

<?php phpinfo(); ?>

Using PHP to control the GPIO of Raspberry Pi

A small and simple example to control one of the pins which can be turned off and on to see the concept. Just create the following file called control.php in the folder /var/www/ and open it up in the web browser.