Apache, PHP and MySQL Installations On Windows XP

27
Apache, PHP and MySQL Installations On Windows XP By: Julian V. Jupiter June 09, 2009 1 Apache, PHP and MySQL Installations on Windows XP Created by: Julian V. Jupiter 6/13/2009

description

This tutorial will teach you to install Apache Web server, MySQL database and PHP. Apache is the famous web server nowadays. MySQL is the world's most popular open-sourced DBMS. PHP is the most popular scripting language on the web. PHP is a server-side language that it runs in the server not in web browser. Like Apache and MySQL, PHP is a freely distributed software. It is an alternative to other scripting language such as that of Sun’s JSP and Microsoft’s ASP framework. This tutorial gives you a step by step guide on how you can install and configure PHP to work together with the Apache HTTP Server and MySQL database on Windows XP.

Transcript of Apache, PHP and MySQL Installations On Windows XP

Page 1: Apache, PHP and MySQL Installations On Windows XP

Apache, PHP and MySQL Installations

On Windows XP

By: Julian V. Jupiter

June 09, 2009

1 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 2: Apache, PHP and MySQL Installations On Windows XP

Apache Installation

1. Double-click the installer.

- apache_2.2.9-win32-x86-no_ssl-r2

2. Installer opens. Click Next.

3. Accept the terms in the license agreement

2 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 3: Apache, PHP and MySQL Installations On Windows XP

4. Click Next.

5. Type in “localhost” for Network Domain and Server Name. Type in also the Administrator’s Email Address. If port 80 is not yet used, click Next.

6. Select Typical. Click Next.

3 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 4: Apache, PHP and MySQL Installations On Windows XP

7. Click Next.

8. Wait while Apache is being installed.

9. Click Finish.

4 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 5: Apache, PHP and MySQL Installations On Windows XP

10. Apache is now included to All Programs menu.

11. To test if Apache is installed properly, type in http://localhost to your web browser. Browser must open like the following:

5 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 6: Apache, PHP and MySQL Installations On Windows XP

12. Instead of localhost or if localhost does not work, you can also use the default/local IP address of the computer, 127.0.0.1.

13. You can also use the name of your computer. My PC has its name “juju”.

6 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 7: Apache, PHP and MySQL Installations On Windows XP

To know your PC’s name open My Computer’s Properties and click Computer Name tab.

14. If you want a trick when opening your pages as if it is online, e.g. www.google.com, open “hosts” file with a text editor from C:\WINDOWS\system32\drivers\etc. Change localhost with the desired name. I used www.juju.com. You can customize/edit the file index.html to desired page.

7 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 8: Apache, PHP and MySQL Installations On Windows XP

15. Default web documents folder is C:\Program Files\Apache Software Foundation\Apache2.2\htdocs. You will place all your documents here.

16. Configuration can be found at C:\Program Files\Apache Software Foundation\Apache2.2\conf. You can easily open it from Apache folder in All Programs menu. This is needed to edit for loading PHP module or other modules.

8 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 9: Apache, PHP and MySQL Installations On Windows XP

17. Starting, restarting and stopping the server when needed.

18. Other way to start, restart or stop the server is to click the Apache Service Monitor on Windows tray.

Congratulations!!!

9 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 10: Apache, PHP and MySQL Installations On Windows XP

PHP Installation and Configuration for Apache

1. Extract the PHP zip and copy to C:\ directory.

- php-5.2.6-Win32.zip

2. Rename the folder to php thus C:\php.

3. C:\php contains the following:

- C:\php\dev

- C:\php\ext

- C:\php\extras

- C:\php\PEAR

- C:\php\php.exe

- C:\php\php-cgi.exe

- C:\php\php-win.exe

- C:\php\ fdftk.dll

- C:\php\ gds32.dll

- C:\php\ php5apache2_2.dll

- C:\php\ php5ts.dll

- …, etc.

4. Look for the file php.ini-recommended. Rename the file to php.ini.

10 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 11: Apache, PHP and MySQL Installations On Windows XP

5. Open php.ini with your favorite text editor, e.g. Notepad.

6. Look for display_errors = Off on line 372. With this directive set to off, errors that occur during the execution of scripts will no longer be displayed as a part of the script output, and thus, will no longer be exposed to remote users. With some errors, the error message content may expose information about your script, web server, or database server that may be exploitable for hacking. Production sites should have this directive set to off.

For development purposes, this directive should be set to On, thus make it display_errors = On.

11 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 12: Apache, PHP and MySQL Installations On Windows XP

7. Open httpd.conf.txt on C:\Program Files\Apache Software Foundation\Apache2.2\conf, or to easily open this file click Start>All Programs> Apache HTTP Server 2.2> Configure Apache Server and click Edit the Apache httpd.conf Configuration File.

8. Add PHP module to last line of list of modules on Apache configuration file. PHP module can be found on the top level of PHP directory. Since the Apache version is 2.2.x or 2.2.9, we used php5apache2_2.dll module.

- Add LoadModule php5_module “C:/php/php5apache2_2.dll”. Take note: use “/” not “\”.

9. Look for the line DirectoryIndex index.html which can be found on <IfModule dir_module> section.

12 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 13: Apache, PHP and MySQL Installations On Windows XP

Change it to DirectoryIndex index.php index.html. Apache will serve the file index.php (or the index.html if the former is not present) if a directory is requested.

10. Look for the following lines under <IfModule mime_module> section:

- AddType application/x-compress .Z

- AddType application/x-gzip .gz .tgz

Add AddType application/x-httpd-php .php to the next line.

11. At the last line add PHPIniDir <php.ini directory> in order for the Apache to know the php.ini configuration. Save the file.

13 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 14: Apache, PHP and MySQL Installations On Windows XP

12. Restart the Apache HTTP Server. Every time you make any changes to php.ini or httpd.conf you have to restart the server. Command-line prompts and fades away immediately if there is no mistake on configurations. It shows messages if there is any wrong in configuration.

13. To test if Apache and PHP work together, make a file with the following codes on your text editor and save with the desired name and with .php extension. In my case I use phpinfo.php.

<?php

phpinfo();

?>

Save this file to the top level of your document directory htdocs or you may create a folder to place it. Open your favorite web browser and open http://localhost/phpinfo.php. You can change localhost as discussed in Apache Installation. It should open the following:

Congratulations!!!

14 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 15: Apache, PHP and MySQL Installations On Windows XP

MySQL Installation and Configuration for PHP

1. Double-click the installer.

- mysql-essential-5.0.67-win32

2. Installer opens. Click Next.

3. Choose Setup Type. You can choose Typical for general use, Complete if all program featuresbe installed or Custom for advanced users. In my case I chose Complete.

15 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 16: Apache, PHP and MySQL Installations On Windows XP

4. Click Install.

5. Wait while MySQL is being installed.

16 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 17: Apache, PHP and MySQL Installations On Windows XP

6. Click Next.

7. Click Next.

17 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 18: Apache, PHP and MySQL Installations On Windows XP

8. Leave Configure… remain check. Click Finish

Note: If you uncheck Configure and want to open it later for instance configuration… go to Start>All programs>MySQL>MySQL Server 5.0> and click MySQL Server Instance Config Wizard.

18 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 19: Apache, PHP and MySQL Installations On Windows XP

9. Instance configuration opens. Click Next.

10. Select Standard Configuration. Click Next.

19 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 20: Apache, PHP and MySQL Installations On Windows XP

11. Check Install As Windows Service and choose Service Name. Check also Include Bin Directory… to open MySQL whatever directory your are in the Command Prompt. Click Next.

12. Enter password for the default user account, root. You can add more user accounts through this user account. Do not check Create An … Click Next.

20 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 21: Apache, PHP and MySQL Installations On Windows XP

13. Click Execute.

14. Wait while processing configuration then click Finish.

21 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 22: Apache, PHP and MySQL Installations On Windows XP

15. To start working with MySQL click MySQL Command Client.

16. The following opens:

22 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 23: Apache, PHP and MySQL Installations On Windows XP

Enter your password and press Enter:

You may also open MySQL Command client by executing the command mysql –u <username> -h <host> -p on Command Prompt.

23 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 24: Apache, PHP and MySQL Installations On Windows XP

You can now execute SQL commands for creating databases, tables, etc. SQL commands are beyond the scope of this tutorial.

To view databases, type in SHOW DATABASES (either case):

To exit MySQL shell, simply type in exit:

24 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 25: Apache, PHP and MySQL Installations On Windows XP

17. After MySQL has been installed, you need to configure PHP in order to have them connected. Take note that MySQL is not required for Apache to run PHP scripts unless you use MySQL databases in your scripts.

- There are two ways in order to connect MySQL and PHP (I prefer to use second approach):

1. Copy mysql.dll and/or mysqli.dll from C:\php\ext to the top level of PHP installation, C:\php. Open php.ini and look for php_mysql and php_mysqli under the list of extensions.

Uncomment these lines:

Save the file and restart the Apache server.

2. Open php.ini and look for extension_dir = “./”.

Change this line to extension_dir = “<extension directory>” where extension directory is the directory for extensions to be loaded such as mysql.dll and/or mysqli.dll. The directory is C:\php\ext.

25 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 26: Apache, PHP and MySQL Installations On Windows XP

Look for php_mysql and php_mysqli under the list of extensions.

Uncomment these lines:

Save the file and restart the Apache server.

18. To know if PHP is now working with PHP, open again your file which contains the follwing code to your web browser.

<?php

phpinfo();

?>

Click refresh to your browser. Look for mysql and/or mysqli. If you see them then everything is fine. Take note: Mostly you have to restart your computer before you can see them on phpinfo() function.

26 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009

Page 27: Apache, PHP and MySQL Installations On Windows XP

Congatulations!!! Now that you have already installed PHP, you may now take the advantage of PHP programming.

27 Apache, PHP and MySQL Installations on Windows XP

Created by: Julian V. Jupiter 6/13/2009