Page 57 - Beginning PHP 5.3
P. 57
Chapter 2: Your First PHP Script
By default, MAMP ’ s Apache server runs on port 8888, and its MySQL server runs on port 8889. This
is to avoid conflicts with any other Apache or MySQL server that might be running on your Mac, but it
does mean that you need to specify the Apache port (8888) in the URL in your browser ’ s address bar, as
shown in Figure 2-9 . If you prefer, you can click the Preferences button in the MAMP application to
change the ports that the MAMP Apache and MySQL servers use. For example, provided you ’ ve
stopped any other Web servers on your Mac that might use the standard HTTP port of 80, you can set
the MAMP Apache port to 80 to avoid having to type the port number into your browser ’ s address bar.
As with the Linux and Windows install options previously discussed, MAMP installs PHP 5.2 at the
time of writing, not PHP 5.3. However, by the time you read this book there ’ s a good chance that a
PHP 5.3 version of MAMP will be available.
Testing Your Installation
Now that you ’ ve installed Apache, PHP, and MySQL on your computer, you ’ re ready to test the
installation to make sure everything ’ s working OK. Along the way, you ’ ll create your very first PHP
script (albeit an extremely simple one!).
Testing the Web Server
The first thing to do is to create a simple HTML Web page for testing. In a text editor such as Notepad for
Windows, TextEdit on the Mac, or vi/emacs/pico on Linux, create the following simple Web page:
<html>
<head>
<title>Testing</title>
</head>
<body>
<h1>Testing, testing, 1-2-3</h1>
</body>
</html>
Call the Web page testing.html and save it in your Web server ’ s document root folder on your hard
drive. What ’ s the document root folder, you ask? When you install Apache, it comes with a default Web
site. This Web site has a document root folder, which is the top - level folder into which you put the
Web site ’ s files. You want to save your testing.html Web page in this folder so you can browse it via
your Web browser.
So where is the document root folder? That depends on your setup, as follows:
❑ If you ’ ve installed Apache on Ubuntu Linux, the document root folder is probably /var/www.
❑ With WampServer on Windows, the document root folder is usually in C:\wamp\www.
❑ If you installed MAMP into the /Applications folder on the Mac, the document root folder is
likely to be /Applications/MAMP/htdocs. (Note that you can check this, and even change it,
by opening the MAMP application and clicking Preferences, then clicking the Apache tab.)
So save your testing.html file to the appropriate folder, and then open a Web browser and type the
following into its address bar:
http://localhost/testing.html
19
9/21/09 8:50:22 AM
c02.indd 19 9/21/09 8:50:22 AM
c02.indd 19