+ 1

How I can run python script in xampp

I try two way but it still not works

11th Oct 2020, 6:22 PM
Shahedmub
5 Answers
+ 1
Shahedmub wrote, "I try it naw and it's giving me Internal Server Error (500)" Answer: Can you check logs for a more specific error message? I have WAMP instead of XAMPP installed on my machine. C:\wamp64\logs\apache_error.log contains most of the messages related to the CGI configuration for me. There should be a similar file in your XAMPP installation that logs the specific internal server error. I configured my local environment to run Python using CGI to see if I'd find something useful to share. In the script, I could get an internal server error if I didn't include path to the Python interpreter or the ending to the HTTP response head. Something like this worked for me: #!C:\Python27\python print("Content-type: text/html\n\n") print('Hello World') Also, be sure to enable CGI for the directory containing your .py file. The +ExecCGI and the AddHandler cgi-script .py are important here in my httpd-vhosts.conf file: <VirtualHost *:80> ServerName localhost ServerAlias localhost DocumentRoot "${INSTALL_DIR}/www" <Directory "${INSTALL_DIR}/www/"> Options +Indexes +Includes +FollowSymLinks +MultiViews +ExecCGI AllowOverride All Require local AddHandler cgi-script .py </Directory> </VirtualHost> The vhosts.conf file is named differently in other operating systems and probably for XAMPP.
11th Oct 2020, 7:02 PM
Josh Greig
Josh Greig - avatar
+ 2
WAMP or XAMPP is awkward to mix with Python so there isn't a very elegant solution. The best you can do is run the Python script as CGI. How to do that is answered here: https://stackoverflow.com/questions/42704846/running-python-scripts-with-xampp Did you try running as a CGI script? If you want your website to use lots of Python, I would create a new server using Flask and integrate your current site with that. You can run the Flask server on another port if you still need Apache HTTP Server and have only 1 machine to host on. This way, your Python script stays fully loaded and therefore runs more efficiently. It also makes it easier for your Python script to respond appropriately to invalid inputs with proper HTTP codes and so on.
11th Oct 2020, 6:29 PM
Josh Greig
Josh Greig - avatar
+ 2
I try it naw and it's giving me Internal Server Error (500)
11th Oct 2020, 6:33 PM
Shahedmub
+ 2
Thank you I appreciate your help I found my mistake
11th Oct 2020, 7:20 PM
Shahedmub
0
To incorporate more Python into your website, I'd recommend setting up a new Flask server and merging it with your current site. If you still require Apache HTTP Server and have only one hosting machine, you can run the Flask server on a different port. I have done this for my resizeing website https://resizepng.com/ , working it very well
13th Apr 2024, 2:58 PM
Asghar Ali Khan
Asghar Ali Khan - avatar