我看到的链接包括:
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.php
的public/
目录。看看标准PHP包的骨架。关于Slim和apache的更多详细信息可以在Slim 4教程中找到。