<$BlogRSDUrl$>
Techno Hack
All about technology tips and trick around us, such as how to optimize our PC, camera, handphone, camcorder and much more

Learn to install Apache 2, MySQL 5, PHP 5, phpMyAdmin 2 and Zend Optimizer 3 on Windows XP (Install PHP)

Monday, July 03, 2006
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:

c:\server\PHP
|
+--dev
|   |
|   |-php5ts.lib
|
+--ext -- extension DLLs for PHP
|   |
|   |-php_bz2.dll
|   |
|   |-php_cpdf.dll
|   |
|   |-..
|
+--extras
|   |
|   +--mibs -- support files for SNMP
|   |
|   +--openssl -- support files for Openssl
|   |
|   +--pdf-related -- support files for PDF
|   |
|   |-mime.magic
|
+--pear -- initial copy of PEAR
|
|
|-go-pear.bat -- PEAR setup script
|
|-fdftk.dll
|
|-..
|
|-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
|
|-php5activescript.dll
|
|-php5apache.dll
|
|-php5apache2.dll
|
|-..
|
|-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, php.ini-dist and php.ini-recommended. We advise you to use php.ini-recommended, because it has been optimized the default settings in this file for performance and security. So copy php.ini-recommended 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
- register_long_arrays = On    => Enables registration of the older (and deprecated) long predefined array variables ($HTTP_*_VARS)
- register_argc_argv = On      => Enables registration of the $argv and $argc variables
- magic_quotes_gpc = On
- 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"

You can change all of the above configuration if you need to do so, but you must understand what you're about to do

7. We must tell PHP to locate the php.ini at c:\server\PHP by doing these:
  - 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
PHPIniDir "c:/server/PHP"


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 cann'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 cann'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 inpo.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.

http://localhost/inpo.php

17. If you see the following page (like below image), then PHP is installed and setup correctly on your server.




 << Install MySQL   Install phpMyAdmin >> 

INDEX SHORTCUT