Apache, MySQL, PHP server on Windows

Apache LogoBeing a web master has its good sides, that's for sure. Messing with slow and unreliable FTP servers all the time isn't one of them. On the other side if you violate your hosters "holy" TOS (Terms of service) you will witness ultra fast shut down of your web page and in some cases wipe of your entire SQL database. What would you say about having testing server of your own? Wouldn't it be nice to test your PHP page locally on your Windows PC during construction and "FTP" it to the server of your choice once it's finished? Sure it would! You don't need Ph.D. in computer science to tune Apache, MySQL and PHP just the way you like it, or maybe even smarter to configure your local testing server the way your web page hosters server is configured. If you're interested, follow me...

First of all, we need to download all of the ingredients for our Windows-Apache-MySQL-PHP cocktail. The one I am talking about is 100% free and it tastes the way you want it to taste. First ingredient is an Apache server. You can get it here. If you don't know what SSL is, take the non-SSL package. Secondly, we need MySQL package for windows. No problem, get yourself one by clicking here. You should download biggest one with its own installer - the msi package. And last but not least important, we need PHP binaries to complete our setup. You can get them here. Do not download package with an installer. Go for the .zip package; be not afraid because I'll show you how to set it up.

Now we have all of the ingredients so we can start mixing our testing server. This is what I have on my desktop that's related to this article:

  • apache_2.2.11-win32-x86-no_ssl.msi
  • mysql-5.1.32-win32.msi
  • php-5.2.9-Win32

If you have all the files from the list (don't mind version number), let's start.

  1. MySQL

    Installing MySQL should be easy. Leave everything at its default, click next until it asks for password. Then make something up and write it down because you will need it for "root" access to your MySQL server. Click again next until you see "Finish"

  2. PHP

    Unzip "php-5.x.x-Win32.zip" to C:\Program Files\php. Now rename php.ini-dist into php.ini if you intend to make a testing server, and that is our intention here. Public servers have to be configured differently when it comes to security, and in that case we would start of with php.ini-recommended. Open your php.ini and remove ";" sign (removing ";" uncomments the affected line) in front of ";extension=php_mysql.dll" like this:

    Change:

    ;extension=php_mysql.dll

    To:

    extension=php_mysql.dll

    Now do the same for ;session.save_path = "/tmp" line and modify it like this:

    session.save_path = "C:/Program Files/php/tmp"

    Also change extension_dir = "./" into:

    extension_dir = "C:/Program Files/php/ext"

    The last thing you must do is to add php folder to your systems PATH variable. Procedure for doing that is specific to version of Windows and here it comes in Windows XP operating system. Right click "My Computer", then click "Properties", "Advanced" tab and at last "Environment Variables". Under System Variables edit "Path". If you followed my guide from the beginning add following to the "Path" variable; ";C:\Program Files\php” including the semicolon.

  3. Apache HTTP Server

    Go ahead and install apache server like any other app. Start its installer and when it asks for some info enter "localhost" for both Network Domain and Server Name. In email address field put your address or make something up. Leave everything else on its default value and finish your installation. Now start your browser and enter "localhost" in address bar. If it pukes on you with "page not found", remove Apache from Control panel and install it again. If it says: "It work's!", then it is apparently working fine and you can proceed. Now open httpd.conf file from your Start Menu (Apache HTTP Server 2.2 => Configure Apache Server Folder). Find the following line:

    DirectoryIndex index.html

    And add "index.php" to it like this:

    DirectoryIndex index.php index.html

    Also add the following under the part with lot's of "LoadModule" lines in your httpd.conf:

    LoadModule php5_module "C:/Program Files/php/php5apache2_2.dll"

    The last two things to add is the following line to your "IfModule mime_module" section:

    AddType application/x-httpd-php .php

    And this line at the end of your httpd.conf:

    PHPIniDir "C:/Program Files/php"

Now restart your machine and go to your favorite browser. In the address bar enter "localhost" and press Enter. Now if you see detailed information about your PHP installation you're good to go. Your new servers root folder is "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs" and that's where you will put your HTML and PHP files. To access MySQL database you must first create it through PHP or MySQL Command Line Client (you'll find it in your start menu). For MySQL username you will use "root" and for password whatever you entered during MySQL installation.

Just to mention, don't be frustrated if it doesn't work. That happens to me from time to time. Just go over the configuration files again, making sure that you didn't make some silly mistake, I usually discover I did just that.

Congratulations! You have a working Apache, MySQL, PHP testing server.

Here you can download php.ini (PHP configuration file) made according to this tutorial. If you want to download matching httpd.conf (Apache configuration file) for this article please click here.

Like in my last article you can also click on “comments” at the top-right of the article if you have a question, or something to add. Enjoy!

DevGenii

A quality focused Magento specialized web development agency. Get in touch!

Leave a Reply

Your email address will not be published. Required fields are marked *