1

I'm hosting a website on AWS. Its a web interface with a SQL database. The website will be used to: 1. View results of query from Database
2. Insert data into database
3. View the data and update it where needed.

The codes and connections works file when I run the application on localhost (Apache on my C drive). But we want to host it on AWS so that people around me can use it.
So, In AWS I uploaded the code on EC2 and installed apache on it, all the html links are working but the python file is simply displaying the code.

I'm guessing it has something to do with the shebang. Currently my code has the following shebang:

#!C:\Python27\python.exe

Can someone guide me if its the shebang or if there is something else i need to do.

I have installed boto, but not sure what to do next. The AWS website and most of the forums talk about using Elastic Beanstalk. I want to host a fully functioning Python webApp on AWS without using Elastic Beanstalk.

AddyB
  • 29
  • 5

2 Answers2

0

Hi have you logged into your EC2 instance through the endpoint and then run your script, from the command line. I have some experience with EC2 running apache2 only my application was written in Java, having previously used python scripts I was able to run them by logging into my EC2 instance, you can do this from AWS management console. hope this helps you somewhat.

Jason Delaney
  • 458
  • 8
  • 21
  • I got the endpoint in case of ElasticBeanstalk but not when i directly launched an EC2 instance. Am i not looking in the right place? – AddyB Mar 21 '17 at 18:15
  • When you log into your Amazon management console, navigate to your active EC2 instance, this will give you information about your instance and you can start and stop your instance from here, also you will see a option to connect to your instance when you select this you will be provided with information to connect to your instance. Hope this helps – Jason Delaney Mar 21 '17 at 23:00
0

When apache displays code, that is a clear sign that Apache is not configured properly to execute python. You should look to see if mod_python is installed and configured correctly.

Also, #! is generally used with Linux not windows. If apache/mod_python is installed and configured correctly I can't imagine what code you'd have that would need #! since the .py extension would be enough.

IF your EC2 instance is indeed running Linux, and your code does indeed need #! try:

#!/bin/python

OR

#!/usr/local/bin/python

(Depends on where the python binary is, and those are the most common locations.)

If your EC2 instance is running Windows then "Unless you are using cygwin, windows has no shebang support"

Community
  • 1
  • 1
talentedmrjones
  • 7,511
  • 1
  • 26
  • 26
  • Thanks for your comment. I'm using Linux. [Amazon (linux) instance of EC2.] The She bang is still not working. The shebang used in the python config file installed in my EC2 was: #!/usr/bin/python2.7 I tried using it, the script still doesn't run. I even installed mod_python. It still doesn't work. Not sure how to check the configuration of mod_python – AddyB Mar 21 '17 at 18:11
  • Try this http://blog.abhinav.ca/blog/2011/06/23/mod-python-on-amazon-linux/ – talentedmrjones Mar 21 '17 at 18:55
  • It almost worked! Now the problem i'm facing is that python did not have all the modules my program needed. So i installed them. All the packages are now in python2.7. Apache however keeps running my program in python2.6. Would you know why is this happening? – AddyB Mar 23 '17 at 18:51