DEV Community

Antonin Neumann
Antonin Neumann

Posted on

Install and setup Apache + MySQL + PHP on Windows

Download

You can download the required installer via links given below:

MariaDB

  • 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: https://www.microsoft.com/en-in/download/details.aspx?id=48145

  • 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 www.example.com:80

    withhttpd.conf

    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/mod_rewrite.so

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
</Directory>
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):
<VirtualHost 127.0.0.1:80>
    ServerAdmin your.name@gmail.com
    DocumentRoot "L:/MyProject"
    ServerName www.myproject.loc
    ServerAlias myproject.loc
    ServerAlias www.myproject.lc
    ServerAlias myproject.lc
    ErrorLog "logs/myproject.log"
</VirtualHost>
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
    • 127.0.0.1 www.myproject.loc myproject.loc www.myproject.lc myproject.lc

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/

PHP

  • 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
</IfModule>
Enter fullscreen mode Exit fullscreen mode

FakeSMTP

  • 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 127.0.0.1 --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 127.0.0.1 --output-dir L:\_emails
exit
Enter fullscreen mode Exit fullscreen mode

Top comments (3)

Collapse
 
ijsucceed profile image
Jeremy Ikwuje • Edited

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

[UPDATE]
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.

Collapse
 
weaponstheyfear profile image
Jonathan

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

To:
LoadModule php_module "{path to php 8}"

Collapse
 
kijato profile image
kijato • Edited

Tell me about more from libmysql.dll...

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