DEV Community


Install and setup Apache + MySQL + PHP on Windows

Antonin Neumann
・3 min read


You can download the required installer via links given below:


  • Firstly install MariaDB server
  • If you needed you can change port during installation process. If you changed it then you improve you must connection string in PHP.

Apache 2.4 server

Install the latest C++ Redistributable Visual Studio 2017:

  • Unzip downloaded Apache archive to the C:\Apache24\ (or somewhere else) directory.
  • After unzipping, go to the folder C:\Apache24\conf\ and open the httpd.conf file by any text editor.

  • In this file change this line

    # ServerName


    ServerName localhost

  • Find all occurrences of AllowOverride None
    and change them to AllowOverride All

  • Enable mod_rewrite by uncomment following line
    #LoadModule rewrite_module modules/

Register Apache service

  • open console and go to Apache directory cd Apache24/bin
  • then type following command httpd -k install
  • now you can see Apache service in Services

Some PRO tips

Change your DocumentRoot

  • You can change default directory where Apache will be looking for websites
DocumentRoot "L:/"
<Directory "L:/">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
Enter fullscreen mode Exit fullscreen mode

Add custom virtual hosts w/ local domains

  • You can also create virtual host with custom local domain for each your projects. Append following to httpd.conf file (for each project):
    DocumentRoot "L:/MyProject"
    ServerName www.myproject.loc
    ServerAlias myproject.loc
    ErrorLog "logs/myproject.log"
Enter fullscreen mode Exit fullscreen mode
  • Then you must edit the hosts file, in Windows is located in C:\Windows\System32\drivers\etc. In this file append following line
    • www.myproject.loc myproject.loc

Change Apache default port

  • You can change default port where Apache server will be listen
    • just change Listen 80 to e.g. Listen 8008
    • and restart service
  • From now you see your website on http://localhost:8008/


  • Unzip downloaded PHP archive to the C:\php7\ (or somewhere else) directory.
  • Rename or copy php-ini-development.ini to php.ini
  • Open php.ini and edit:
    • Find section Dynamic Extensions and uncomment extension which you want to load, here is listing good base of enabled extensions: bz2, curl, fileinfo, intl, imap, mbstring, mysqli, openssl, pdo_mysql, pdo_sqlite, sqlite3, xsl
    • Then change SMTP port to smtp_port = 2525
  • Add PHP in system environment variable.

    • in cmd type setx path "%PATH%, C:\php7" /M
  • Open Apache configuration file (c:\Apache24\conf\httpd.conf) again

    • and append following lines:
PHPIniDir "C:/PHP7"
AddHandler application/x-httpd-php .php
LoadModule php7_module "C:/PHP7/php7apache2_4.dll"
Enter fullscreen mode Exit fullscreen mode
  • Then change DirectoryIndex from index.html to:
<IfModule dir_module>
    DirectoryIndex index.php
Enter fullscreen mode Exit fullscreen mode


  • FakeSMTP is Java application which simulate SMTP server for local developing on Windows.
  • You can start it with following command: start java -jar C:\sw\faceSMTP\fakeSMTP-2.0.jar --start-server --background --port 2525 --bind-address --output-dir L:\_emails
  • Or you can create command file (e.g.: fakesmpt.cmd) with following content:
@echo off
start java -jar C:\sw\faceSMTP\fakeSMTP-2.0.jar --start-server --background --port 2525 --bind-address --output-dir L:\_emails
Enter fullscreen mode Exit fullscreen mode

Discussion (3)

ijsucceed profile image
Jeremiah Ikwuje • Edited

Thanks, Antonin, I love the domain aspect with apache.

Try to check if PHP is installed successfully:

php -v
Enter fullscreen mode Exit fullscreen mode

and you'll get the current version of PHP.

PHP 7.4.5 (cli) (built: Apr 14 2020 16:17:34) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
Enter fullscreen mode Exit fullscreen mode

However, you might get extension errors:

PHP Warning:  PHP Startup: Unable to load dynamic library 'bz2' (tried: C:\php\e
xt\bz2 (The specified module could not be found.), C:\php\ext\php_bz2.dll (The s
pecified module could not be found.)) in Unknown on line 0
Enter fullscreen mode Exit fullscreen mode

This is due to fail extension_dir path. To fix this, comment out the extension_dir for windows inside php.ini file.

; On windows:
extension_dir = "ext"
Enter fullscreen mode Exit fullscreen mode

You can CTRL F to find extension_dir line.

weaponstheyfear profile image

Trying to install php8, this needs to be changed:
LoadModule php7_module "{path to php 8}"

LoadModule php_module "{path to php 8}"

kijato profile image
kijato • Edited

Tell me about more from libmysql.dll...

In my opinion you must:
copy dll to the Apache bin directory
add to path of dll to the PATH
add a "LoadModule /libmysql.dll" row to the httpd.conf
else the Apache cannot find the neccessary dll and throw an error.

Forem Open with the Forem app