[Watford] PHP

walt walt at helvatron.co.uk
Sat Dec 1 18:34:18 GMT 2007


Great! Many thanks. I understand the technology no problem.

I have apache2 running and it picks up the index.html and displays the test
website without any problems.  I then installed the PHP5 module (or whatever
its called) and hey presto your sample scripts in index.php worked fine.
Ergo php must be kicking in.

So now to learning the language.  There must be oodles of documentation on
the web. But I may be picking your brains later in my learning curve if
thats ok.

BTW: I am atheist with the motto live and let live.  So you have no worries
on that front.  I have read quite a lot about it all and although some of it
is well over my head I figured PHP looks like my best bet to start with.
Should I get to point of where I start seeing the advantages of the other
technologies I will have no hesitation in using them.  

I will need database access and if frameworks - django can do that I might
well switch to that in a few weeks.  I'll check it out.  

Are you going to the meeting (6th December) next week?

Thanks again, Walter

-----Original Message-----
From: watford-bounces at mailman.lug.org.uk
[mailto:watford-bounces at mailman.lug.org.uk] On Behalf Of Yvan Seth
Sent: 01 December 2007 16:49
To: watford at mailman.lug.org.uk
Subject: Re: [Watford] PHP

<quote who="walt">
> I usually use just a text editor for HTML and JavaScript which are 
> very easy to debug in most browsers.  I have no idea how PHP does it.
> There must something behind it that interprets and/or compiles the 
> script.

PHP is entirely interpreted at the server-side.  The usual method being that
the web-server internally (typically with a loaded "module") executes the
PHP interpreter over the "page" before sending the final generated HTML to
the client.  I.e. you have this in index.php on the
server:

    <html>
    <head><title>Silly</title></head>
    <body><?php echo "Hello World"?></body>
    </html>

A web browser "hits" your page and the server reads the above off disc and
runs the PHP engine over it to generate this:

    <html>
    <head><title>Silly</title></head>
    <body>Hello World</body>
    </html>

Which is then sent to the web browser.

> I thought an IDE would help understand it more easily.

I'm not aware of IDEs for PHP that do much beyond syntax highlighting.
Though I rely on vi for all my editing and so I'm pretty clueless when it
comes to these GUI critters :)

> If I use gedit how to I run the script and debug it?  

Two ways:

1. a) You have a page with embedded PHP code: index.php
   b) You have the "php" command, on debian-sarge, for example, this
      comes from the "php4-cli" package.
   c) You execute: php index.php
   d) This spits out the HTML as it would be sent to the web client.

That's pretty ugly though (you get a bunch of HTML dumped to the screen).
Almost all PHP developers I've seen work with "live" systems:

2. a) You have a web server installed with PHP support.
   b) You put your "index.php" within your web server's document tree.
      (And edit it in-place.)
   c) You visit the "index.php" via the web server with a web browser.
      (And hit shift-refresh to check things while you edit.)

This has the advantage of showing you the actual page as rendered, and you
can examine the HTML using Firefox's syntax highlighted "view source".  Plus
PHP natively generates error messages that render to web browsers.  (Also,
"tail -f <server-error-log>" is an invaluable tool when developing web
apps.)

You don't have to use your "live" website.  Typically you'll run something
like Apache on your local machine and view it from the same machine with
http://localhost/blah/...php

> By the way, this is just a 'retirement project' to keep my brains 
> occupied and, maybe, create some web applications in the process. I 
> will need MySQL database connections etc so I thought, after a bit of 
> research, PHP is just the job.  We'll see; I might be better off 
> reverting to MS-Access and VB :-(

Personally I'm not a fan of PHP, but it is easy to learn and start running
with.  It could also be worth considering "frameworks" like Django
(http://www.djangoproject.com/), which makes it easy to build web
applications quickly (and I like Python).  Of course, this way lies
religious wars.  There's Perl (with, say, Mason), Ruby (Rails!), etc...

HTH
-Yvan





More information about the Watford mailing list