1.1. Why You Need Apache, MySQL, and PHP

PHP is a powerful scripting language that can be run by itself in the command line of any computer with PHP installed. However, PHP alone isn't enough in order to build dynamic web sites.

To use PHP on a web site, you need a server that can process PHP scripts. Apache is a free web server that, once installed on a computer, allows developers to test PHP scripts locally; this makes it an invaluable piece of your local development environment.

Additionally, dynamic websites are dependent on stored information that can be modified quickly and easily; this is the main difference between a dynamic site and a static HTML site. However, PHP doesn't provide a simple, efficient way to store data. This is where a relational database management system like MySQL comes into play. This book's examples rely on MySQL; I chose this database because PHP provides native support for it and the database is free, open-source project.

NOTE

An open-source project is available for free to end users and ships with the code required to create that software. Users are free to inspect, modify, and improve the code, albeit with certain conditions attached. The Open Source Initiative lists 10 key provisions that define open-source software; you can view this list at www.opensource.org/docs/osd.

1.1.1. Drilling Down on PHP

PHP is a general-purpose scripting language that was originally conceived by Rasmus Lerdorf in 1995. Lerdorf created it to satisfy the need for an easy way to process data when creating pages for the World Wide Web.

NOTE

PHP was born out of Rasmus Lerdorf's desire to create a script that would keep track of how many visits his online resume received. Due to the wild popularity of the script he created, Lerdorf continued developing the language. Over time other developers joined him in creating the software; today, PHP is one of the most popular scripting languages in use on the Internet.

PHP originally stood for "Personal Home Page" and was released as a free, open source project. Over time, the language was reworked to meet the needs of its users. In 1997, PHP was renamed to the current "PHP: Hypertext Preprocessor."

At the time I write this, PHP 5.2.9 is the latest stable release available, but versions 5.3 and 6 are both scheduled for release in the near future. PHP 4 is still in use on a number of servers, but support has been discontinued. Many hosting companies let developer use either PHP 4 or PHP 5 on their sites.

1.1.1.1. Stable/Production vs. Development Releases

Many software products will have a development release available, alongside the current, stable release. This is a way for the development community to test an upcoming version of a product; this helps the product's creators work bugs out of the system.

After a proposed release has been tested to a satisfactory level, its creators mark it as the current production release. Users reasonably expect the production software they use to be free of major defects or bugs; calling a version a stable/production release is a way for the product's creators to let potential users know that, in the opinion of the product's creators, all major issues have been worked out, and that it is safe to use this software for mission-critical applications.

1.1.1.2. How PHP Works

PHP is generally used as a server-side scripting language; it is especially well-suited for creating dynamic web pages. The scripting language features integrated support for interfacing with databases such as MySQL, which makes it a prime candidate for building all manner of web applications, from simple personal web sites to complex enterprise-level applications.

Unlike HTML, which is parsed by a browser when a page loads, PHP is preprocessed by the machine that serves the document (this machine is referred to as a server). All PHP code contained with the document is processed by the server before the document is sent to the visitor's browser.

PHP is a scripted language, which is another great advantage for PHP programmers. Many programming languages require that you compile files into machine code before they can be run, which is a time-consuming process. Bypassing the need to compile means you're able to edit and test code much more quickly.

Because PHP is a server-side language, running PHP scripts on your local machine requires installing a server on your local machine, as well. The examples in this book rely on the Apache web server to deliver your web pages.

1.1.1.3. Server-Side vs. Client-Side Scripting

The Internet features two main kinds of scripting: server-side and client-side. Client-side scripting is comprised mainly of JavaScript, which is responsible for many of the web features that you can actually see happening, such as pop-up windows, some animations, and other site features like drop-down menus. The reason this is called "client-side" scripting because the code is executed on the user's machine, after the page has been loaded.

Using client-side scripts enables you to make changes to a page without requiring a page refresh; it also facilitates initial form validation and simplifies making improvements to the user interface.

However, using client-side scripts requires that the users have JavaScript turned on or that their browsers support the script you have written. This means you should not use client-side scripts for user authentication or the handling of anything sensitive, due to the user's ability to modify and/or disable your client-side scripts.

Server-side scripting is performed on the site's hosting server before the page is delivered to the user. This means that any changes that must be made by the script require a page refresh.

Using server-side scripting is great for user authentication, saving changes to database information, retrieving entries for display, and many other tasks.

The downside of server-side scripts lies mainly in the required page refresh. Because the script is processed before it is delivered to the browser, the user doesn't have access to the inner workings of the code. This makes server-side scripts the best choice for handling any sensitive information.

Server-side scripting is better suited to handling sensitive information than client-side scripts, but you still must take care to protect sensitive data. We'll spend more time on basic security later in the book.


Serving web pages with Apache HTTP Server is the most popular web server on the web; it hosts nearly half of all web sites that exist today. Apache is an open-source project that runs on virtually all available operating systems.[] Apache server is a community-driven project, with many developers contributing to its progress. Apache's open-source roots also means that the software is available free of charge, which probably contributes heavily to Apache's overwhelming popularity relative to its competitors, including Microsoft's IIS and Google's GWS, among others.

[] Wikipedia, "Apache HTTP Server," http://en.wikipedia.org/wiki/Apache_(HTTP_server)

On the Apache web site (www.apache.org), Apache HTTP Server is described as "an effort to develop and maintain an open-source HTTP server for modern operating systems including UNIX and Windows NT. The goal of this project is to provide a secure, efficient, and extensible server that provides HTTP services in sync with the current HTTP standards."

1.1.1.4. What Apache Does

Like all web servers, Apache accepts an HTTP request and serves an HTTP response. The World Wide Web is founded on web servers, and every website you visit demonstrates the functionality of web servers.

I've already mentioned that, while HTML can be processed by a web browser, programming languages such as PHP need to be handled by a web server. Due to its overwhelming popularity, Apache is used for testing purposes throughout this book.

1.1.2. Store Info with MySQL

MySQL is a relational database management system (DBMS). Essentially, this means that MySQL allows users to store information in a table-based structure, using rows and columns to organize different pieces of data. This structure is similar to that of Microsoft's Access database.

The examples in this book rely on MySQL to store the information you'll use in your PHP scripts, from blog entries to administrator information; it is that approach that allows your site to be dynamic.

NOTE

Blog is short for weblog, which is an online journal for an individual or business.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.14.93