Page 1 of 2 | 1 | 2 | > | >> | All |
Posted By: tidus on November 23, 2012, 5:42 am | Post: 1 |
Hi,
For running python scripts you must first get familiar with mod_wsgi. Here is the tutorial to run the python scripts using mod_wsgi. http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide ----------------------- Follow AMPPS on, Twitter : https://twitter.com/AMPPS_Stack Facebook : http://www.facebook.com/softaculousampps Google+ : https://plus.google.com/+AmppsStack |
Posted By: memzxi on December 26, 2012, 8:04 pm | Post: 2 |
Hi. Another newbie here. I thank you for your work creating the product and giving it for free, but after that much work, is it that hard to make Python run by default ?
If I want to run php, I put test.php file in www directory and it works fine. I put test.py and it shows unprocessed source code, the same as it would if I opened it in a browser without AIMPS installed. Can you just say which file to put where in order for it to work ? I read quick configuration guide that you posted a link to, but it doesn't seem to help properly. What I did is put the code below in C:\Program Files\Ampps\apache\conf\httpd.conf in line 634 after << # Python Include "C:/Program Files/Ampps/python/python.conf" >> Quote <VirtualHost *:80>
ServerName localhost ServerAlias 127.0.0.1 ServerAdmin webmaster@example.com DocumentRoot /usr/local/www/documents <Directory /usr/local/www/documents> Order allow,deny Allow from all </Directory> WSGIScriptAlias /myapp /usr/local/www/wsgi-scripts/myapp.wsgi <Directory /usr/local/www/wsgi-scripts> Order allow,deny Allow from all </Directory> </VirtualHost> After that, I created the file C:\Program Files\Ampps\www\wsgi-scripts\myapp.wsgi and put the code below in it. the code is from that "quick" configuration guide Quote def application(environ, start_response): status = '200 OK' output = 'Hello World!' response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output] Then I restarted apache, tried to access http://localhost/documents/test.py http://localhost/test.py http://localhost/wsgi-scripts/test.py none worked, help ? ( AMPPS installation is fresh, nothing modified ) |
Posted By: tidus on December 27, 2012, 7:46 am | Post: 3 |
Quote From : memzxi December 26, 2012, 8:04 pm Hi. Another newbie here. I thank you for your work creating the product and giving it for free, but after that much work, is it that hard to make Python run by default ?
If I want to run php, I put test.php file in www directory and it works fine. I put test.py and it shows unprocessed source code, the same as it would if I opened it in a browser without AIMPS installed. Can you just say which file to put where in order for it to work ? I read quick configuration guide that you posted a link to, but it doesn't seem to help properly. What I did is put the code below in C:\Program Files\Ampps\apache\conf\httpd.conf in line 634 after << # Python Include "C:/Program Files/Ampps/python/python.conf" >> Quote <VirtualHost *:80>
ServerName localhost ServerAlias 127.0.0.1 ServerAdmin webmaster@example.com DocumentRoot /usr/local/www/documents <Directory /usr/local/www/documents> Order allow,deny Allow from all </Directory> WSGIScriptAlias /myapp /usr/local/www/wsgi-scripts/myapp.wsgi <Directory /usr/local/www/wsgi-scripts> Order allow,deny Allow from all </Directory> </VirtualHost> After that, I created the file C:\Program Files\Ampps\www\wsgi-scripts\myapp.wsgi and put the code below in it. the code is from that "quick" configuration guide Quote def application(environ, start_response): status = '200 OK' output = 'Hello World!' response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output] Then I restarted apache, tried to access http://localhost/documents/test.py http://localhost/test.py http://localhost/wsgi-scripts/test.py none worked, help ? ( AMPPS installation is fresh, nothing modified ) Hi, Your VirtualHost is wrongly configured, you will have to change(take care of) the paths. i.e change all Code /usr/local/www/documents Code "C:\Program Files\Ampps\www\wsgi-scripts" Change Code WSGIScriptAlias /myapp /usr/local/www/wsgi-scripts/myapp.wsgi Code WSGIScriptAlias /myapp "C:\Program Files\Ampps\www\wsgi-scripts\myapp.wsgi" And Remove This Tag Code <Directory /usr/local/www/wsgi-scripts>
Order allow,deny Allow from all </Directory> Restart Apache. And try accessing http://localhost/myapp Let us know the output. ----------------------- Follow AMPPS on, Twitter : https://twitter.com/AMPPS_Stack Facebook : http://www.facebook.com/softaculousampps Google+ : https://plus.google.com/+AmppsStack |
Posted By: tidus on December 27, 2012, 1:23 pm | Post: 5 |
Quote From : memzxi December 26, 2012, 8:04 pm After that, I created the file C:\Program Files\Ampps\www\wsgi-scripts\myapp.wsgi and put the code below in it. the code is from that "quick" configuration guide Quote def application(environ, start_response): status = '200 OK' output = 'Hello World!' response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output] Hi, The contents were right before which you copied from "quick" configuration guide. Edited by tidus : December 27, 2012, 1:23 pm ----------------------- Follow AMPPS on, Twitter : https://twitter.com/AMPPS_Stack Facebook : http://www.facebook.com/softaculousampps Google+ : https://plus.google.com/+AmppsStack |
Posted By: tidus on December 27, 2012, 2:22 pm | Post: 7 |
Quote From : memzxi December 27, 2012, 1:57 pm Didn't understand what you meant here.
This is my test.py which is in C:\Program Files\Ampps\www\myapp\test.py and I get the same text if open the browser at localhost/myapp/test.py Quote #!/usr/bin/python
print "Content-type: text/html\n\n" print "Hello World from PythonStandard Hello World from a Python" Content of C:\Program Files\Ampps\www\wsgi-scripts\myapp.wsgi is the same, I didn't changed it after first creating the file and pasting the code Quote def application(environ, start_response):
status = '200 OK' output = 'Hello World!' response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output] What is the output of http://localhost/myapp ? BTW Python scripts doesn't work like PHP here. In virtualhost when we configure Code WSGIScriptAlias /myapp "C:\Program Files\Ampps\www\wsgi-scripts\myapp.wsgi" Also the below code won't work... here you here using directly the CGI(not mod_wsgi). Instead of below code, Code #!/usr/bin/python
print "Content-type: text/html\n\n" print "Hello World from PythonStandard Hello World from a Python" write the following code. Code #!"C:\Program Files\Ampps\python\python.exe"
print "Content-type: text/html\n\n" print "Hello World from PythonStandard Hello World from a Python" Before you run test.py, Go to AMPPS Application -> Apache Tab -> Configuration Tab. Find Line Code AddHandler cgi-script .cgi .pl Code AddHandler cgi-script .cgi .pl .py Copy test.py and paste it to C:\Program Files\Ampps\www\cgi-bin\test.py and access http://localhost/cgi-bin/test.py Edited by tidus : December 27, 2012, 2:23 pm ----------------------- Follow AMPPS on, Twitter : https://twitter.com/AMPPS_Stack Facebook : http://www.facebook.com/softaculousampps Google+ : https://plus.google.com/+AmppsStack |
Posted By: memzxi on December 30, 2012, 9:23 pm | Post: 8 |
I installed AMPPS freshly just in case.
1. In folder C:\Program Files\Ampps\www created new folder "wsgi-scripts" 2. in newly created folder C:\Program Files\Ampps\www\wsgi-scripts created file "myapp.wsgi" contents below Code def application(environ, start_response): status = '200 OK' output = 'Hello World!' response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output] 3. Opened the file C:\Program Files\Ampps\apache\conf\httpd.conf 4. In file C:\Program Files\Ampps\apache\conf\httpd.conf line 637 pasted the code Code <VirtualHost *:80> ServerName localhost ServerAlias 127.0.0.1 ServerAdmin webmaster@example.com DocumentRoot "C:\Program Files\Ampps\www\wsgi-scripts" <Directory "C:\Program Files\Ampps\www\wsgi-scripts"> Order allow,deny Allow from all </Directory> WSGIScriptAlias /myapp "C:\Program Files\Ampps\www\wsgi-scripts\myapp.wsgi" </VirtualHost> 5. In folder C:\Program Files\Ampps\www created new folder "myapp" 6. In folder C:\Program Files\Ampps\www\myapp put file test.py contents below Code #!/usr/bin/python print "Content-type: text/html\n\n" print "Hello World from PythonStandard Hello World from a Python" 7. Open in browser http://localhost/myapp/test.py screenshot below, just the code I put in file No sign of working so I'm trying CGI method. STRANGE THING HAPPENED. As you said Quote Go to AMPPS Application -> Apache Tab -> Configuration Tab. Find Line I went there to search for a line, scrolled down and saw there went my code there which I put to C:\Program Files\Ampps\apache\conf\httpd.conf I guess that's some other file. So I pasted the code here hoping it would work, restarted apache, unfortunately the output is the same as in screenshot. Continuing to try with CGI method. Quote Before you run test.py, Go to AMPPS Application -> Apache Tab -> Configuration Tab. Find Line Code AddHandler cgi-script .cgi .pl
change it to Code AddHandler cgi-script .cgi .pl .py
Save the File. Restart Apache. Copy test.py and paste it to C:\Program Files\Ampps\www\cgi-bin\test.py and access http://localhost/cgi-bin/test.py It worked! Thanks a bunch! Still wondering why WSGI method didn't work. Besides, what is the differences between the two ? |
Posted By: tidus on December 31, 2012, 7:46 am | Post: 9 |
Hi,
To start scripting with mod_wsgi : Quote 1. In folder C:\Program Files\Ampps\www created new folder "wsgi-scripts"
2. in newly created folder C:\Program Files\Ampps\www\wsgi-scripts created file "myapp.wsgi" contents below Code def application(environ, start_response): status = '200 OK' output = 'Hello World!' response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output] 3. Opened the file C:\Program Files\Ampps\apache\conf\httpd.conf 4. In file C:\Program Files\Ampps\apache\conf\httpd.conf line 637 pasted the code Code <VirtualHost *:80> ServerName localhost ServerAlias 127.0.0.1 ServerAdmin webmaster@example.com DocumentRoot "C:\Program Files\Ampps\www\wsgi-scripts" <Directory "C:\Program Files\Ampps\www\wsgi-scripts"> Order allow,deny Allow from all </Directory> WSGIScriptAlias /myapp "C:\Program Files\Ampps\www\wsgi-scripts\myapp.wsgi" </VirtualHost> Till step 4, you are correct. Quote 5. In folder C:\Program Files\Ampps\www created new folder "myapp"
6. In folder C:\Program Files\Ampps\www\myapp put file test.py contents below Code #!/usr/bin/python print "Content-type: text/html\n\n" print "Hello World from PythonStandard Hello World from a Python" 5th & 6th step is not needed. Quote 7. Open in browser http://localhost/myapp/test.py screenshot below, just the code I put in file Instead of accessing http://localhost/myapp/test.py just access http://localhost/myapp Because now your wsgi script is mounted at /myapp. Quote Still wondering why WSGI method didn't work. Besides, what is the differences between the two ? There are actually many ways run python on web. This link can explain properly about it. http://docs.python.org/2/howto/webservers.html ----------------------- Follow AMPPS on, Twitter : https://twitter.com/AMPPS_Stack Facebook : http://www.facebook.com/softaculousampps Google+ : https://plus.google.com/+AmppsStack |
Posted By: tidus on January 15, 2013, 5:09 am | Post: 11 |
Hi,
Copy the following contents in Ampps/conf/python.conf and Save.: Code LoadModule wsgi_module modules/mod_wsgi.so
DirectoryIndex index.wsgi default.wsgi index.py default.py WSGIPythonPath "C:/Program Files/AMPPS/python/Lib;C:/Program Files/AMPPS/python/Lib/site-packages;C:/Program Files/AMPPS/python/DLLs" WSGIPythonHome "C:/Program Files/AMPPS/python" Try running the same script again. Edited by tidus : January 15, 2013, 5:11 am ----------------------- Follow AMPPS on, Twitter : https://twitter.com/AMPPS_Stack Facebook : http://www.facebook.com/softaculousampps Google+ : https://plus.google.com/+AmppsStack |
Posted By: tidus on January 15, 2013, 5:41 am | Post: 12 |
Hi,
To install Django you can follow their doc : https://docs.djangoproject.com/en/1.4/topics/install/ mod_wsgi module is already loaded in AMPPS which is required by Django. ----------------------- Follow AMPPS on, Twitter : https://twitter.com/AMPPS_Stack Facebook : http://www.facebook.com/softaculousampps Google+ : https://plus.google.com/+AmppsStack |
Posted By: tidus on January 21, 2013, 5:39 pm | Post: 14 |
Hi,
And did you try the Django docs ? ----------------------- Follow AMPPS on, Twitter : https://twitter.com/AMPPS_Stack Facebook : http://www.facebook.com/softaculousampps Google+ : https://plus.google.com/+AmppsStack |