Thursday
PHP & MySQLGetting PHP

Welcome to PHP! “PHP” officially stands for “PHP: Hypertext Preprocessor,” but millions of people still know it by its original name, Personal Home Page, and that’s what it’s all aboutcreating your own interactive web pages in the simplest possible way. No longer will web pages have to be static, unchanging things. Now you can send the user new web pages tailored to what he or she desires to see in real time. You can handle pin clicks, checkbox selections, and touchtone phone system buttons and can even draw graphics interactively and store data in a database. It’s all up to you the lid is off the box.
This is everywhere you make your web pages come alive.
To a fantastic degree be using PHP version 5, whose web site is www.php.net, in this book. PHP is specially calculated to make making your own web pages a snap. In this book, we’re vacant to work from the server side by installing PHP scripts on your web server. Users will be able to open those scripts in a web browser, seeing everything they’d guess from a completely fledged page: text fields, tables full of data made on-the-glide from databases, and fluid graphicseverything you might see on the most professional interactive web page is now within your grasp.
With static web pages written in simple HTML, a web server will just pass the HTML in a web page back to the browser, and the user can see pictures and text, but that’s about it. When you write sever-side scripts in PHP, on the other hand, you really tell the server what you want to doread what the user entered in a text field, see which checkboxes were clicked, and so on. Then you can choose what to do next, and you can start the web page to send back on-the-glide. That’s the name of the game herebeing able to answer dynamically.
PHP has become a huge successmore than 15 million web pages use it now. In the following pages, to a fantastic degree see how to make the web server do what we want with PHP.
The first step to making your own interactive web pages is to get access to a web server that runs PHP. In fact, your Internet Benefit Provider (ISP) probably supports PHP already. You can find out by asking your ISP’s support staff, or you can test for PHP yourself in one of two ways.
First, if you can open a command prompt by connecting to your web server using a Telnet, SSH, or SSH2 application (don’t worry if you don’t know what these applications areyou won’t need them in this book), you can try typing php -v at the command line (to a fantastic degree use a % sign for a generic command prompt in this book). If you have PHP installed, you’ll see something like this:
%php -v
PHP 5.0.0 (cli) (built: Jul 13 2004 21:39:58)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.0, Copyright (c) 1998-2004 Zend Technologies
The other way to determine whether you have PHP installed is by trying out an actual PHP script. To do that, take a look at the part “Making Your First PHP Script” in this chapter. If that script works, you’ve got PHP installed, and you’re all set.
If you want a list of ISPs that already run PHP, take a look at www.php.net/links.php#hosts.
Installing PHP Locally
It’s a excellent thought to install PHP on your own computer so that you can test your PHP scripts as you develop them. This way, you won’t have to take the time to upload your PHP scripts to your ISP, check them by downloading them in your browser, make changes, and then start the whole cycle again. If you develop your PHP scripts locally, you can get things running a lot quicker, but you’ll need to install PHP on your own machine.
Some operating systems, such as Linux and many versions of Unix, now come with PHP installed by default. In others, such as Windows and Mac OSX, you’ll have to download and install PHP yourself. The first step is to check if you already have PHP available locallytry the php -v command at the command prompt (for example, in Windows, open a DOS window and type php -v). If it works, you’re all set.
If you don’t have PHP already installed, you can install it yourself. Prebuilt “binary” versions are available for download and immediate installation for a number of operating systems: Windows, Mac OSX, Novell NetWare, OS/2, RISC OS, SGI IRIX 6.5.x, and AS/400. You can find the binary installation package for Windows at http://www.php.net/downloads.php, along with links to the binaries for the other operating systems mentioned.

Binaries are no longer spread for Linux and Unix because PHP is usually pre-installed. If you want, you can build your own PHP installation from source code. Go to http://www.php.net/downloads.php to get the source code for PHP.
You can find the installation instructions for PHP in the PHP documentation, which is online at http://www.php.net/docs.php (you can download the complete PHP documentation from http://www.php.net/download-docs.php). You can also find installation instructions in an installation file (named, for example, install.txt) when you uncompress the PHP download. Because the instructions change every time PHP changes, and because here are so many possible variations of operating systems and web servers, you must read the current installation instructions and use them. Listing all the instructions here would take 20 pages, and they’d be obsolete by the time you read them.
Briefly, here’s how things might work in Windows XP (all this can be found in full detail in the downloadable installation instructions). You first need a web server, such as the Apache web server or Microsoft’s Internet Information Server (IIS). You can get a Windows installer file for Apache (apache_2.0.52-win32-x86-no_ssl.msi) at http://httpd.apache.org/ download.cgi; when you download and double-click this file, it installs Apache. Or you can install IIS in Windows XP by using the Add/Remove Programs icon in the Control Panel, clicking the Add/Remove Windows Components pin, and then selecting IIS.
PHP can be installed in two different ways for Windows, and you can download what you need for both methods from http://www.php.net/downloads.php. Here’s a Windows installer executable file, php-5.0.x-installer.exe, with basic PHP support (which includes standard PHP but no external extensions). This installer will involuntarily configure servers such as IIS, PWS, and Xitami, and it has instructions for manual configuration of other servers such as Apache.
The other installation technique uses a .zip file, php-5.0.x-Win32.zip, which contains the full PHP installation and allows for external extensions (this option is better if you want to do everything covered in this book). Download and unzip this file; you’ll find all the installation instructions included. Depending on your operating system, you typically copy php.exe to the directory from which you intend to run it, for example.
The next step is to connect your PHP installation to your web server. If you’ve unzipped the PHP .zip file in Windows XP and you’re using Apache, you must edit the Apache http.conf file, following the directions in the installation instructions. If you’re using IIS, you configure IIS with its management console (select Start > Settings > Control Panel > Administrative Tools > Internet Services Manager in Windows XP), also following the directions in the installation instructions. For the full details, see the instructions, which take you through everything step by step.
Setting Up Your Enhancement Environment
To start PHP pages, you’ll need a text editor of some kind to start PHP files, which are a mix of HTML and PHP. All kinds of text editors are available on numerous operating systems that can serve the purpose, such as vi, emacs, pico, Macintosh’s BBEdit or SimpleText, and Windows Notepad or WordPad. By default, PHP files are given the extension .php (as in myBigTimeWebPage.php).
The text you enter into our pages is just plain text, a mix of HTML and PHP. You can see an example in Figure 1-1; to start this PHP-enabled page, you just enter the text as it appears in the figure and save it as a file with the extension .php. As you can see, this example is mostly HTML; the PHP part is the script that appears between the <?php and the ?>. When you navigate to this document in your browser, the PHP-enabled server will read the document, find the PHP part between the <?php and the ?>, and do it involuntarily. In this case, our PHP is just the single line phpinfo();, which will show an HTML table full of information about the PHP installation on the server, as we’re about to see in “Making Your First PHP Script.”

Figure 1-1. Making a PHP page with HTML in it.

Windows WordPad has the annoying habit of appending the extension .txt to a filename if it doesn’t know the extension you’ve given the file. If you try to save a text document with the extension .php, WordPad will give it the extension .php.txt, which is very annoying. To avoid that, surround the name of the file with quotation marks when you save it, as in “logbook.php”. Also note that by default, WordPad saves files in rich text format (.rtf) or as Microsoft Word (.doc) files, depending on your version of Windows. To make sure you save your XML documents in plain text format, select the Text Document option in the Save as type drop-down list box in the Save As dialog.
In fact, you can even use a word processor such as Microsoft Word to start PHP documents if you save your documents in plain text format, not in some other format such as .doc (for example, in Microsoft Word, you’d select the Text Only option from the Save as type drop-down list box in the Save As dialog). It’s much better to stick with a plain text editor than a word processor, but, because except you’re careful, word processors will add all kinds of features and decorations that will get in the way.
You can also use a PHP integrated enhancement environment (IDE) to start your PHP pages. IDEs give you all kinds of tools that simple text editors don’t, such as checking what you’ve written involuntarily to make sure it’s valid PHP, automatic syntax highlighting (everywhere items such as PHP keywords grow in various colors, making it simple to pick out what’s vacant on at a glance), and automatic deployment, everywhere the IDE can upload your PHP pages to your ISP when you click a pin or select a menu item.
Here’s a starter list of IDEs available online that can handle PHP. Note, but, that most of them cost money, and although they have some nice features, we won’t rely on those features in this book:
- Komodo (www.activestate.com/Products/Komodo) runs on Linux and Windows.
- Maguma (www.maguma.com) runs on Windows only.
- PHPEdit (www.phpedit.com/products/PHPEdit) is free, but runs on Windows only.
- Zend Studio (www.zend.com/store/products/zend-studio.php) runs on Windows and Linux. This one is made by the same people who made the Zend software “engine” that really runs at the core of PHP itself.
If you’re working with an ISP, you’ll also need some way of transporting your PHP pages to the ISP, as you would with standard web pages. You can use a File Transfer Protocol (FTP) program or a web interface if one is provided by your ISP. If you haven’t uploaded web pages before, question your ISP support team what they recommend because they will often point you to an FTP program that they support or a web interface they’ve set up to allow people to upload web pages. You upload and run PHP pages just as you would standard HTML pages, as long as your server supports PHP.
Post Tags: Apache, Essential PHP, Install PHP Locally, Installing PHP, Komodo, Learn PHP, Maguma, Personal Homepage, Personal Web Server, PHP, PHP for Beginner, PHP for Newbie, PHPEdit, PWS, Zend Studio
Related Posts
- An Overview Of Coding With PHP
- Working with the X-debug extension`s var_dump() function
- Generating Web Pages in Multiple Languages with a PHP IP-to-Country Mapping Application
- Debugging Program Flow with the Xdebug Extension
- Using PHP to Create Relevant Title Tags in osCommerce Websites
- Handling Views with CodeIgniter
- Embedding Model Data in Views with Code Igniter
- Generating Contract Numbers for Online Licenses using PHP and MySQL
- Mixing PHP in Some HTML
- Using the Active Record Pattern with PHP and MySQL
Popular
- iPhone or iPod Touch, Which One Should You Choose? - 47,761 views
- Introduction to Facebook - 26,655 views
- 7 Top Twitter Topic Trackers - 16,375 views
- Introduction of Hacking Methodology - 15,051 views
- Google Hacking Keywords - 11,716 views
- LG BD390 Wi-Fi Blu-ray Player Review: So Packed You’ll Forget About Blu [Review] - 10,094 views
- Complete Guide to Web Site Marketing - 9,774 views
- BlackBerry Curve 3G: A Familiar, Powerful Phone - 9,774 views
- Microsoft’s Zune HD Wiill Have OLED, HD Radio - 9,300 views
- Photo Album and Printing Services - 8,953 views
Featured Articles
- The Elements of the Facebook Platform
- Introducing the Facebook Platform
- Social Skills Today Are Being Lost
- GibBook – Gibraltar Own Social Network Site
- 7 Deadly Twitter Sins
- Introduction to Facebook
- Google’s Wave: Many Online Apps in One Tool
- App Mapping War Casualties Debuts for Memorial Day Weekend
- Google@Omgili Mashes Traditional Web Search With Social Buzz
- Capital Factory: Austin-Based Incubator (RWS Interview)
Recent Posts
- Tweet via something
- Lightroom Review And Other Phot
- Several Words About The Advantages Of Tablet PCs
- Dissimilar Positive Features Of Table Computers
- Digi Link Doctor
- Why You Need Professional SEO Software
- Automated SEO Tools For Online Business
- How To Choose The Best Tablet PC
- Tablet PC – The Latest Computer Technology
- Tablet PCs Compared To Laptops