Signup/Sign In
PUBLISHED ON: FEBRUARY 27, 2023

Install and setup Apache + MySQL + PHP + FakeSMTP on Windows

Apache, PHP, MariaDB and FakeSMTP are essential tools for web development on a Windows machine. Apache is a web server that allows you to host your own websites and applications, PHP is a popular programming language used for server side scripting, MariaDB is a database management system, and FakeSMTP is a Java application that simulates an SMTP server for local development. .

This tutorial will walk you through the process of installing and configuring these tools on your Windows computer.

Prerequisites

Before you begin, you'll need to download the following installers:

You will also need to install the latest C++ Redistributable for Visual Studio 2017, which can be downloaded from https://microsoft.com/en-in/download/details.aspx?id=48145.

Installing MariaDB/MySQL in Windows

  • Install the MariaDB server by running the downloaded installer.
  • If necessary, you can change the port during the installation process. If you change the port, you'll need to update the connection string in PHP.

Installing the Apache Server in Windows

  1. Unzip the downloaded Apache archive into the C:\Apache directory (or another location).
  2. Go to the C:\Apache\conf directory and open the httpd.conf file in a text editor.
  3. In the "httpd.conf" file, change the line # ServerName www.domain.com:80 to ServerName localhost.
  4. Find all occurrences of AllowOverride None and change them to AllowOverride All.
  5. Enable mod_rewrite by uncommenting the line #LoadModule rewrite_module modules/mod_rewrite.so.
  6. To register Apache as a service, open the powershell and go to the Apache directory (for example, C:\Apache24bin) and enter the command httpd -k install. Apache will now appear in the Services list.

Apache customization

Change the document root

You can change the default directory in which Apache looks for websites by looking for the DocumentRoot and Directory lines in the httpd.conf file and changing the directory path to the desired location. For instance:

DocumentRoot "F:/"
<Directory "F:/">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Creating virtual hosts with custom local domains

You can create virtual hosts with custom local domains for each of your projects by adding a VirtualHost block to the httpd.conf file for each project. For instance:

<VirtualHost 127.0.0.1:80>
    ServerAdmin user.name@mail.com
    DocumentRoot "F:/public_html"
    ServerName www.domain.com
    ServerAlias domain.com
    ServerAlias www.domain.co
    ServerAlias domain.co
    ErrorLog "logs/domain.log"
<VirtualHost>

PHP installation in Windows

  1. Unzip the downloaded PHP file into the C:\php7 directory (or a different location).
  2. Rename or copy "php-ini-development.ini" to "php.ini".
  3. Open "php.ini" and find the "Dynamic Extensions" section. Uncomment the extensions you want to load (for example, bz2, curl, fileinfo, intl, imap, mbstring, mysqli, openssl, pdo_mysql, pdo_sqlite, sqlite3, xsl).
  4. Change the SMTP port to 2525.
  5. To add PHP to system environment variables, open the shell and enter the command setx path "%PATH%, C:\php7" /M.
  6. To configure Apache to use PHP, open the Apache configuration file (for example, C:\Apache24\conf\httpd.conf) and add the lines PHPIniDir "C:/PHP7", AddHandler application/x-httpd -php .php and LoadModule php7_module "C:/PHP7/php7apache2_4.dll".
  7. In the "DirectoryIndex" section of the httpd.conf file, change the DirectoryIndex index.html line to DirectoryIndex index.php.

Installing FakeSMTP in Windows

FakeSMTP is a Java application that simulates an SMTP server for local development on Windows. To install FakeSMTP:

  • Download and unzip the FakeSMTP application to your desired location (for example, C:\FakeSMTP).
  • To start FakeSMTP, open the console and go to the FakeSMTP directory (for example, C:\FakeSMTP) and execute this command java -jar fakeSMTP-2.0.jar --start-server --background --port 2525 --bind- address 127.0 .0.1 --output-dir L:\_email.

Alternatively, you can create a command file (e.g. "fakesmpt.cmd") with the following content:

@echo off
start java -jar C:\FakeSMTP\fakeSMTP-2.0.jar --start-server --background --port 2525 --bind-address 127.0.0.1 --output-dir L:\_emails

So, to start FakeSMTP, simply double click on the "fakesmpt.cmd" file.

Conclusion

By following the steps in this tutorial, you should now have Apache, PHP, MariaDB, and FakeSMTP installed and configured on your Windows computer. You can now start developing and hosting your own websites and applications using these tools.



About the author:
Pradeep has expertise in Linux, Go, Nginx, Apache, CyberSecurity, AppSec and various other technical areas. He has contributed to numerous publications and websites, providing his readers with insightful and informative content.