|Article Time Stamp: 06 January 2010, 18:08:50 GMT+7|
Learn to install Apache, MySQL, PHP, phpMyAdmin, Zend Optimizer and MySQL Tools on Windows XP (Install PHP)
In the last few articles we’ve gotten our basic server applications installed and running. This will give us a great foundation to continue with the next few applications. The next thing we’ll need to get installed is PHP, as this will be the language we’re going to use to develop with, and we can’t use PHP without having a PHP engine phrasing all our code.
We didn't use the PHP installer because it isn't the preferred method for installing PHP and it's not secure. So we prefer manually install the PHP.
1. First, we want to create PHP folder under our server directory, so we must create c:\server\PHP folder
2. Open the PHP Zip file we downloaded at the beginning of this project and extract all the files at c:\server\PHP. If you use Winzip, make sure you check "Use Folder Names" option
3. After you've extracted the files, you'll see these directory structure at PHP folder:
+--ext -- extension DLLs for PHP
| +--mibs -- support files for SNMP
| +--openssl -- support files for Openssl
| +--pdf-related -- support files for PDF
+--pear -- initial copy of PEAR
|-go-pear.bat -- PEAR setup script
|-php-cgi.exe -- CGI executable
|-php-win.exe -- executes scripts without an opened command prompt
|-php.exe -- CLI executable - ONLY for command line scripting
|-php.ini-dist -- default php.ini settings
|-php.ini-recommended -- recommended php.ini settings
|-php5ts.dll -- core PHP DLL
4. After that, we need to create 2 new folder, and we can name it uploadtemp (it's for temporary directory for HTTP uploaded files) and sessiondata (it's for storing all the session files). So, it will be c:\server\PHP\uploadtemp and c:\server\PHP\sessiondata
5. The next step is to set up a valid configuration file for PHP, php.ini. There are two ini files distributed in the zip file, for PHP 5.1.4 and PHP 5.2.10 there are php.ini-dist and php.ini-recommended. For PHP 5.3.0 there are php.ini-development and php.ini-production. We advise you to use php.ini-recommended (or php.ini-production), because it has been optimized the default settings in this file for performance and security. So copy php.ini-recommended (or php.ini-production) and put it in the same folder (c:\server\PHP) with the name php.ini
6. We still need some customization at PHP configuration, so open php.ini with your favorite text editor, such as notepad. Find these strings and change the values according to these:
- variables_order = EGPCS => The environment variables are hashed into the $_ENV. But for better performance and because ENV is not as commonly used as the others, ENV is not recommended on productions servers. So, you can use GPCS instead
- register_long_arrays = Off => Enables registration of the older (and deprecated) long predefined array variables ($HTTP_*_VARS). You may want to set it off for performance, since they are deprecated.
- register_argc_argv = Off => Enables registration of the $argv and $argc variables. These arrays are extremely useful when running scripts from the command line. When this directive is enabled, registering these variables consumes CPU cycles and memory each time a script is executed. For performance reasons, this feature should be disabled on production servers.
- magic_quotes_gpc = Off => Because of character encoding issues and non-standard SQL implementations across many databases, it's not currently possible for this feature to be 100% accurate. We strongly recommend you use the escaping mechanisms designed specifically for the database your using instead of relying on this feature. Also note, this feature has been deprecated as of PHP 5.3.0 and is scheduled for removal in PHP 6.
- upload_tmp_dir = c:\server\PHP\uploadtemp => after you've change the values, make sure you've delete the comment character (;) at the beginning of the syntax, to make it active
- session.save_path= "c:\server\PHP\sessiondata" => after you've change the values, make sure you've delete the comment character (;) at the beginning of the syntax, to make it active. If there's more than one of these syntax, just use one and uncommented it
- extension_dir = "c:\server\PHP\ext"
- short_open_tag = Off => Allow the <? tag. With the wide spread use of XML and use of these tags by other languages, the server can become easily confused and end up parsing the wrong code in the wrong context. We recommend you don't use them
- max_execution_time = 120 => Maximum execution time of each script, in seconds
- display_errors = Off   => You would like to turn this on in development server, but would be better to turn this off on production server. If you set log_errors = on and you didn't specified the file for error_log file, you can see the error at Apache error log file
You can change all of the above configuration if you need to do so, but you must understand what you're about to do. And keep in mind, after you've changed anything within php.ini, you must restart your Apache web server to activate the changes.
7. We must tell PHP to locate the php.ini at c:\server\PHP by doing these (NOTES: For PHP 5.2.10 or PHP 5.3.0 you don't need to do this step):
- Go to Control Panel and open the System icon (Start -> Control Panel -> System)
- Go to the Advanced tab
- Click on the 'Environment Variables' button
- Look into the 'System variables' panel
- Click on 'New' and enter 'PHPRC' as the variable name and the directory where php.ini is located as the variable value (c:\server\PHP)
- Press OK and restart your computer
8. After we've finished configuring the PHP, we must configure the Apache webserver to work with PHP files. There is 2 way, by installing as a CGI binary or installing as an Apache module. Installing as a CGI binary will make our server is open to several possible attacks. So we'd prefer installing as an Apache module
9. Open Apache configuration file, just like this:
10. Add these lines at the very bottom:
LoadModule php5_module "c:/server/PHP/php5apache2.dll"
AddType application/x-httpd-php .php .htm .html
If you have PHP version 5.2.x or later, you can use this line instead the above syntax (Thanks to Monique Pengel):
LoadModule php5_module "c:/server/PHP/php5apache2_2.dll"
AddType application/x-httpd-php .php .htm .html
The first line will let Apache know the installation of PHP and the next two will let Apache know how to handle PHP files (sometimes, in html file, we can put PHP scripts on it, so we must also configure PHP to handle .htm and .html file).
11. Restart the Apache server. If the Apache server can't started, then do:
- open command prompt (Start -> Run -> Type "cmd", click OK)
- Type "cd c:\server\Apache2.2\bin" and then press Enter button
- Type "httpd -t" to see if there's an error on our Apache configuration
- If the error said "httpd: Syntax error on line 486 of C:/server/Apache2.2/conf/httpd.conf: Cannot load C:/server/PHP/php5apache2.dll into server: The specified module could not be found", you can continue on the next steps (the line number can be different, though). Otherwise, you must check your Apache configuration again by examine the error logs
12. By looking at the error messages, it seems that there's something missing at the php5apache2.dll module. After searching on the net, i have found a solution (Thanks to Steffen, http://www.apachelounge.com webmaster). Just download these file:
- http://www.apachelounge.com/download/mods/php5apache2.dll-php5.1.x.zip or at my backup server at http://other.monx007.com/tools/php5apache2.dll-php5.1.x.zip (it's 05/05/2006 version). You must check the file at http://www.apachelounge.com first for the newest version
- if you haven't installed the .NET framework, then you must also download http://download.microsoft.com/download/d/3/4/d342efa6-3266-4157-a2ec-5174867be706/vcredist_x86.exe or you can find the link from http://www.microsoft.com/downloads/details.aspx?familyid=32BC1BEE-A3F9-4C13-9C99-220B62A191EE&displaylang=en
13. After that, just read the instruction file (Readme.txt), or, i can describe it here anyway:
- Copy php5apache2.dll to c:\server\PHP
- Copy httpd.exe.manifest to c:\server\Apache2.2\bin
- If you haven't installed the .NET framework, then run vcredist_x86.exe that we've downloaded before (Click Yes to Accept the agreement).
14. Try to start the apache again. If it can't started, check the Apache configuration file just like steps 11.
15. If the Apache start successfully, we must test to see if PHP is installed correctly
16. We’ll want to create a file in the htdocs folder located in the main folder of Apache. This is where all of our web documents are going to be stored. Create a new file in this folder can name it phpinfo.php. Be sure that it saves with a .php extension and not .php.txt or whatever you’ll use to create the file. Once the phpinfo.php file has been created, open it up and place the following code within it.
<?php phpinfo(); ?>
Save it, close the file and then open your favorite browser and type this in the location bar.
17. If you see the following page (like below image), then PHP is installed and setup correctly on your server.
Last but not least, you may want to look at PHP Syntax Error And Solutions for any warnings / errors that you may find.
|<< Install MySQL||Install phpMyAdmin >>|