Skip to main content

How to natively install Apache, MySQL/MariaDB and PHP on Windows

Usually when doing PHP web development on Windows, the reccomended route is to use a virtual machine based solution such as Vagrant to run a true LAMP (Linux OS, Apache web server, MySQL or MariaDB database, and PHP) stack. Sometimes there are reasons why you might not want a virtualized sever, but a native Windows install, or WAMP.

Some reasons could include:

  • You have a entry level computer with 4GB of RAM or less, you may not want the overhead and sluggishness that can come with running a virtualized server environment.
  • You want to have utilities like Composer, node, Grunt, etc. running natively on Windows, and not walled off in your VM.
  • You're not a fan of integrated solutions like WAMPServer or XAMPP, and want to roll it out on your own. (Seriously, though, you really should try these, it'll save you time and headaches)
  • You want to be able to specify the exact versions of Apache, PHP and your database software
  • You like a challenge, and just want to see if you can do it. (You're such a badass!)

Whatever the reason, it is not all that difficult to get a native WAMP stack running. Here are the steps…

Installation

First thing you'll need to do is download the individual software components:

Apache HTTP server

You can get Windows binaries direct from Apache Lounge. You'll also need the the C++ Redistributable Visual Studio 2015 Update 1

  • Unzip the archive, and move the "Apache24" folder to the root of your C: drive 
  • navigate to the C:\Apache24\bin folder, and hold shift while right-clicking within the folder. From the context menu, choose "open command window here"
  • run the following command to install Apache as a service:

> httpd.exe -k install

  • To have a handy system tray icon to start, stop and restart Apache, double click ApacheMonitor.exe.
  • If you want the Apache monitor to run on startup, place a shortcut to ApacheMonitor.exe in your Startup folder.
    • You can do this by Opening the “Run” dialog box by pressing the Windows key + R.
    • Type “shell:startup” (without the quotes) in the “Open” edit box and click “OK.” Your startup folder will open.
    • Right-click and choose New > Shortcut In the shortcut dialog, use the path C:\Apache24\bin\ApacheMonitor.exe in the location field.
    • Click next, and then customize the shortcut name if you wish and click Finish.

Database server - MariaDB or MySQL 

MariaDB and MySQL are two database servers that are frequently used in web applications. MariaDB is a fork of the MySQL project, and is a drop-in replacement.

Download and run the installer for either database - just accept the defaults in the installer. You'll be prompted to select your database root password, and you'll probably want to select "Install as a service" to register it as a Windows service.

MariaDB install properties
set root password in MariaDB installer
MariaDB intaller - install as a service
Install MariaDB as a service

PHP

As of the writing of this article, the stable relases of PHP are 5.6.18, or 7.0.3. Either will do, it just depends on the versions supported by whatever PHP applications you will be using. In this case we'll use the PHP 5.6.18 - VC11 x64 Thread Safe version.

Extract the zip file to C:\php

Configuration

Apache

Open the Apache configuration file C:\Apache24\conf\httpd.conf in Notepad or your favorite plain text editor
Add the following directives:

# Add to the end of the LoadModule section LoadModule php5_module "C:/php/php5apache.dll" # Add this line inside the conditional brace AddType application/x-httpd-php .php # For syntax highlighted .phps files, also add AddType application/x-httpd-php-source .phps

You will also want to uncomment the lines to load your needed modules, and include needed configuration files. Here are some you might want to enable:

# rewrite module LoadModule rewrite_module modules/mod_rewrite.so # Virtual hosts Include conf/extra/httpd-vhosts.conf

PHP

  • Open the appropriate sample php.ini file in a plain text editor such as Notepad or Notepad++
    • for development server, use php.ini-development
    • for a production server, use php.ini-production
  • Save this file as php.ini
  • Search for 'date.timezone', uncomment the line by removing the ';', and set the value to your local timezone as defined at http://php.net/date.timezone
  • Search for 'extension_dir', and uncomment the line: extension_dir = "ext"
  • Enable the various extensions you want enabled by uncommenting the appropriate lines ';extension=xxx.dll' in the Dynamic Extensions section. You will definitely need to uncoment the lines for php_mysql.dll or php_mysqli.dll in order toconnect to a MySQL or MariaDB database.
  • Make sure the DLLs files actually exist in your C:\php\ext directory or you will get an error when you try to start Apache.

Once you are finished configuring PHP, it is time to restart Apache. If all goes well you will see the message "It works!" when you visit http://localhost/

You can test out your PHP configuration by creating a test file phpinfo.php in c:\Apache24\htdocs. Add the following code to the file:

<?php
phpinfo();

When you visit http://localhost/phpinfo.php, you will see a listing of all your PHP variables and settings.

That wasn't so difficult now, was it?