Skip to content


Configuring PHP & MySQL on Windows

This section contains help & material related to web development.

Configuring PHP & MySQL on Windows

Postby Web Guru » April 28th, 2009, 6:55 am

WAMP Installation Instructions (Windows Apache MySQL PHP)

The following instructions will assist you with configuring a WAMP server on your Windows desktop.

1- Apache Web Server
Download the latest version of Apache 2.0 series as a msi install. http://httpd.apache.org

When installing, select the custom install. Accept the default values When at the components page, select the root component and change the default install directory from “c:\program files\apache foundation” to simply “C:\”. This will install apache here:
Code: Select all
c:\apache2
c:\apache2\bin\apache.exe
c:\apache2\htdocs
c:\apache2\logs



2- PHP
Download the latest versions of PHP and PECL packages in zip format found here: http://www.php.net

Unzip the standard PHP package here:
Code: Select all
c:\php


Unzip the PECL packages here:
Code: Select all
    c:\php\ext


Make the following directories:
Code: Select all
    c:\php\uploadtemp
    c:\php\sessions
    c:\php\conf


Copy the php.ini-recommended to the following file:
Code: Select all
    c:\php\php.ini


Edit the php.ini, changing the following settings:
Code: Select all
    error_reporting = E_ALL & ~E_NOTICE
    …
    display_errors = On
    …
    extension_dir = “c:/php/ext/”
    …
    upload_tmp_dir = c:/php/uploadtemp/
    …
    upload_max_filesize = 8M
    …
    ; Uncomment the following extensions
    extension=php_mbstring.dll
    extension=php_curl.dll
    extension=php_gd2.dll
    extension=php_mysql.dll
    extension=php_sockets.dll
    extension=php_zip.dll
    …
    sendmail_from = your@email.com
    …
    session.save_path = “C:/php/sessions”


Create the following apache conf file and save it as c:\php\conf\php.conf
Code: Select all
    LoadModule php5_module “c:/php/php5apache2.dll”
    PHPIniDir “C:/php”
    AddType application/x-httpd-php .php
    DirectoryIndex index.php


Add the following line to your apache conf file (near the bottom of the file, before VirtualHosts):
Code: Select all
    Include “C:/php/conf/php.conf”


In your c:\apache2\htdocs folder, you may seen many files called ‘index.html.*’. These are safe to delete. Create a new file in your c:\apache2\htdocs folder called phpinfo.php and open in your favorite editor. Add the following code: <?php phpinfo(); ?>

Restart apache. Go to the following URL and verify that PHP is installed correctly
Code: Select all
    http://localhost/phpinfo.php


Add to the PATH environment variable.
Code: Select all
    PATH=c:\php;c:\php\ext;…
    (where … means the existing values)


You should now reboot your computer for the change in environment variables to take effect. (So modules such as MySQL can be loaded).


3- MySQL

Install the latest version of the MySQL 5.0.x series in zip format found here: http://www.mysql.com

Extract the files to the following directory:
Code: Select all
    c:\mysql


Install MySQL as a service by opening the command prompt, and browsing to the following directory:
Code: Select all
    cd c:\mysql\bin
    mysqld-nt –install


MySQL (alternate)
You can also install the latest ‘essential’ version of MySQL as an install: http://www.mysql.com

Change the installation directory to C:\mysql

Make sure to check “Install as a service”

If you enter a root password, you’ll have to enter that in phpMyAdmin’s config.inc.php


Code: Select all
4- phpMyAdmin (Web Application to Mange MySQL Database

Download the latest version of phpMyAdmin, english format in either zip or 7z format found here: http://www.phpmyadmin.net

Unzip the contents of the branch version to the following folder:
Code: Select all
    C:\apache2\htdocs\phpmyadmin\


Create a new config.inc.php modeled from the sample config file in the current directory. Don’t forget to include the <?php and ?> at the beginning and end of the file.
Code: Select all
    c:\apache2\phpmyadmin\config.inc.php


Edit in your favorite editor. Make sure to add the following settings:
Code: Select all
    $cfg['blowfish_secret'] = ‘random-str’;
    $i = 0;
    $i++;
    $cfg['Servers'][$i]['auth_type'] = ‘config’;
    $cfg['Servers'][$i]['user'] = ‘root’;
    $cfg['Servers'][$i]['password'] = ”; // put here your password after
    // setting one ( strongly recommended ! )
    $cfg['Servers'][$i]['ssl'] = false; // pma 2.10.0.0


Go into the phpmyadmin, create a pma user. Follow the instructions found here: http://wiki.cihar.com/pma/controluser

Edit the config.inc.php file in your favorite editor a second time.
Code: Select all
    $cfg['blowfish_secret'] = ‘random-str’;
    $i = 0;
    $i++;
    /* Authentication type */
    $cfg['Servers'][$i]['auth_type'] = ‘cookie’;
    /* Server parameters */
    $cfg['Servers'][$i]['host'] = ‘localhost’;
    $cfg['Servers'][$i]['connect_type'] = ‘tcp’;
    $cfg['Servers'][$i]['compress'] = false;
    /* Select mysqli if your server has it */
    $cfg['Servers'][$i]['extension'] = ‘mysql’;
    /* User for advanced features */
    $cfg['Servers'][$i]['controluser'] = ‘pma’;
    $cfg['Servers'][$i]['controlpass'] = ‘pma’;
    // For your sanity, set the cookie to not expire for 12 hours.
    $cfg['LoginCookieValidity'] = (60*60*12);


Last, change your root password so it is secure. You should now be able to sign in/out of phpmyadmin with the root password.

Create Apache Config Files for Each Site
Similar to the config file created for loading php in apache, we will create separate config files for each local web site you wish to host on your computer.

Create a folder on your computer where you would like your local web site to reside. Example:
Code: Select all
    c:\projects\my_website


Create a cgi-bin, conf, htdocs and logs folders within the my_website folder. Example:
Code: Select all
    c:\projects\my_website\cgi-bin
    c:\projects\my_website\conf
    c:\projects\my_website\htdocs
    c:\projects\my_website\logs


Create an apache configuration file for your web site:
Code: Select all
    c:\my_website\conf\httpd.conf


Open the httpd.conf file in your favorite editor and add the following:
Code: Select all
    # my_website.com
    <VirtualHost *:80>

    # General site settings
    ServerName www.my_website.local
    ServerAlias my_website.local
    ServerAdmin postmaster@my_website.com

    # PHP Settings (optional):
    php_flag display_errors on
    php_value error_reporting 2039

    # htdocs:
    DocumentRoot “c:/projects/my_website/htdocs”
    <Directory “c:/projects/my_website/htdocs”>
    Allow from all
    AllowOverride Options FileInfo AuthConfig
    Options Includes FollowSymLinks
    </Directory>

    # cgi-bin (optional):
    ScriptAlias “/cgi-bin/” “c:/projects/my_website/cgi-bin”
    <Directory “c:/projects/my_website/cgi-bin”>
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
    </Directory>

    # Support phpMyAdmin (optional):
    Alias “/phpmyadmin/” “c:/apache2/htdocs/phpmyadmin”

    # Logging
    ErrorLog “c:/projects/my_website/logs/error.log”
    CustomLog “c:/projects/my_website/logs/access.log” combined
    </VirtualHost>


You may switch the use of .local with .com if you like. I prefer to use .local so I know I am working with a local copy of my web site and not the actual production web site.

Open the main apache httpd.conf file (c:\apache2\conf\httpd.conf) and include the following at the very bottom of the configuration file:
Code: Select all
    # Enable virtual hosts in Apache:
    NameVirtualHost *:80

    # Default htdocs directory for all unknown virtual hosts:
    <VirtualHost *:80>
    DocumentRoot c:/apache2/htdocs
    ServerName localhost
    </VirtualHost>

    # Include your own apache configuration files
    Include “C:\projects\my_website\conf\httpd.conf”


Add the following line to your windows hosts file (c:\windows\system32\drivers\etc\hosts):
Code: Select all
    127.0.0.1 my_website.local www.my_website.local


Restart apache, then browse to the following url in your web browser.
Code: Select all
    http://my_website.local



Conclusion
Hopefully you will find these steps useful for configuring your own WAMP server on your desktop. The steps above were carefully crafted so you can quickly upgrade any of the software without having to perform a lot of re-configuration. I hope you find this method of installing and configuring Apache, MySQL and PHP on a Windows desktop as useful I do.
User avatar
Web Guru
 
Posts: 94
Joined: March 24th, 2008, 7:59 am
Location: Lahore, Pakistan

Return to Board index

Return to Miscellaneous

Who is online

Users browsing this forum: No registered users and 0 guests