Chapter 2. Your First PHP Script

Now that you have a feel for what PHP is, it's time to dive in and start writing PHP programs. To do this, you'll first need access to a Web server running PHP. This chapter kicks off by showing you, in simple terms, how to install the following programs on your computer:

  • The Apache Web server

  • The PHP engine

  • The MySQL database server

You also learn a bit about troubleshooting Web servers as you go.

The installation process is fairly straightforward; however if you're put off by the idea of having to install these programs on your computer, you can instead run your PHP scripts on a remote Web server that's already set up for the job (see the section "Running PHP Remotely" later in the chapter).

Once you have PHP up and running, you get to create your first PHP script. Along the way, you learn how you can embed PHP code within an HTML Web page, which is one of the fundamental concepts of PHP.

You then extend your script to display some dynamic information in the page — in this case, the current time — and you also learn about comments: how to write them, and why they're useful.

Once you've followed this chapter, you'll have a basic understanding of how to install PHP, and you'll have learned how PHP scripts are put together. This is all useful knowledge that you'll build on in later chapters. So let's get going!

Installing PHP

To create and run PHP scripts, you need to have a few things in place:

  • A computer running Web server software, such as Apache or ...

Get Beginning PHP 5.3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.