我在Heroku上部署了一个简单的PHP应用程序,其中只包含一个(PHP)脚本用于我的源代码。我决定在一个单独的PHP脚本中编写一个函数。在此之后,我收到了403 Forbidden Error
,此消息显示在我的应用的网址上:Forbidden You don't have permission to access / on this server
。因此,我创建了一个名为Procfile
的文本文档,没有任何扩展名,我在其中发布了以下内容:web: vendor/bin/heroku-php-apache2 web/
。
但是,现在我在heroku logs
上收到以下错误:
2018-04-10T09:09:09.853483+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/" host=************.herokuapp.com request_id=************ fwd="************" dyno= connect= service= status=503 bytes= protocol=https
2018-04-10T09:09:56.037642+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=************.herokuapp.com request_id=************ fwd="************" dyno= connect= service= status=503 bytes= protocol=https
并在我的应用的网址上显示以下消息:
Application error
An error occurred in the application and your page could not be served.
If you are the application owner, check your logs for details.
Heroku上的My(主)PHP脚本从Dialogflow接收/托管webhook,并从数据库中检索一些信息。它看起来像这样:
<?php
$dbServername = '******************';
$dbUsername = '******************';
$dbPassword = '******************';
$dbName = '******************';
$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
header('Content-Type: application/json');
$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'POST') {
$requestBody = file_get_contents('php://input');
$json = json_decode($requestBody);
$action = $json->result->action;
$first_name = $json->result->contexts[0]->parameters->{'given-name'};
$last_name = $json->result->contexts[0]->parameters->{'last-name'};
$lifespan = $json->result->contexts[0]->lifespan;
$sql = "SELECT * FROM family WHERE name LIKE '%$first_name%$last_name%';";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$person = $row;
}
switch ($action) {
case 'Name':
$speech = "$first_name is my" . $person["name"] . ".";
break;
case 'Location':
$speech = "$first_name is living in {$person["location"]}.";
break;
default:
$speech = "Please ask me something more relevant to my family";
break;
}
} else {
$speech = "Sorry, $first_name $last_name is not a member of my family.";
}
$response = new \stdClass();
$response->speech = $speech;
$response->displayText = $speech;
$response->source = "agent";
echo json_encode($response);
} else {
echo "Method not allowed";
}
?>
为什么我会收到此错误以及如何解决此问题?
我不知道这是否相关,但当我在终端输入git push heroku master
时,我也收到以下警告:
remote: ! WARNING: Your Composer vendor dir is part of your Git repository.
remote: This directory should not be under version control; only your
remote: 'composer.json' and 'composer.lock' files should be added, which
remote: will let Composer handle installation of dependencies on deploy.