Install and setup Apache + MySQL + PHP on Windows

tonda13

Antonin Neumann

Posted on October 1, 2019

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
💖 💪 🙅 🚩
tonda13
Antonin Neumann

Posted on October 1, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related