App Web Tutorials
  • Home
  • Contact
  • Privacy Policy
Reading: How to Host a Python Flask App with SSL on WAMP Server in Windows: A Step-by-Step Guide for Beginners
Share
Subscribe Now
App Web TutorialsApp Web Tutorials
Font ResizerAa
Search
  • Home
  • Contact
  • Privacy Policy
Follow US
Copyright © 2017-2025 App Web Tutorials. All Rights Reserved.
ApachePython FlaskSSL configuration

How to Host a Python Flask App with SSL on WAMP Server in Windows: A Step-by-Step Guide for Beginners

Chetan
By Chetan
Last updated: January 21, 2025
4 Min Read
SHARE
How to Host a Python Flask App with SSL on WAMP Server in Windows: A Step-by-Step Guide for Beginners
How to Host a Python Flask App with SSL on WAMP Server in Windows: A Step-by-Step Guide for Beginners

Setting up a Python Flask application with SSL on a WAMP server in
Windows can be challenging for beginners, but it’s a valuable skill for
deploying secure web applications. This step-by-step tutorial will guide you
through the process, from configuring virtual hosts to enabling SSL on your
WAMP server.

Prerequisites

Before starting, ensure you have
the following:

  • WAMP server installed on your Windows machine
  • Python and Flask installed
  • Basic understanding of Apache, virtual hosts, and SSL certificates

Step 1: Setting Up the Project Directory

First, make sure your project
directory is properly structured. For this example, we’ll use the following
paths:

  • Project directory: C:/wamp64/www/projectdirectory
  • Flask app entry point: C:/wamp64/www/projectdirectory/flaskapp.wsgi
  • Static files directory: C:/wamp64/www/projectdirectory/static

Step 2: Configuring Virtual Hosts in Apache

Next, you need to configure
virtual hosts in Apache to handle different domains and SSL. Open your 
httpd-vhosts.conf file located at C:/wamp64/bin/apache/apache2.4.59/conf/extra/httpd-vhosts.conf and update it with the following
configuration
:

<VirtualHost _default_:80>

    ServerName localhost

    ServerAlias localhost

    DocumentRoot "${INSTALL_DIR}/www"

    <Directory "${INSTALL_DIR}/www/">

        Options +Indexes +Includes+FollowSymLinks +MultiViews

        AllowOverride All

        Require local

    </Directory>

</VirtualHost>

<VirtualHost *:80>

    ServerName example.test

    DocumentRoot "c:/wamp64/www/projectdirectory"

    WSGIScriptAlias / "c:/wamp64/www/projectdirectory/flaskapp.wsgi"

    <Directory "c:/wamp64/www/projectdirectory/">

        Require all granted

    </Directory>

    Alias /static "c:/wamp64/www/projectdirectory/static"

    <Directory "c:/wamp64/www/projectdirectory/static/">

        Require all granted

    </Directory>

</VirtualHost>

<VirtualHost *:80>

    ServerName exampledomain.com

    Redirect permanent / https://exampledomain.com/

</VirtualHost>

<VirtualHost *:443>

    ServerName exampledomain.com

    DocumentRoot "c:/wamp64/www/projectdirectory"

    WSGIScriptAlias / "c:/wamp64/www/projectdirectory/flaskapp.wsgi"

    <Directory "c:/wamp64/www/projectdirectory/">

        Require all granted

    </Directory>

    Alias /static "c:/wamp64/www/projectdirectory/static"

    <Directory "c:/wamp64/www/projectdirectory/static/">

        Require all granted

    </Directory>

    SSLEngine on

    SSLCertificateFile "c:/wamp64/ssl/certificate.pem"

    SSLCertificateKeyFile "c:/wamp64/ssl/key.key"

    ErrorLog "c:/wamp64/logs/myapp-error.log"

    CustomLog "c:/wamp64/logs/ myapp-access.log" common

<span style="background: 0px 50%; border: 0px; color: white; font-family: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="font-family: 'Courier New'; font-size: 10pt;"></VirtualHost></span></span>

Step 3: Configuring Python and WSGI in Apache

To host a Python Flask application, you need to
configure Python and mod_wsgi in Apache. Add the following lines to your 
httpd.conf file, located at C:/wamp64/bin/apache/apache2.4.59/conf/httpd.conf:



LoadFile "C:/Users/Administrator/AppData/Local/Programs/Python/Python312/python312.dll"
LoadModule wsgi_module "C:/projectdirectory/myenv/Lib/site-packages/mod_wsgi/server/mod_wsgi.so"
WSGIPythonHome "C:/projectdirectory/myenv"

Step 4: Enabling SSL in Apache

To enable SSL, ensure that the
SSL module is loaded and the 
httpd-ssl.conf file is included in the Apache configuration.
Uncomment the following line in your 
httpd.conf file:

Include conf/extra/httpd-ssl.conf

Step 5: Disabling Global SSL Settings

Since we’re using virtual
host-specific SSL settings, it’s crucial to disable global SSL settings
in 
httpd-ssl.conf. Comment out the SSL configuration in httpd-ssl.conf by placing # before the SSL directives.

Step 6: Restarting Apache

After completing all the configurations, restart
Apache to apply the changes. You can do this via the WAMP control panel or by
running the following command in the command prompt:

httpd.exe -k restart

Step 7: Testing Your Setup

Now, test your setup by
accessing 
http://exampledomain.com/ and https://exampledomain.com/. Ensure that the site is accessible over both HTTP
and HTTPS, and that SSL is properly configured.

Conclusion

By following this step-by-step
guide, you should now have a working Python Flask application hosted on a WAMP
server in Windows with SSL enabled. This setup ensures that your web
application is secure and accessible to users over HTTPS. Happy hosting!

Final Thoughts

This tutorial aimed to simplify the process of hosting
a Flask app with SSL on WAMP for beginners. The configurations provided are
tailored to a typical deployment scenario, but you can customize them based on
your project’s specific needs. Always remember to keep your SSL certificates
secure and up-to-date to maintain a safe web environment.

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Fixing SSH ‘Unprotected Private Key File’ Error in Windows 11: A Quick Guide Easily Fix the SSH ‘Unprotected Private Key File’ Error on Windows 11 in Minutes
Next Article How to Install and Use pyenv on Windows, Ubuntu, and macOS: A Complete Guide The Ultimate Guide to Installing pyenv on Windows, Ubuntu, and macOS
Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

FacebookLike
XFollow
InstagramFollow
Most Popular
How to Install and Use pyenv on Windows, Ubuntu, and macOS: A Complete Guide
The Ultimate Guide to Installing pyenv on Windows, Ubuntu, and macOS
January 21, 2025
How to Host a Python Flask App with SSL on WAMP Server in Windows: A Step-by-Step Guide for Beginners
January 21, 2025
Fixing SSH ‘Unprotected Private Key File’ Error in Windows 11: A Quick Guide
Easily Fix the SSH ‘Unprotected Private Key File’ Error on Windows 11 in Minutes
January 20, 2025
How to Add Eye-Catching Animations to Your HTML Website: A Step-by-Step Guide for Beginners
Power Your HTML Website with Stunning Animations: Easy Guide for Beginners
January 15, 2025
Master Git with Ease: The Ultimate Cheatsheet Every Developer Needs
Master Git with Ease: The Ultimate Cheatsheet Every Developer Needs
January 21, 2025

Always Stay Up to Date

Subscribe to our newsletter to get our newest articles instantly!
App Web Tutorials

We provide tutorials, tips, tricks, and advice for improving programming and development skills.

Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?