HOME      Other material for programmers   Pi? Arduino? Other?
(Parent page for this and other small getting started with Raspberry Pi tutorials)

I have notes for translators, if you would add a translation.


Using php...
Raspberry Pi edition... with much for other readers

Webserver3

filename: pt0FirstWebserver3.htm

More webserving...

This is part 3 in a series of pages about doing webserving. Parts of it are specific to serving with a Raspberry Pi, but after part 1, much is relevant to any webserving. Webserver1 explained how to create a webserver on a Pi. Webserver2 explained how to make an existing webserver accessible across the whole internet.

This part will introduce you to php. Among other things, it will tell you how to upgrade a Pi with "just" the Apache webserver software to a Pi with Apache AND php.

php

If a webserver has the necessary additional software running, and in the same folder as the .htm files it can serve up to a browser, if you add a file that says....

<html>
<head></head>
<body>
<p>Really simple example of php...</p>
<br>

<?php
  echo date('h:i:s');
?>

</body>
</html>

... and save that as "ReallySimple.php"... then if someone accesses the file, using "ReallySimple.php", when the system time in the server is 10:23:05, they will get...

Really simple example of php...
10:23:05

This is pretty cool! With mere html, we can get set up web pages to deliver mostly static content. With php, when a "customer" asks for a page, what they get can be "assembled", according to a "scrip", turning out a different page every time.

I have barely scratched the surface in my example of What PHP Can Do. There are many places on the internet where you can learn more.

In this introduction to using php, I want to stress just a few things...

Some php pages consist mostly of "normal" html, with just small bits "done by" php. The php bits are enclosed between...

<?php

//... and ...

?>

(Lines inside the php part of a page beginning "//" are comments... they are ignored by the php script processor.

For the magic to work, the file has to be saved with .php as the extension. (And the person wanting the page has to ask for it with that extension.)

The user of .php pages doesn't need anything special on his/ her machine.

The serving machine has to have a php engine in it, in addition to the basic web serving software.

So How Do I Get PHP Processing For My Pi/ Apache Webserver?

As I hope I already made clear: You need a working webserver, Apache is recommended, before you even think about adding php. My earlier Webserver pages covered getting that in place.

The first time I did this on a Pi, I was very new to working on Pi's... and, with the update/ upgrade, it only took me 15 minutes to add php to my server!

I did the usual sudo apt-get update / sudo apt-get update.

Then...

sudo apt-get install php libapache2-mod-php -y

... which only took about a minute.

Then I rebooted the system, just to be tidy. Always prudent after major installs.

I put a REALLY CRUDE bit of php in a file called tmp.php....

<?php
  echo("Hi from PHP. Time is... ");
  echo date('h:i:s');
?>

And tried to run it.

It worked!

That's it, for PHP

I think we deserved something so deliciously simple, after the trials and tribulations in the preceding tutorials. Don't you agree?


Hope that helped?

I hope that was helpful. Getting started is always so tedious. This page was just "a sidebar" off of my main "Getting started with Raspberry Pi" page. Feel free to contact me (see below) with comments, suggestions, questions... save the next reader being confused by something? Please cite this page's URI, if you do: pt0FirstWebserver3.htm.




Footer

Please remember that this material is copyright. (TK Boyd, 2018) There are further notes in this page's parent page.




   Search this site or the web      powered by FreeFind

Site search Web search
Site Map    What's New    Search

The search engine is not intelligent. It merely seeks the words you specify. It will not do anything sensible with "What does the 'could not compile' error mean?" It will just return references to pages with "what", "does", "could", "not".... etc.

This page is a "sidebar" to my main discussion of Getting Started with the extraordinary Raspberry Pi.




To email this page's editor, Tom Boyd.... Editor's email address. Suggestions welcome!



Valid HTML 4.01 Transitional Page tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org. Mostly passes. There were two "unknown attributes" in Google+ button code. Sigh.

Why does this page cause a script to run? Because of the Google panels, the code for the search button, etc. Why do I mention scripts? Be sure you know all you need to about spyware.

....... P a g e . . . E n d s .....