In these step-by-step activities, we are going to install and test PHP engine (parser), so that PHP files can be parsed. In this installation package, we will include the PHP extensions and in PHP and Windows 2003 Server, we will try to 'install' the PHP extension (PEAR/PECL) separately. We will also show how to install PEAR.
The machine specifications used in this task are:
1. Download PHP MSI installer for windows at PHP.net. At the current writing, the msi installation package version is 4.2.3. Launch the installation wizard by double clicking the msi file.
2. Click Next when greeted by the PHP installation wizard welcome page.
3. Accept the EULA and click Next.
4. Specify the PHP destination folder. Again, the issues to consider are the security of the PHP and the Windows system itself. Keep in mind that in the real production, the PHP page will be accessed by users through your web pages. The default destination folder given is not recommended for production. It is better to provide separate partition for PHP installation. If you want to change the installation folder, click Browse. We will change the installation folder to C:\. Click the Browse button.
5. Browse to C:\ and type PHP if needed. So the installation folder is C:\PHP\ Click OK.
6. Click Next.
7. Depending on the services that your web server will provide, you can select the web server type here. In our case we select Apache 2.2.x Module as shown in the following Figure. There is no CGI or ISAPI related services that will be hosted by our Apache server, previously installed. Click Next.
8. Setting the Apache configuration file (httpd.conf) directory. Click the Browse button and find the folder where httpd.conf file resides.
9. In this case it is C:\Apache Software Foundation\Apache2.2\conf. Adjust accordingly based on your Apache installation folder.
10. Click the OK.
11. The following Figure shows our Apache’s configuration file folder. Change accordingly if yours are different. Click Next.
12. The required file already selected for us such as the PHP’s program and Web Server Setup.
13. We will add the PHP extensions. We can select all the extensions and later we can enable the only needed extensions (modules) using the PHP configuration file.
14. Some extensions already obsolete or discontinue. Some need the client side DLL to be installed else the PHP engine will complain some files cannot be found later on (this things created a lot of 'bogus' bugs at PHP.net). So be careful, just install the needed extension because you can ‘re-install’ it later. These extensions come with their respective DLL files that will be copied to extensions/ folder for PHP 4 and ext/ folder for PHP 5 and need to enable them in PHP configuration file (php.ini) under the extension= directive for automatic loading. In our case we just select several PHP extensions related to MySQL database.
15. Click Next after you have finish selecting items to be installed.
16. Click Install if you have completed the needed PHP and \its item to be installed. You still can go back to the previous steps to change any PHP setup settings.
17. The PHP installation is in progress.
18. The PHP installation was successfully completed. ClickFinish.
19. You should see the PHP 5 on the Windows Start menu as shown below.
20. The PHP folders and files are shown below.
21. All the PHP extensions copied under the PHP/ext folder.
22. The PHP configuration file is php.ini and if you want to customize your PHP. Depending on your web services needs, you can edit this file. Please read the PHP documentation on this thing.
23. You can open php.ini using any text editor and the following Figure shows php.ini content.
24. The following are some of the php.ini sections.
; Allow ASP-style <% %> tags.
asp_tags = Off
; The number of significant digits displayed in floating point numbers.
precision = 14
zlib.output_compression = Off
;zlib.output_compression_level = -1
; Safe Mode
safe_mode = Off
; Colors for Syntax Highlighting mode. Anything that's acceptable in
; <span style="color: ???????"> would work.
;highlight.string = #DD0000
;highlight.comment = #FF9900
;highlight.keyword = #007700
;highlight.bg = #FFFFFF
;highlight.default = #0000BB
;highlight.html = #000000
max_execution_time = 30 ; Maximum execution time of each script, in seconds
max_input_time = 60 ; Maximum amount of time each script may spend parsing request data
;max_input_nesting_level = 64 ; Maximum input variable nesting level
memory_limit = 128M ; Maximum amount of memory a script may consume (128MB)
Error handling and logging
; - Show all errors, except for notices and coding standards warnings
error_reporting = E_ALL & ~E_NOTICE
; The separator used in PHP generated URLs to separate arguments.
; Default is "&".
;arg_separator.output = "&"
; Maximum size of POST data that PHP will accept.
post_max_size = 8M
; PHP's built-in default is text/html
default_mimetype = "text/html"
Paths and Directories
; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"
; Directory in which the loadable extensions (modules) reside.
; Whether to allow HTTP file uploads.
file_uploads = On
; Temporary directory for HTTP uploaded files (will use system default if not
; Maximum allowed size for uploaded files.
upload_max_filesize = 10M
; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
allow_url_fopen = On
; Whether to allow include/require to open URLs (like http:// or ftp://) as files.
allow_url_include = Off
; Define the anonymous ftp password (your email address)
; If you wish to have an extension loaded automatically, use the following
; Defines the default timezone used by the date functions
SMTP = localhost
smtp_port = 25
; Allow or prevent persistent links.
msql.allow_persistent = On
; Local Variables:
WARNING! Comment out or delete all directive under the ;Local Variables as shown in the highlighted section in the following Figure, else your PHP will complain many DLL cannot be found. We will enable the PHP extensions using the extension= under the Dynamic Extensions header. This happened when we include the PHP extensions during the installation process. We found that if we copy and paste the PHP extensions separately, this issue does not exist as can be seen in PHP installation on Windows 2003 Server. Our real example can be seen in PHP bogus bug?.
25. The following is the system variable for PHP. If you can’t see the PHP path, you can add it manually by clicking the Edit button. In this case we can run any PHP binaries at any relative Windows path.
26. The PHP path can also be verified through the Windows command prompt by issuing the path command.
27. By assuming the path already been set in the environment variables, we can test our PHP engine through the Windows command line. If the environment variable for PHP is not set, you need to run any php command at the PHP installation folder. For example if you install the PHP under the C:\>Program Files\PHP\ then you need to run the php binaries as shown below:
C:\>Program Files\PHP>php -h
28. Type the following PHP statement for help.
Usage: php [options] [-f] <file> [--] [args...]
php [options] -r <code> [--] [args...]
php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]
php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]
php [options] -- [args...]
php [options] -a
-a Run interactively
-c <path>|<file> Look for php.ini file in this directory
-n No php.ini file will be used
-d foo[=bar] Define INI entry foo with value 'bar'
-e Generate extended information for debugger/profiler
-f <file> Parse and execute <file>.
-h This help
-i PHP information
-l Syntax check only (lint)
-m Show compiled in modules
-r <code> Run PHP <code> without using script tags <?..?>
-B <begin_code> Run PHP <begin_code> before processing input lines
-R <code> Run PHP <code> for every input line
-F <file> Parse and execute <file> for every input line
-E <end_code> Run PHP <end_code> after processing all input lines
-H Hide any passed arguments from external tools.
-s Display colour syntax highlighted source.
-v Version number
-w Display source with stripped comments and whitespace.
-z <file> Load Zend extension <file>.
args... Arguments passed to script. Use -- args when first argument
starts with - or script is read from stdin
--ini Show configuration file names
--rf <name> Show information about function <name>.
--rc <name> Show information about class <name>.
--re <name> Show information about extension <name>.
--ri <name> Show configuration for extension <name>.
C:\>php –v for PHP version
C:\>php –ini showing the PHP configuration file path.
C:\>php –m showing the PHP modules
C:\>php –i showing all the PHP setting information similar to running the phpinfo() function.
C:\>php –r "php_function" is running the php function at command prompt.
29. In the following step we are going to test our PHP through our Apache web server setup previously. Our default web root document is shown in the following Figure, then our php file should be under this folder.
30. First of all, using a text editor type the following php code. This is a php function that extracts all the PHP information from the current machine.
<? php phpinfo(); ?>
31. Save this file with .php extension. In this case the filename is testphpengine.php.
32. This file then has been saved under the Apache’s htdocs folder.
33. The following is the html version if you want to try.
34. Next, open your browser and point to the testphpengine.php file (http://localhost/testphpengine.php or any php filename that you have used in the previous step). You will be greeted with the following web page, meaning that our PHP engine or parser is working properly. If the file name is index.php, you just need to point to the http://localhost. Your next steps to do are customizing the PHP to suit your needs by editing the PHP configuration file, php.ini and downloading and/or updating the PHP extensions.
35. If there is an empty web page displayed, restart Apache and/or clear your browser cache and/or cookies. Re-browse the page again.
36. At this stage our PHP engine should be working. Other related extensions will be activated/enabled when it is needed through php.ini.
PEAR is the PHP Extension and Application Repository that can be found at pear.php.net. PEAR contains useful software libraries and applications such as MDB2 (database abstraction), HTML_QuickForm (HTML forms management), PhpDocumentor (auto-documentation generator), DB_DataObject (Data Access Abstraction), and many more. All the available packages can be found at pear.php.net.
We use PEAR installer, which contains executable files and PHP code that is used to download and install PEAR code from pear.php.net.
1. After downloading the TGZ PEAR, unzip the file.
2. In the previous PHP installation, PEAR is included together in the Extras package.
3. For post PHP installation, you need to run the batch file, go-pear.bat shown below under the PHP folder.
4. Let run it. In the Command prompt console type go-pear.
5. The following is the complete steps when running go-pear.
Are you installing a system-wide PEAR or a local copy?
(system|local) [system] : local
Please confirm local copy by typing 'yes' : yes
Below is a suggested file layout for your new PEAR installation. To change individual locations, type the number in front of the directory. Type 'all' to change all of them or simply press Enter to accept these locations.
1. Installation base ($prefix) : C:\PHP
2. Temporary directory for processing : C:\PHP\tmp
3. Temporary directory for downloads : C:\PHP\tmp
4. Binaries directory : C:\PHP
5. PHP code directory ($php_dir) : C:\PHP\pear
6. Documentation directory : C:\PHP\pear\docs
7. Data directory : C:\PHP\pear\data
8. Tests directory : C:\PHP\pear\tests
9. Name of configuration file : C:\PHP\pear.ini
10. Path to CLI php.exe : C:\PHP\.
1-10, 'all' or Enter to continue:
Configuration written to C:\PHP\pear.ini...
Preparing to install...
pear/PEAR can optionally use package "pear/XML_RPC" (version >= 1.4.0)
install ok: channel://pear.php.net/Archive_Tar-1.3.2
install ok: channel://pear.php.net/Console_Getopt-1.2.2
install ok: channel://pear.php.net/Structures_Graph-1.0.2
install ok: channel://pear.php.net/PEAR-1.5.4
PEAR: Optional feature webinstaller available (PEAR's web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer)
PEAR: To install optional features use "pear install pear/PEAR#featurename"
WARNING! The include_path defined in the currently used php.ini does not
contain the PEAR PHP directory you just specified:
If the specified directory is also not in the include_path used by
your scripts, you will have problems getting any PEAR packages working.
Would you like to alter php.ini <C:\PHP\php.ini>? [Y/n] : Y
php.ini <C:\PHP\php.ini> include_path updated.
Current include path : .;C:\php5\pear
Configured directory : C:\PHP\pear
Currently used php.ini (guess) : C:\PHP\php.ini
Press Enter to continue:
** WARNING! Old version found at C:\PHP, please remove it or be sure to use the new c:\php\pear.bat command
The 'pear' command is now at your service at c:\php\pear.bat
Press any key to continue . . .
The following Figure shows the PEAR folders and files post installation.
6. The following are PEAR commands that you can use.
7. Let try the download-all command. You may want to try other command as well. Use Ctrl + C to stop the batch execution.
8. We also found the PECL binary available under the PHP folder. The following are PECL commands that you can use.
9. Let try the download-all command.
All failed lol!
For users who cannot perform the above steps, or who wish to obtain the latest PEAR with a slightly higher risk of failure, use go-pear. go-pear is obtained by downloading PEAR and saving it as go-pear.php. After downloading, simply run "php go-pear.php" or open it in a web browser (windows only) to download and install PEAR. To download PEAR package manually, go to PEAR download page
As stated by PHP.net, most of the PECL extension files come standard with the PHP 4 Windows binaries, but have been moved into this separate PECL download. PECL is a repository for PHP Extensions, providing a directory of all known extensions and hosting facilities for downloading and development of PHP extensions. The packaging and distribution system used by PECL is shared with its sister, PEAR (PHP Extension and Application Repository).
The PECL collection can be downloaded from PHP download page. Using PHP version 5.x.x, we found that the extension also included in the msi installation package under the Extensions folder shown below.
2. Copy all the files and paste it into the %PHP\ext folder. Let all the new files overwrite the all old one.