• Microsoft Windows XP or Windows 2000 (I have not tested on Windows 98).
• Apache 2.0.x (I use Apache 2.0.50). You can download the latest Apache 2.0.50 version for Win32 at http://httpd.apache.org/ .
• PHP 5.0 (I will install PHP 5 as an Apache module, in the way that people install PHP for servers). Download the official PHP 5.0 version at http://www.php.net/download or the development version at http://snaps.php.net .
• MySQL 4.0 latest version can be downloaded from http://dev.mysql.com/get/Downloads/MySQL-4.0/mysql-4.0.20d-win.zip/from/pick#mirrors .
INSTALL APACHE 2.0
Apache 2.0.x has an automated installer and you won't have much trouble installing this web server software on Windows. For example, to install Apache 2.0.50, simply download a file named apache_2.0.50-win32-x86-no_ssl.msi and run it. By default it is installed on c: Program FilesApache GroupApache2. However, to facilitate server management and associated modules, I install it on c: webserverApache2. You can refer to the visual guide article at http://www.opensourcevn.org/javavietnam .
After installation is complete, temporarily turn off Apache. However, you may not need to do this until you modify the Apache configuration file below.
INSTALL PHP 5.0
Currently PHP 5 does not have an automatic installer. You download from PHP.net file php-5.0.0-Win32.zip with a capacity of about 7.6 MB. Unzip this file into the directory you choose. For ease of management, I unzip to c: webserverphp5.
After decompressing, you will see PHP 5 has a different directory structure than PHP 4. The reason is that PHP has been rewritten almost entirely for improved performance and speed. However, you do not need to worry, all you need to do after extracting is to find the file php.ini-recommended and perform the following steps:
- Copy it to the Apache folder mentioned above and rename it to php.ini (c: webserverApache2php.ini).
- Use a pure text editor like NotePad or EditPlus to open this file.
- Find the line
extension_dir = '. /'
and replace it with
extension_dir = 'c: webserverphp5ext'
- Find the line
; extension = php_mysql.dll
and remove the ';' at the beginning of the line (applies when you need to use PHP functions that handle data contained in MySQL).
Since the release of PHP 5.0 Beta for the first time, developers have reported that it is set by default not to work with MySQL because the PHP 5.0 installer already contains SQLite, an embedded database administration system. , runs extremely fast, has enough features to use for small businesses. In addition, the main reason is the GPL license issue. However, if you need a more advanced database management system like MySQL, PHP 5 allows you to reconfigure to be ready to work. If you do not pay attention to this, you may encounter the following error:
Fatal error: call to undefined function mysql_connect () prints c: webserverwebroottexttextpatternlibtxplib_db.
phpon line 15
- Also in this php.ini file, you find the line
; session.save_path
and adjust it to
session.save_path = 'c: webserverphp5tmp'
(depending on the directory you installed PHP5).
- Next, go to the [mail function] line, below the line you will see the line
; sendmail_from
Please uncheck the ';' at the beginning of the line and change your email address to your liking.
Example: localhost@phpvietnam.net
This configuration will be used until you program with the mail () function in PHP to send and receive mail with a built-in email server like QK Server.
- Go to the sub subdirectory in the PHP 5 directory (wallet
For example, c: webserverphp5ext) and check if there is a php_mysql.dll file there. This is the library for PHP 5 to handle data handling calls with MySQL. If you download PHP 5.0 officially, this file is definitely there. But if you use PHP 5.0 versions that are being developed and exported as snapshots (http://snaps.php.net), this file may be removed. If so, find it in the unzipped folder and copy it to the ext subdirectory.
- Copy libmysql.dll file in PHP 5 directory into c: Windowssystem32 folder or bin directory of Apache 2 (for example, c: webserverApache2bin). If you don't do this step, you might get an error 'can't load c: webserverphp5extphp_mysql.dll'.
- Next, go to the Apache conf subdirectory and find the httpd.conf file. If Apache 2.0.x is installed by default, its path is c: Program FilesApache GroupApache2confhttpd.conf. In my case, it is located at c: webserverApache2confhttpd.conf. Open this file with a plain text editor and navigate to the line
#LoadModule ssl_module modules / mod_ssl.so
You add the following two lines below this line:
LoadModule php5_module 'c: /webserver/php5/php5apache2.dll'
AddType application / x-httpd-php .php
The LoadModule line will allow Apache to load the library module called PHP 5 to perform processing tasks related to php files. You need to pay attention to change the path of php5apache2.dll depending on your case.
Now it is time to restart Apache 2. If there are no errors, the system tray appears as shown in Figure 1.
INSTALL MYSQL 4.0
So you have configured PHP 5.0 and Apache 2.0 to run them together. You have also configured PHP 5.0 functions to query MySQL 4.0. However, you need to install MySQL 4.0 to have enough PHP 5 programming tools. Installing MySQL 4.0.20 is quite simple. Just download a .zip file. Unzip and run the setup.exe file. MySQL software will automatically install to the default directory c: mysql. Then go to the folder c: mysqlbin to run the file winmysqladmin.exe. When you run this program, you will see a window as shown in Figure 2.
This window allows you to provide the name / password of the person with full admin rights to the MySQL Server. Usually this name / password pair is root / localhost or you can leave it blank by default. After the import is complete and press the OK button, this window disappears and in the system tray will appear the service icon of MySQL Server as shown in Figure 3.
As such, you already have the MySQL Server running on your computer and ready to handle queries.
CHECK THE INSTALLATION RESULTS
To re-check the installation work, follow these two steps:
• Go to Apache 2htdocs web root directory, and use a pure text editor like Notepad to create a file called phpinfo.php with the content:
• Open the browser and type in the address http:///localhost/phpinfo.php. You should see the full configuration of PHP 5. Turn on the Apache Service Monitor program window and you will see something like Figure 4.
Now you can program with PHP 5. Wish you success.
Pham Cong Dinh
PHPVietnam
pcdinh@yahoo.com Reference:
- Changes in PHP 5: http://www.php.net/ChangeLog-5.php
- Wiley PHP5 and MySQL Bible books in 2004.
- PHP and MySQL books for Dummies 2nd Edition 2004 by Wiley Publishing
Repeater (Iterator)
Repeaters are a completely new feature in PHP 5.0. They allow you to use a for-each loop to loop through different data types: directory lists, database result sets, and XML documents. SPL - Standard PHP Library - is a set of repeaters that provides this functionality along with filtering, limiting, caching and changing of repeater results.
Repeaters are a great way to manually remove all the interfering code in your source code.
For example , the DirectoryIterator repeater transforms iterations through directories from writing:
$ dir = opendir ($ path);
while (false! == ($ file = readdir ($ dir))) {
print '$ filen';
}
closedir ($ dir);
into writing:
foreach (new DirectoryIterator ($ path) as $ file) {
print '$ filen';
}
So there is no reference directory pointer lying in a mess, as well as there is no lack of comparison conditions in the need to check inside the loop.
In addition to the above highlights, PHP 5.0 also provides:
• Improving lines (streams), wrappers and filters.
The line is the concept given in PHP 4.3, but before PHP 5.0 it was the least used part. Improvements included in PHP 5.0 Beta 3 allow the file interface to be read and written to data by using protocol-dependent objects, which are often referred to as wrappers. The line also allows changing the flow of data through them by attaching filters.
• Endoscopic code using the Reflection layer.
This set of classes allows you to test classes, methods, parameters, and other things to explore object properties. With them, you can easily create class probes, PHP debuggers and other tools based on collecting object and function details.
• Generate standard HTML code thanks to Tidy.
The Tidy extension module makes it easy to understand the validity of HTML and XHTML generation. Its smart parser even turns the most arbitrary code-writing pages into pages that strictly adhere to the latest W3C specifications.
• Superior command line processing
The PHP5 command line version now allows processing individual lines, like Perl and awk.You can specify the code to run at the beginning, middle, and end of each line in a file.ÿ