在托管环境中将我的 PHP Slime Framework 应用程序获取到 运行?
Getting my PHP Slime Framework Application to run in a Hosted Environment?
简介
大家好。我目前已经完成了我的第一个 PHP 网络应用程序的开发——一个使用流行的 PHP 微框架构建的非常简单的应用程序 - Slim Framework 3。
应用程序代码
我的应用程序非常简单,只是将不同的 get
请求路由到不同的模板页面。我正在使用 slimphp/Twig-View
进行视图渲染/模板化。
主 index.php
文件如下所示:
// Require composer autoloader
require __DIR__ . '/vendor/autoload.php';
// Application settings
$settings = require __DIR__ . '/app/settings.php';
// New Slim app instance
$app = new Slim\App( $settings );
// Add our dependencies to the container
require __DIR__ . '/app/dependencies.php';
// Require our route
require __DIR__ . '/app/routes.php';
// Run Slim
$app->run();
routes.php
文件是这样的:
// Creating routes
// Psr-7 Request and Response interfaces
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
$app->group('/', function () {
$this->get('', function (Request $request, Response $response, $args) {
$vars = [
'page' => [
'title' => 'East End Ink',
'description' => 'Best apparel company in Austin'
],
];
return $this->view->render($response, 'home.twig', $vars);
});
$this->get('products', function (Request $request, Response $response, $args) {
$vars = [
'page' => [
'title' => 'East End Ink',
'description' => 'Best apparel company in Austin'
],
];
return $this->view->render($response, 'products.twig', $vars);
});
[...... cut out some repetition ....]
$this->get('services', function (Request $request, Response $response, $args) {
$vars = [
'page' => [
'title' => 'East End Ink',
'description' => 'Best apparel company in Austin'
],
];
return $this->view->render($response, 'services.twig', $vars);
});
});
整个应用程序的源代码是HERE。
我如何在本地 运行 应用程序/尝试在生产环境中 运行
这就是我在本地 运行 Web 应用程序的样子:
20 秒视频 - http://tinypic.com/r/n6c5g7/9
我只是 运行 php -S localhost:8080
一次 localhost:8080
应用程序运行良好。问题是,我不知道如何将其翻译成运行在线申请。我已经将我的源代码部署到 CloudWays 和 FortRabbit,两者都以某种方式成功显示了主页。
CloudWays - http://phpstack-115365-328618.cloudwaysapps.com/:
FortRabbit - https://custom-5yx3.frb.io/:
当我尝试导航到此登台环境中任何其他页面的路由时遇到的错误是:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at [no address given] to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Apache/2.4.10 (Debian) Server at phpstack-115365-328618.cloudwaysapps.com Port 80
我认为它所做的只是在那里提供 php 文件,就像 php 在本地做的那样,如果我在没有 运行ning [=19 的情况下转到应用程序在端口 80 的路由=].
17 我在本地重现相同问题的第二个视频:http://tinypic.com/r/28s6n87/9
现在的问题是:
如何才能将此 Web 应用程序托管在 CloudWays 或 FortRabbit 之类的地方。总的来说,我要做什么才能让它 运行 在那里?如果你足够友善,我可以具体怎么做?
P.S.
该站点的源代码仍然是 public,因此请随时检查它的 GitHub Repo 以细读文件。
P.P.S.
我非常感谢您能够提供的任何帮助。我是 n00b 和这个竞技场,当我像在其他领域一样成为更 able/experienced PHP 的开发人员时,我会回报它。
我从存储库下载了你的文件。
首先,我在本地查看您的网站时遇到以下错误:
Parse error: syntax error, unexpected '}' in /var/www/htdocs/slim/app/routes.php on line 98
那是因为第 97 行缺少分号。我修复了它。
然后我可以看到主页,但尝试转到其他页面时出现 500 错误。
我的问题出在您的 .htaccess 文件中。你有这条线:
RewriteBase /var/www/html/brand-builders-php-site/
如果我将其更改为:
RewriteBase /
然后一切正常(我可以加载页面)
通常有 500 个错误与使用 Slim 3 时的 htaccess 有关,至少从我使用它的时候是这样。
关于 htaccess 的另一个答案正确地解决了这个问题,我会评论但修复不够所以我只能回答。
简介
大家好。我目前已经完成了我的第一个 PHP 网络应用程序的开发——一个使用流行的 PHP 微框架构建的非常简单的应用程序 - Slim Framework 3。
应用程序代码
我的应用程序非常简单,只是将不同的 get
请求路由到不同的模板页面。我正在使用 slimphp/Twig-View
进行视图渲染/模板化。
主 index.php
文件如下所示:
// Require composer autoloader
require __DIR__ . '/vendor/autoload.php';
// Application settings
$settings = require __DIR__ . '/app/settings.php';
// New Slim app instance
$app = new Slim\App( $settings );
// Add our dependencies to the container
require __DIR__ . '/app/dependencies.php';
// Require our route
require __DIR__ . '/app/routes.php';
// Run Slim
$app->run();
routes.php
文件是这样的:
// Creating routes
// Psr-7 Request and Response interfaces
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
$app->group('/', function () {
$this->get('', function (Request $request, Response $response, $args) {
$vars = [
'page' => [
'title' => 'East End Ink',
'description' => 'Best apparel company in Austin'
],
];
return $this->view->render($response, 'home.twig', $vars);
});
$this->get('products', function (Request $request, Response $response, $args) {
$vars = [
'page' => [
'title' => 'East End Ink',
'description' => 'Best apparel company in Austin'
],
];
return $this->view->render($response, 'products.twig', $vars);
});
[...... cut out some repetition ....]
$this->get('services', function (Request $request, Response $response, $args) {
$vars = [
'page' => [
'title' => 'East End Ink',
'description' => 'Best apparel company in Austin'
],
];
return $this->view->render($response, 'services.twig', $vars);
});
});
整个应用程序的源代码是HERE。
我如何在本地 运行 应用程序/尝试在生产环境中 运行
这就是我在本地 运行 Web 应用程序的样子:
20 秒视频 - http://tinypic.com/r/n6c5g7/9
我只是 运行 php -S localhost:8080
一次 localhost:8080
应用程序运行良好。问题是,我不知道如何将其翻译成运行在线申请。我已经将我的源代码部署到 CloudWays 和 FortRabbit,两者都以某种方式成功显示了主页。
CloudWays - http://phpstack-115365-328618.cloudwaysapps.com/:
FortRabbit - https://custom-5yx3.frb.io/:
当我尝试导航到此登台环境中任何其他页面的路由时遇到的错误是:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at [no address given] to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Apache/2.4.10 (Debian) Server at phpstack-115365-328618.cloudwaysapps.com Port 80
我认为它所做的只是在那里提供 php 文件,就像 php 在本地做的那样,如果我在没有 运行ning [=19 的情况下转到应用程序在端口 80 的路由=].
17 我在本地重现相同问题的第二个视频:http://tinypic.com/r/28s6n87/9
现在的问题是:
如何才能将此 Web 应用程序托管在 CloudWays 或 FortRabbit 之类的地方。总的来说,我要做什么才能让它 运行 在那里?如果你足够友善,我可以具体怎么做?
P.S. 该站点的源代码仍然是 public,因此请随时检查它的 GitHub Repo 以细读文件。
P.P.S. 我非常感谢您能够提供的任何帮助。我是 n00b 和这个竞技场,当我像在其他领域一样成为更 able/experienced PHP 的开发人员时,我会回报它。
我从存储库下载了你的文件。
首先,我在本地查看您的网站时遇到以下错误:
Parse error: syntax error, unexpected '}' in /var/www/htdocs/slim/app/routes.php on line 98
那是因为第 97 行缺少分号。我修复了它。
然后我可以看到主页,但尝试转到其他页面时出现 500 错误。
我的问题出在您的 .htaccess 文件中。你有这条线:
RewriteBase /var/www/html/brand-builders-php-site/
如果我将其更改为:
RewriteBase /
然后一切正常(我可以加载页面)
通常有 500 个错误与使用 Slim 3 时的 htaccess 有关,至少从我使用它的时候是这样。
关于 htaccess 的另一个答案正确地解决了这个问题,我会评论但修复不够所以我只能回答。