Step by step installation & configuration of Apache-PHP-MySQL-Perl-phpMyAdmin

* The Tutorial is written for Windows environment

** Root directory for Windows XP SP2 is assumed E:\WINDOWS throughout the tutorial

*** If you encounter any kind of question during installation processes that is not mentioned here, that means "do whatever you want!"

Files used:

Apache Web Server and PHP

  1. Install Apache Server with typical choice
  2. Extract php-4.3.10-Win32.zip to the root directory to folder called "php" (i.e. E:\php)
  3. Copy E:\php\php4ts.dll file into E:\WINDOWS\system32\ directory
  4. Edit E:\Program Files\Apache Group\Apache2\conf\httpd.conf
  5. Edit E:\php\install.txt to find following two lines:
    LoadModule php4_module "c:/php/sapi/php4apache2.dll"
    AddType application/x-httpd-php .php
  6. Copy/paste the first line at the end of LoadModule section of httpd.conf without double quotes and change "c:" to "e:"
  7. Copy/paste the second line (at step 5) after the following lines in http.conf:
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
  8. Save changes and close these two files
  9. Copy E:\php\php.ini-dist file into your windows directory and rename it as php.ini
  10. Locate "extension_dir" string in that file and change it as:
    extension_dir = e:\php\extensions
  11. Save and close php.ini file
  12. Restart the Apache Server:
    cd "E:\Program Files\Apache Group\Apache2\bin"
    E:\Program Files\Apache Group\Apache2\bin>apache -k restart
  13. Your .php files must be in the E:\Program Files\Apache Group\Apache2\htdocs\ directory. To test your configuration create a file called index.php. Write following lines in it:
    <?
    phpinfo();
    ?>
  14. Save this file into the directory mentioned in 13th step
  15. Open a browser window
  16. Type the address (in your browser window) as the following:
    localhost\index.php
  17. See the PHP info table and enjoy!

Important Bug Information

; PHP 4.2 and less have an undocumented feature/bug that allows you to
; to initialize a session variable in the global scope, albeit register_globals
; is disabled. PHP 4.3 and later will warn you, if this feature is used.
; You can disable the feature and the warning separately. At this time,
; the warning is only displayed, if bug_compat_42 is enabled.

**** You will need to restart your Apache server after making the change (you can find out how below).

PHP Sessions Directory Configuration

  1. Create a folder in E:\ (root) where you want PHP to store session information (i.e. E:\phpsessions)
  2. Edit E:\WINDOWS\php.ini file
  3. Find second "session.save_path" string
  4. Change it to "session.save_path = E:/phpsessions" (without quotes and uncomment it (i.e. remove ";"))
  5. ATTENTION: "If session.save_path's path depth is more than 2, garbage collection will not be performed."

**** You will need to restart your Apache server after making the change (you can find out how below).

Important Apache Commands

Go to the E:\Program Files\Apache Group\Apache2 directory.

	bin\apache -?

	bin\apache -k install (to install the service into Windows)
	bin\apache -k uninstall

	bin\apache -k start
	bin\apache -k stop (or shutdown)
	bin\apache -k restart

	net start apache2 (same as bin\apache -k start)
	net stop  apache2 (same as bin\apache -k stop)

Important MySQL Commands

AFTER INSTALLING MySQL (i.e. install MySQL to E:\mysql directory) copy E:\mysql\my.ini to E:\WINDOWS to get rid of error 1067

Go to the E:\mysql directory.

	bin\mysqld-nt --install (to install the service into Windows)
	bin\mysqld-nt --remove

	net start mysql
	net stop  mysql

Default Index Page Configuration

Edit httpd.conf of Apache. Search for "DirectoryIndex" add index.php filename.

	DirectoryIndex index.html index.xhtml index.php

Default Index Page Configuration Using .htaccess

Add "DirectoryIndex index.php" to the .htaccess file (if no such file create) in the root directory of the site. Make sure you change the "AllowOverride None" line in httpd.conf file to "AllowOverride All".

phpMyAdmin Installation & Configuration

Apache+PHP+MySQL should be installed and running before applying following steps.

  1. Extract the zip file (i.e. phpMyAdmin-2.6.0-pl3.zip) into a directory in E:\Program Files\Apache Group\Apache2\htdocs\
    (i.e. E:\Program Files\Apache Group\Apache2\htdocs\myfiles\phpmyadmin\)
  2. Edit file "config.inc.php" in the folder that you have extracted zip file
  3. Find
    $cfg['PmaAbsoluteUri']
    line and modify it as in the following step
  4. $cfg['PmaAbsoluteUri'] = 'localhost/your_phpmyadmin_dir';
    (include semicolon) (i.e. $cfg['PmaAbsoluteUri'] = 'localhost/myfiles/phpmyadmin';)

    If your are running phpMyAdmin on a real server (not localhost):

    $cfg['PmaAbsoluteUri']= 'http://breuer.cs.kent.edu/php_cem/phpmyadmin/';
  5. Find
    $cfg['Servers'][$i]['auth_type']
    line
  6. Make the value of this line 'http' if you would like to be asked for password whenever MySQL users run phpMyAdmin
  7. Run phpMyAdmin typing the following to the address bar of your browser:
    http://localhost/myfiles/phpmyadmin/index.php

Securing The Initial MySQL Accounts

(from http://dev.mysql.com/doc/mysql/en/Default_privileges.html)

The grant tables define the initial MySQL user accounts and their access privileges. These accounts are set up as follows:

As noted, none of the initial accounts have passwords. This means that your MySQL installation is unprotected until you do something about it:

CREATE A USER from phpMyAdmin (don't give ANY global privilege, so "USAGE" priviledge will be assigned only):

	host    : localhost
	username: michael
	password: *********

And then you can provide him database-specific priviledges. Keep in mind that global priviledges always dominates the database-specific priviledges.

Perl Installation

  1. Install ActivePerl (activeperl-5.8.6.811-mswin32-x86-122208.msi)
  2. Using Notepad (or other text editor) open ..\Apache2\conf\httpd.conf and search for "Options Indexes FollowSymLinks" (about line 267) when you find it add ExecCGI to the end so it looks like
    Options Indexes FollowSymLinks ExecCGI
  3. Testting the CGI: create a file in ../Apache2/cgi-bin/ called hello.cgi (or hello.pl) and put these three lines in it (if you did disable the default cgi-bin directory, put the CGI file anywhere in your document_root):
    #!e:/Perl/bin/Perl.exe
    print "Content-type:text/html\n\n";
    print "hello world";

    Alternatively use the following code to see the environment variables:

    	#!e:/Perl/bin/Perl.exe
    	##
    	##  printenv -- demo CGI program which just prints its environment
    	##
    
    	print "Content-type: text/plain\n\n";
    	foreach $var (sort(keys(%ENV))) {
    	    $val = $ENV{$var};
    	    $val =~ s|\n|\\n|g;
    	    $val =~ s|"|\\"|g;
    	    print "${var}=\"${val}\"\n";
    	}
    
  4. Restart Apache if it is already running. Now go to
    http://127.0.0.1/cgi-bin/hello.cgi (or hello.pl)
    using your web browser. If you get a hello world (or environment variables) in your browser, CGI is running. If you get a 500 error, go to the last entry in
    E:\Program Files\Apache Group\Apache2\logs\error.log
    (or the Review Error Log in the start menu/Apache) to see exactly what caused this error.

HTTP Authentication

  1. Open a command prompts and go to your Apache server bin directory.
    cd\"Program Files\Apache Group\Apache2\bin"
  2. Type the following command is to create the .htpasswd file under \htdocs\myfiles\ directory:
    htpasswd -c "E:\Program Files\Apache Group\Apache2\htdocs\myfiles\.htpasswd" michael
    	(Output)
    	Automatically using MD5 format.
    	New password: ********
    	Re-type new password: ********
    	Adding password for user michael
    

    Note that in the example shown, a password file is being created containing a user called "michael", and this password file is being placed in the location:

    E:\Program Files\Apache Group\Apache2\htdocs\myfiles\.htpasswd

    The -c flag is used only when you are creating a new file. After the first time, you will omit the -c flag, when you are adding new users to an already existing password file. For instance:

    cd\"Program Files\Apache Group\Apache2\bin"
    htpasswd "E:\Program Files\Apache Group\Apache2\htdocs\myfiles\.htpasswd" balfredo
    

    In order to delete a user from .htpasswd use the following command:

    htpasswd -D "E:\Program Files\Apache Group\Apache2\htdocs\myfiles\.htpasswd" balfredo
  3. Once you have created the password file, you need to tell Apache about it, and tell Apache to use this file in order to require user credentials for admission. To do that create "E:\Program Files\Apache Group\Apache2\htdocs\myfiles\secure\.htaccess" where "secure" is the directory (create it) that you want to protect from people, and add the following lines in it:
    AuthType Basic
    AuthName "By Invitation Only"
    AuthUserFile "E:\Program Files\Apache Group\Apache2\htdocs\myfiles\.htpasswd"
    Require valid-user
    

    The phrase "By Invitation Only" will be displayed in the password pop-up box, where the user will have to type their credentials.

  4. Edit the file E:\Program Files\Apache Group\Apache2\conf\httpd.conf and find the "AccessFileName" string. Change the following:
    #
    # AccessFileName: The name of the file to look for in each directory
    # for additional configuration directives.  See also the AllowOverride
    # directive.
    #
    AccessFileName .htaccess
    
    <Directory "E:\Program Files\Apache Group\Apache2\htdocs\myfiles\secure">
    	Options Indexes FollowSymLinks MultiViews Includes
    	AllowOverride AuthConfig
    	Order allow,deny
    	Allow from all
    </Directory>
    
    #
    # The following lines prevent .htaccess and .htpasswd files from being
    # viewed by Web clients.
    #
    <Files ~ "^\.ht">
        Order allow,deny
        Deny from all
    </Files>
  5. Restart the Apache server.
    net stop apache2
    net start apache2
  6. Now, the following address should ask for authentication. Any user in the .htpasswd file can access to that folder using their own passwords.
    http://localhost/myfiles/secure/

    Note that you should not be able to see the directory content of "secure" when you go to address:

    http://localhost/myfiles/

    You can see the content only after you type a valid username/password after visiting that secure folder as long as you don't restart your browser.

Setting Up A Virtual Host In Apache

There are two files that you will need to edit. The first file we'll need to edit is the Apache httpd.conf file.

E:\Program Files\Apache Group\Apache2\conf\httpd.conf

Let's assume that you have your web sites located in a folder on your E drive called "My Sites". Each web site has a sub-folder of its own under that folder, like this:

E:\My Sites\Site1
E:\My Sites\Site2

Say also, for this example, that the domains for the two sites are site1.com and site2.com. We're going to set up virtual hosts for those two sites using the domain names site1.local and site2.local. That way, you'll be able to tell at a glance whether you're looking at the live site, or your testing site.

You can call the domains anything you want. I choose to use the convention of using the same domain name along with the .local TLD to simplify and minimize the typing needed to switch between the live site and the testing site. The only important point, and it's really important, is that you NEVER use an actual, real, live domain name. If you used, for example, site1.com for the local virtual host, you would never be able to actually reach the live site. All requests for the live site would be re- directed to your local virtual host.

Go to the very bottom of your httpd.conf file in your text editor. You should see an (commented) example of a virtual host there. Add the following lines below that example:

NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
   DocumentRoot "E:\My Sites\Site1"
   ServerName site1.local
</VirtualHost>

<VirtualHost 127.0.0.1>
   DocumentRoot "E:\My Sites\Site2"
   ServerName site2.local
</VirtualHost>

Save and close the file. That will tell the Apache server everything it needs to know in order for it to serve the pages using the domain names site1.local and site2.local. We put quotation marks around the document root directory because there is blank space in the path. If the path does not have any spaces in it, do not quote the path.

The second file you need to edit (for resolving the DNS issue) is called "hosts". It is a Windows system file and it will enable you to enter specific addresses for specific domains instead of using a DNS lookup. The normal location for this file is:

E:\WINDOWS\system32\drivers\etc\hosts

If you don't find it there, do a search in your Windows directory for the word "hosts" in the file name.

If there are any non-commented entries in the file leave them alone. Just go to the bottom of the file, below all the comments and any existing entries and add the following two lines:

127.0.0.1 	site1.local
127.0.0.1 	site2.local

Save and close the hosts file.

The only remaining thing you need to do is to re-start the Apache server. In the browser's address bar, type http://site1.local and hit the Enter key. If you see a message saying "Forbidden". That's because you don't have read permission for the folder. Create a simple phpinfo.php file with

<?php phpinfo(); ?>

line in it and put it in "E:\My Sites\Site1" directory. Now you should see php information tables when you visit "http://site1.local/phpinfo.php".

When you create the virtual hosts like this, the default http://localhost will no longer work. In many cases, that is unimportant. However, if you're using something like phpMyAdmin, you'll still need it. The solution to that is to create one additional virtual host called "localhost" and points to the original Apache htdocs folder. It might look something like this:

NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
   DocumentRoot "E:\Program Files\Apache Group\Apache2\htdocs"
   ServerName localhost
</VirtualHost>

You must also include this additional virtual host editing the Windows hosts file:

127.0.0.1       localhost

Note that there are other optional settings you can use to configure the virtual host. The above uses only two lines and that's all that's really necessary. You can read about other options in the Apache documentation.

 

Created and maintained by K.Cem Karadeniz
Last update:

Valid XHTML 1.1!   Valid CSS!