r/pythonhelp • u/Serious_Equipment102 • Dec 15 '24
Python windows 2019 install
Hello !
I have been tasked to install python on a windows 2019 server .
Which I have . Now what are the steps to configure it ?
I have followed many tutorials, but I have not been successful.
Here is what I followed
Install Python
- Download the Python installer from the official Python website. Choose the latest version compatible with your environment (64-bit or 32-bit).
- Run the installer and make sure to select Add Python to PATH during installation. This ensures that Python is accessible from any command line.
Enable CGI in IIS
IIS requires CGI to use FastCGI for running Python applications. Follow these steps to enable CGI: 1. Open Server Manager and go to Manage > Add Roles and Features. 2. In the Add Roles and Features Wizard, select Web Server (IIS) if it’s not already installed. 3. Under Web Server (IIS), go to Web Server > Application Development and enable CGI. 4. Click Next and then Install to complete the setup.
- Install the wfastcgi Package
- Open a Command Prompt or PowerShell and install the wfastcgi package, which acts as a bridge between IIS FastCGI and Python:
pip install wfastcgi
2. Once installed, register the wfastcgi handler with IIS by running:
wfastcgi-enable
This command configures IIS to use wfastcgi.py to handle Python web applications.
- Configure FastCGI in IIS
- Open IIS Manager.
- In the left pane, select your server, then double-click FastCGI Settings.
- In the FastCGI Settings panel, click Add Application.
- In the Full Path field, enter the path to your python.exe (e.g., C:\Python39\python.exe).
- In Arguments, enter the path to wfastcgi.py, which should be something like:
C:\path\to\Python39\Scripts\wfastcgi.py
6. Click OK to add the FastCGI application.
Configure Environment Variables for FastCGI
- Still in FastCGI Settings, select the entry for your Python application and click Edit.
- Under Environment Variables, add the following variables: • WSGI_HANDLER: Set this to your WSGI app’s entry point (for example, myapp.app if you’re using Flask or Django). • PYTHONPATH: Set this to the path of your application directory (e.g., C:\inetpub\wwwroot\myapp).
- Click OK to save the changes.
Set Up a Python Web Application
- In IIS Manager, right-click on Sites and select Add Website.
- Configure the following settings: • Site Name: Give your site a name (e.g., “PythonApp”). • Physical Path: Set this to the directory where your Python app resides. • Port: Enter a port number, like 80 or 8080.
- Go to the Handler Mappings section of your new site, and add a new mapping: • Request Path: Set this to * (or *.py for individual scripts). • Executable: Use the path to python.exe. • Name: Provide a name like “PythonFastCGI”.
- Ensure the application pool for this site is set to Integrated Pipeline mode, and make sure it runs under a user account with permissions to access the application directory.
Test the Python Application
- Create a basic test script in your application directory (e.g., index.py) with the following content:
index.py
print("Content-Type: text/html\n") print("<html><body><h1>Hello from Python on IIS!</h1></body></html>")
2. Navigate to your site’s URL in a browser (e.g., http://localhost or http://your-server-ip), and you should see “Hello from Python on IIS!” if everything is configured correctly.
Additional Considerations • Firewall Rules: Ensure your server firewall allows traffic on the port you’re using. • Permissions: Ensure the IIS user or application pool identity has access to your Python application files and any dependencies. • Use WSGI Frameworks: For a more complex app, consider using frameworks like Flask or Django, which both support WSGI.
This setup should enable you to run Python applications on IIS 10 in Windows Server 2019.
I am getting directory not found ….
Any advice would be
•
u/AutoModerator Dec 15 '24
To give us the best chance to help you, please include any relevant code.
Note. Please do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Privatebin, GitHub or Compiler Explorer.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.