1、1 中文 3670 字 外文原文 Setting Up the PHP Development Environment Getting a working development environment put together can be intimidating, especially for the absolute beginner. To follow along with the project in this book, youll need to have access to a working installation of Apache, PHP, and MySQL,
2、preferably on your local machine. Its always desirable to test locally, both for speed and security. Doing this both shelters your work-in-progress from the open Internet and decreases the amount of time spent uploading files to an FTP server and waiting for pages to reload. Why You Need Apache, MyS
3、QL, 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 isnt 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
4、 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
5、 a dynamic site and a static HTML site. However, PHP doesnt provide a simple, efficient way to store data. This is where a relational database management system like MySQL comes into play. This books examples rely on MySQL; I chose this database because PHP provides native support for it and the dat
6、abase is free, open-source project. It runs in both 32-bit and 64-bit environments, but on Windows the only official distribution is 32-bit, requiring Windows 32-bit compatibility mode to be enabled while using IIS in a 64-bit Windows environment. There is a third-party distribution available for 64
7、-bit Windows. PHP is a general-purpose scripting language that is especially suited for web development. PHP generally runs on a web server, taking PHP code as its input and creating web pages as output. It can also be used for command-line scripting and client-side GUI applications. PHP can be depl
8、oyed on most web servers, many operating systems and platforms, and can be used with many relational database management systems. It is available free of charge, and the PHP Group provides the complete source code for users to build, 2 customize and extend for their own use. PHP primarily acts as a
9、filter, taking input from a file or stream containing text and/or PHP instructions and outputs another stream of data; most commonly the output will be HTML. It can automatically detect the language of the user. From PHP 4, the PHP parser compiles input to produce byte code for processing by the Zen
10、d Engine, giving improved performance over its interpreter predecessor 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
11、. Many hosting companies let developer use either PHP 4 or PHP 5 on their sites. PHP Origin PHP originally stood for “Personal Home Page” and was released as a free, open source project. It began in 1994 as a set of Common Gateway Interface binaries written in the C programming language by the Danis
12、h/Greenlandic programmer Rasmus Lerdorf. Lerdorf initially created these Personal Home Page Tools to replace a small set of Perl scripts he had been using to maintain his personal homepage. The tools were used to perform tasks such as displaying his rsum and recording how much traffic his page was r
13、eceiving. He combined these binaries with his Form Interpreter to create PHP/FI, which had more functionality. PHP/FI included a larger implementation for the C programming language and could communicate with databases, enabling the building of simple, dynamic web applications. Lerdorf released PHP
14、publicly on June 8, 1995 to accelerate bug location and improve the code. This release was named PHP version 2 and already had the basic functionality that PHP has today. This included Perl-like variables, form handling, and the ability to embed HTML. The syntax was similar to Perl but was more limi
15、ted, simpler, and less consistent. Zeev Suraski and Andi Gutmans, two Israeli developers at the Technion IIT, rewrote the parser in 1997 and formed the base of PHP 3, changing the languages name to the recursive initialism PHP:Hypertext Preprocessor. The development team officially released PHP/FI 2
16、 in November 1997 after months of beta testing. Afterwards, public testing of PHP 3 began, and the official launch came in June 1998. Suraski and Gutmans then started a new rewrite of PHPs core, producing the Zend Engine in 1999. They also founded Zend Technologies in Ramat Gan, Israel. On May 22, 2
17、000, PHP 4, powered by the Zend Engine 1.0, was released. On July 13, 2004, PHP 5 was released, powered by the new Zend Engine II. PHP 5 included new features such as improved support for object-oriented programming, the PHP Data Objects extension (which defines a lightweight and consistent interfac
18、e for accessing databases), and numerous performance enhancements. The most recent update released by 3 The PHP Group is for the older PHP version 4 code branch. As of August, 2008 this branch is up to version 4.4.9. PHP 4 is no longer under development nor will any security updates be released. In
19、2008, PHP 5 became the only stable version under development. Late static binding has been missing from PHP and will be added in version 5.3. PHP 6 is under development alongside PHP 5. Major changes include the removal of register_globals, magic quotes, and safe mode. The reason for the removals wa
20、s because register_globals had given way to security holes, and magic quotes had an unpredictable nature, and was best avoided. Instead, to escape characters, magic quotes may be substituted with the addslashes() function, or more appropriately an escape mechanism specific to the database vendor its
21、elf like mysql_real_escape_string() for MySQL. 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
22、 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
23、 code contained with the document is processed by the server before the document is sent to the visitors 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, whic
24、h is a time-consuming process. Bypassing the need to compile means youre 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 A
25、pache web server to deliver your web pages. 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.1 Apache server is a commun
26、ity-driven project, with many developers contributing to its progress. Apaches open-source roots also means that the software is available free of charge, which probably contributes heavily to Apaches overwhelming popularity relative to its competitors, including Microsofts IIS and Googles GWS, among others. 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