Page 62 - Beginning PHP 5.3
P. 62
Part I: Getting Up and Running with PHP
This is a very simplified overview, and in practice you often need to install other libraries and
applications — particularly on Windows — to successfully compile PHP. You can find detailed
information on how to compile PHP for UNIX, Windows, and Mac OS X systems at http://www.php
.net/manual/en/install.php .
Running PHP Remotely
If the idea of installing PHP on your own computer is a bit daunting, you can always create and test PHP
scripts using the Web hosting account where your Web site is hosted (assuming the account supports
PHP). This is easier if your account runs on a UNIX - type server such as Linux or BSD and supports ssh
access; this way, you can connect to the server using ssh and develop and test your PHP scripts right on
the server via the command line.
To access the Web server via ssh, you need an ssh client. On Ubuntu install the ssh package if it ’ s not
already installed; on Windows try putty ( http://www.putty.org/ ). Mac OS X comes with an ssh client
preinstalled.
If your Web hosting account supports PHP but doesn ’ t support ssh, you can write your PHP scripts on
your computer using a text editor, then use FTP to upload them to the Web server for testing. It can be a
tedious process, because you have to wait for the script to upload every time you want to test your
changes, but it ’ s better than nothing!
Creating Your First Script
Now that you have successfully installed PHP on your computer, or gained access to another computer
running PHP, it ’ s time to start writing your first proper PHP script. This script will do one very simple
thing: display the text “ Hello, world! ” in the browser window. Once you have this script working, you ’ ll
learn how to enhance it in various ways.
To create this very simple script, open your text editor once more and enter the following:
< ?php
echo “Hello, world!”;
? >
Save this file as hello.php in your document root folder, and view the results in your browser by
visiting http://localhost/hello.php. You should see something like Figure 2-12 .
Figure 2-12
24
9/21/09 8:50:24 AM
c02.indd 24
c02.indd 24 9/21/09 8:50:24 AM