Are you tired of using pre-packaged WAMPP solutions that limit your control and flexibility? Do you need to run Python web applications on Windows using the Apache web server? Look no further! This guide will walk you through the process of setting up a custom WAMPP environment on Windows, complete with mod_wsgi support for running Python web applications.

By following this guide, you’ll learn how to:

  • Install and configure Apache, MySQL, and PHP/Python on Windows
  • Set up mod_wsgi to run Python web applications using Apache
  • Configure your custom WAMPP environment to meet your specific needs
  • Troubleshoot common issues and optimize performance

Whether you’re a developer, system administrator, or simply looking for a more customizable WAMPP solution, this guide has got you covered. Let’s get started!

Php installation

or

  • Set ChocolateyToolsLocation to C:\Apps
  • Install php using choco

    choco install php --version=8.1.22 --package-parameters='"/ThreadSafe"'
    choco install php --version=8.2.15 --package-parameters='"/ThreadSafe"'
    
  • Set extension directory

    extension_dir = "ext"
    
  • Copy C:\Apps\php81\php.ini-production into C:\Apps\php81\php.ini
  • Enable the extensions by commenting following lines

    extension=curl
    extension=ftp
    extension=fileinfo
    extension=gd
    extension=gettext
    extension=mbstring
    extension=exif      ; Must be after mbstring as it depends on it
    extension=mysqli
    extension=openssl
    extension=pdo_mysql
    extension=pdo_sqlite
    extension=soap
    extension=xsl
    

Download ca certificate and replace for curl config

  • Download the cacert.pem from https://curl.se/ca/cacert.pem.
  • Move it to C:/Apps/php81/extras/ssl and add uncomment the below line in php.ini.

    curl.cainfo = "C:\Apps\php81\extras\ssl\cacert.pem"
    

Apache server installation

Go to directory and install as service

  • Open the terminal in administrative mode and run the below commands
cd C:\Apache24\bin\
httpd -k install
  • httpd server will be installed and Apache2.4 should be available in Services.

Configuring in httpd server

  • Prepare a httpd-php.conf file with following content in C:\Apps\Apache24\conf\extra

    #
    # PHP-Module setup
    #
    
    LoadFile "C:/Apps/php81/php8ts.dll"
    LoadFile "C:/Apps/php81/libpq.dll"
    LoadFile "C:/Apps/php81/libsqlite3.dll"
    LoadModule php_module "C:/Apps/php81/php8apache2_4.dll"
    
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>
    
    <IfModule php_module>
        PHPINIDir "C:/Apps/php8"
    </IfModule>
    
    <IfModule mime_module>
        AddType text/html .php .phps
    </IfModule>
    
    ScriptAlias /php-cgi/ "C:/Apps/php8/"
    <Directory "C:/Apps/php8">
        AllowOverride None
        Options None
        Require all denied
        <Files "php-cgi.exe">
              Require all granted
        </Files>
    </Directory>
    
  • Include the above file in C:\Apps\Apache24\conf\httpd.conf.

    Include conf/extra/httpd-php.conf
    

MySQL installation

phpMyAdmin

/* Authentication type and info */
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '<mysql_password>';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
$cfg['Lang'] = 'en';

/* User for advanced features */
$cfg['Servers'][$i]['controluser'] = 'pma';
$cfg['Servers'][$i]['controlpass'] = '<control_password>';

Adding Xdebug for code coverage

zend_extension=xdebug
  • Create a symbolic directory from project directory
mklink /D C:\Apache24\htdocs\diybaazar C:\Users\purch\Documents\Projects\Github\DIY-Baazar\diybaazar-main

mklink /D C:\Apache24\htdocs\diybaazar-admin C:\Users\purch\Documents\Projects\Github\DIY-Baazar\diybaazar-admin

mklink /D C:\Apache24\htdocs\diybdocs C:\Users\purch\Documents\Projects\Github\DIY-Baazar\diybaazar-docs
  • Add virtual host config in httpd-vhosts.conf
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@diybaazar.xyz
    DocumentRoot "${SRVROOT}/htdocs/diybaazar"
    ServerName diybaazar.xyz
    ErrorLog "logs/diybaazar.xyz-error.log"
    CustomLog "logs/diybaazar.xyz-access.log" common
</VirtualHost>

Hosting Flask Service

  • Installing mod-wsgi
 pip install mod-wsgi
  • Run the following the command and copy the output
 mod_wsgi-express module-config

Output will look something like this:

LoadFile "C:/Python311/python311.dll"
LoadModule wsgi_module "C:/Python311/Lib/site-packages/mod_wsgi/server/mod_wsgi.cp311-win_amd64.pyd"
WSGIPythonHome "C:/Python311"
  • Paste it in httpd.conf.

  • Add the following config in httpd-vhosts.conf.

<VirtualHost *:80>
    DocumentRoot "${SRVROOT}/htdocs/diybdocs"
    ServerAdmin webmaster@diybaazar.xyz
    ServerName docs.diybaazar.xyz

    WSGIScriptAlias / "${SRVROOT}/htdocs/diybdocs/app.wsgi"
    <Directory "${SRVROOT}/htdocs/diybdocs">
        WSGIApplicationGroup %{GLOBAL}
        WSGIScriptReloading On
        allow from all
        #Options None
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog "logs/docs.diybaazar.xyz-error.log"
    CustomLog "logs/docs.diybaazar.xyz-access.log" common
</VirtualHost>