简体   繁体   English

在AWS上部署Python webApp(不使用Elastic Beanstalk)

[英]Deploy Python webApp on AWS (without using Elastic Beanstalk)

I'm hosting a website on AWS. 我正在AWS上托管一个网站。 Its a web interface with a SQL database. 它是带有SQL数据库的Web界面。 The website will be used to: 1. View results of query from Database 该网站将用于:1.从数据库查看查询结果
2. Insert data into database 2.将数据插入数据库
3. View the data and update it where needed. 3.查看数据并在需要时进行更新。

The codes and connections works file when I run the application on localhost (Apache on my C drive). 当我在本地主机(C驱动器上的Apache)上运行应用程序时,代码和连接有效。 But we want to host it on AWS so that people around me can use it. 但是我们希望将其托管在AWS上,以便我周围的人可以使用它。
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. 因此,在AWS中,我将代码上传到EC2并在其上安装了apache,所有html链接都可以使用,但是python文件只是显示了代码。

I'm guessing it has something to do with the shebang. 我猜想这与shebang有关。 Currently my code has the following shebang: 目前,我的代码具有以下shebang:

#!C:\Python27\python.exe

Can someone guide me if its the shebang or if there is something else i need to do. 有人可以指导我,如果它是shebang还是我需要做其他事情。

I have installed boto, but not sure what to do next. 我已经安装了boto,但不确定下一步该怎么做。 The AWS website and most of the forums talk about using Elastic Beanstalk. AWS网站和大多数论坛都谈论使用Elastic Beanstalk。 I want to host a fully functioning Python webApp on AWS without using Elastic Beanstalk. 我想在AWS上托管功能全面的Python webApp,而不使用Elastic Beanstalk。

Hi have you logged into your EC2 instance through the endpoint and then run your script, from the command line. 嗨,您是否已通过端点登录到EC2实例,然后从命令行运行脚本。 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. 我对运行apache2的EC2有一定的经验,只有我的应用程序是用Java编写的,以前使用过python脚本,因此我可以通过登录EC2实例来运行它们,您可以从AWS管理控制台执行此操作。 hope this helps you somewhat. 希望这对您有所帮助。

When apache displays code, that is a clear sign that Apache is not configured properly to execute python. 当apache显示代码时,这清楚地表明Apache没有正确配置为执行 python。 You should look to see if mod_python is installed and configured correctly. 您应该查看是否已正确安装和配置mod_python

Also, #! 另外, #! is generally used with Linux not windows. 通常用于Linux而不是Windows。 If apache/mod_python is installed and configured correctly I can't imagine what code you'd have that would need #! 如果正确安装和配置了apache / mod_python,我将无法想象您需要的代码是#! since the .py extension would be enough. 因为.py扩展名就足够了。

IF your EC2 instance is indeed running Linux, and your code does indeed need #! 如果您的EC2实例确实在运行Linux,并且您的代码确实需要#! try: 尝试:

#!/bin/python

OR 要么

#!/usr/local/bin/python

(Depends on where the python binary is, and those are the most common locations.) (取决于python二进制文件的位置,而这些是最常见的位置。)

If your EC2 instance is running Windows then "Unless you are using cygwin, windows has no shebang support" 如果您的EC2实例正在运行Windows,则“除非您使用cygwin,否则Windows不支持shebang”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM