Configuring Apache and Python

Configuring Apache and Python

Postby jblevins1991 » Mon Jun 20, 2016 7:10 pm

I have followed this https://www.digitalocean.com/community/tutorials/how-to-set-up-an-apache-mysql-and-python-lamp-server-without-frameworks-on-ubuntu-14-04 guide. I keep getting an internal error (status 500) when putting my url localhost/test/index.py into the browsers url. I am pretty decent with administering Apache and the url localhost/test/index.html does work. I am pretty sure Apache is just going WHAT ARE THOSE!?!?!?! everytime I request the python script and has no idea what to do. Any help would be awesome!
Last edited by Yoriz on Mon Jun 20, 2016 7:23 pm, edited 1 time in total.
Reason: First post lock.
jblevins1991
 
Posts: 1
Joined: Mon Jun 20, 2016 7:07 pm

Re: Configuring Apache and Python

Postby metulburr » Mon Jun 20, 2016 10:21 pm

I keep getting an internal error (status 500)

This could be a number of things...

Did you write out the headers exactly as shown before printing anything else?
Code: Select all
print("Content-Type: text/html")
print()


Did you change its permissions?

Code: Select all
sudo chmod 777 index.py


Is it executable?

Code: Select all
sudo chmod +x index.py


Did you put the python shebang line on your first line of your python script?

Code: Select all
#!/usr/bin/env python


Did you make sure you have no syntax errors on your code?

Did you enable cgitb on your script?

Code: Select all
import cgitb
cgitb.enable()


Did you read the apache error logs? Run this next command alongside as you get your browser to show a 500. IT will show you the errors to why you are getting a 500.

Code: Select all
tail -f  /var/log/apache2/error.log


Did you install and enable the cgi module?

Code: Select all
sudo a2enmod cgi
sudo service apache2 restart


more info here
How to run Python CGI program
we will be moving to python-forum.io on October 1 2016
more details here
User avatar
metulburr
 
Posts: 2244
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY


Return to Web Development

Who is online

Users browsing this forum: No registered users and 1 guest