Skip to content


How to install an Apache test server on Windows (XAMPP equivalent)

About 5 years after my previous tutorial about installing an Apache+PHP+MySQL server on Windows, the time has come to finally dust it off I think. The main reason why I haven’t updated it for so long was because I started using XAMPP instead (or, actually, XAMPP Lite). But XAMPP isn’t very often updated (and XAMPP Lite is even worse in that matter), and although I’ve managed to manually update PHP 5.3.x from a minor version to another, this isn’t working for the recently released PHP 5.4.

I’m going through the trouble of manual setup in order to get the latest versions, so this guide (not really detailed enough to be called a tutorial I think) will deal with Apache 2.4.1, PHP 5.4 and MySQL 5.5.21. I’m on Windows 7 now (XP wasn’t really an option for >4GiB of RAM), so I picked the 64 bits version whenever available (MySQL – at the time of writing Apache is available in 64 bits but this version doesn’t seem to have a PHP handler yet). For PHP I picked the thread safe binaries because as far as I understood non-thread safe ones are only useful for IIS.

Apache

Unzip the archive wherever you want. I put it in E:\PROGRAMMING\My WAMPP and renamed folder Apache24 to Apache.

Open Apache/conf/httpd.conf in a text editor and:

  • Edit ServerRoot "c:/Apache24" to match the path where you unzipped Apache (for me: ServerRoot "E:/PROGRAMMING/My WAMPP/Apache")
  • Edit Listen 80 as you wish. I don’t want my test server to be reachable from the outside, so I replaced that with Listen 127.0.0.1:80
  • Around lines 72-171 there are lots of modules, uncomment those you want to activate. I uncommented: LoadModule rewrite_module modules/mod_rewrite.so, which is useful for URL rewriting.
  • You may want to also edit:
    ServerAdmin admin@example.com
    ServerName www.example.com:80

    I don’t think what you put there matters on a private, test server, but you do have to uncomment ServerName, even if you leave its default value then.
  • Edit DocumentRoot "c:/Apache24/htdocs" to indicate the folder where you’ll place the files you want Apache to server (that would be your development folder I guess). I configured it as DocumentRoot "F:/OTHER/htdocs"
  • Just below that, make the same kind of edit to <Directory "c:/Apache24/htdocs">. Within that section, you might want to remove indexes (optional since this can actually help with development) by replacing Options Indexes FollowSymLinks with Options FollowSymLinks, and probably to replace AllowOverride None with AllowOverride All for more .htaccess file functionality.
  • Because we’ll be using PHP, replace DirectoryIndex index.html with DirectoryIndex index.php index.htm index.html
  • Finally, logs will probably be useless so to avoid clogging them you could replace LogLevel warn with LogLevel emerg

Apache is now almost ready to run. Run httpd.exe -k install (browse with the console to Apache/bin) to install it as a service, then run ApacheMonitor.exe to control it (you might want to add it to your start menu, too). If you don’t want to install it as a service, simply running httpd.exe should work fine.

To check if everything is working, open http://127.0.0.1 in any browser. Maybe put a file in your DocumentRoot folder to check that you’re indeed loading it.

PHP

Unzip the archive wherever you want. I put it in E:\PROGRAMMING\My WAMPP\PHP.

PHP.ini

Copy php.ini-production as php.ini, and open this php.ini (NB: there are few differences between the production and development php.ini, mainly around error reporting. You can copy the development ini instead if you prefer):

  • Tweak the error reporting as you like. Personally I configured:
    error_reporting = E_ALL
    display_errors = On
    log_errors = Off
  • Set extension_dir to its proper value, for instance extension_dir = "E:/PROGRAMMING/My WAMPP/PHP/ext"
  • If you are going to deal with user-uploaded files, you’ll want to tweak upload_max_filesize, max_file_uploads and post_max_size (the latest should be greater than upload_max_filesize)
  • In the ; Dynamic Extensions ; section, I’ll just uncomment extension=php_pdo_mysql.dll, for PDO access to MySQL extension=php_mbstring.dll, for “multibyte” functions such as mb_stripos and mb_strlen, and extension=php_mysqli.dll, which is required for phpMyAdmin. Also note that you might need to copy/paste the php_mysqli.dll file itself into your Apache/bin folder for it to actually work… funny behavior of this extension (same for the standard php_mysql.dll).
    Other extensions of particular interest are php_mysql.dll and php_gd2.dll (for image manipulation such as CAPTCHAs/turing numbers).
  • In the [mail function] section, uncomment sendmail_from = me@example.com (and optionally replace that with the address that should appear as sender on e-mails sent out by your server – probably you can leave the default value since we’re just configuring a development environment)
  • Some other various interesting settings (I let you figure out what they do, it’s all in the doc – and actually for most of them already all in the sample php.ini file). Note that I mentioned the subsections for easier organization:
    [PHP]
    expose_php = Off
    default_charset = "UTF-8"
    allow_url_include = Off
    default_socket_timeout = 10
    [Date]
    date.timezone = "Europe/Paris"
    [Pdo_mysql]
    pdo_mysql.cache_size = 2000
    pdo_mysql.default_socket=
    [Session]
    session.cookie_httponly = 1
    session.cache_limiter = nocache
    session.hash_function = "sha256"
    session.hash_bits_per_character = 6
    session.upload_progress.enabled = Off
    mbstring.func_overload = 7

    The ; Resource Limits ; section has interesting stuff, too.

That’s all for php.ini. Actually, although this is a huge file (about 1860 lines) at the beginning, if you remove all comments and unused options you can end up with a much smaller file, such as mine which currently has only 125 lines.

Calling PHP from Apache

Now that PHP is configured, we need to make the link between Apache and PHP.
First, grab php5apache2_4.dll and place it in your PHP folder.
Then at the end of httpd.conf, add:
LoadModule php5_module "E:/PROGRAMMING/My WAMPP/PHP/php5apache2_4.dll"
PHPIniDir "E:/PROGRAMMING/My WAMPP/PHP"
AddHandler application/x-httpd-php .php

That’s all for PHP. To check if everything works, restart Apache and then for instance create in your htdocs folder a php file with the following content:

<?php phpinfo(); ?>

MySQL

This time there is an installer, so it’s quite straightforward.

In the installer, we’ll choose custom setup, then remove all components named “development” or “debug” and set the install path to E:\PROGRAMMING\My WAMPP\MySQL\. At some point you’ll have some ad about MySQL enterprise which looks hell lot like an installer, just hit next a couple of times. Then hit finish (leaving the “launch the MySQL instance configuration wizard” box checked).

In the configuration wizard, choose “standard configuration”, leave the default options (Install As Windows Service, Launch the MySQL Server automatically) unless you prefer otherwise, and finally configure the root password.

All is now already configured, although you might want to change
default-character-set=latin1
character-set-server=latin1

to UTF-8 in my.ini
NB: even though I asked MySQL to install in a specific folder, the jack*** put itself (and notably, my.ini) in the standard C:\Program Files\MySQL\MySQL Server 5.5 folder, only leaving data files in the folder where I asked it to install… FFFS…

If you want to be able to quickly start and stop the MySQL service, you can create batch files containing:
net start MySQL
and
net stop MySQL

Aftermath

Well, that pretty much covers it. You now have a fully functional WAMPP equivalent, and it’s much more up-to-date that XAMPP.
This time I won’t cover the phpMyAdmin installation, because 1) it’s pretty trivial (notably, properly documented unlike interfacing Apache and PHP) and 2) if you really, really need help on this, you can probably still apply what I wrote in the previous tutorial, so read on there.
However, if all you want is to quickly set up phpMyAdmin, without using the GUI and without much tweaking, you can just copy the sample config file as config.inc.php, and add/edit those lines, which will allow connection without the need to type login credential and will remove the highly annoying warning message about configuration storage:

$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'xxxxxx'; // your password here
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['PmaNoRelation_DisableWarning'] = true;

Posted in web development, Windows.


3 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. naughty naughty says

    This piece of writing will help the internet users
    for building up new webpage or even a weblog from start to end.

  2. patheticcockroach says

    Seriously, this hasn’t been online for 2 hours and you’re already spamming it? Jeez…

  3. Marcus says

    Hi!
    Try this guide here to install Apache 2.4.3! I tested and it works perfectly:
    mamertum.it/installare-apache-2-4-http-server-su-windows/



Some HTML is OK

or, reply to this post via trackback.

Sorry about the CAPTCHA that requires JS. If you really don't want to enable JS and still want to comment, you can send me your comment via e-mail and I'll post it for you.

Please solve the CAPTCHA below in order to fight spamWordPress CAPTCHA