Apache2上的PHP Slim4给出了HttpNotFoundException



我看到的链接包括:

https://akrabat.com/running-slim-4-in-a-subdirectory/

https://discourse.slimframework.com/t/slim-4-httpnotfoundexception/3273/18

和其他一些

我正试图在apache2上设置一个Slim4项目。但试图访问它给了我错误

PHP致命错误:未捕获Slim\Exception\HttpNotFoundException:未找到。。。。

我的索引文件在/var/www/html/_projects/work/calc1/src中。

以下是我在/etc/apache2/sites-available:中的计算.conf

<VirtualHost *:80>
ServerName calc.mrid.local
ServerAlias calc.mrid.local
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/_projects/work/calc1/src
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

这是我的.htaccess,位于src目录中

RewriteEngine On
RewriteBase /_projects/work/calc1/src/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
RewriteRule ^(.*).html$ /$1 [L,R=301]

我的index.php看起来像这样:

// use and require statements...
$container = new Container();
AppFactory::setContainer($container);
$container->set('view', function() {
return SlimViewsTwig::create(__DIR__ . '/public/templates');
});
$app = AppFactory::create();
// even without this line it doesn't work
$app->setBasePath("/_projects/work/calc1/src"); 
$app->add(TwigMiddleware::createFromContainer($app));
// my routes....
$app->run();

有人在Apache2上与Slim4合作过吗?如果是的话,你能给我指路吗?

src/目录实际上只适用于PHP类,不能访问web。apacheDocumentRoot应该指向包含前端控制器public/index.phppublic/目录。看看标准PHP包的骨架。关于Slim和apache的更多详细信息可以在Slim 4教程中找到。

相关内容

  • 没有找到相关文章

最新更新