Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试将slim framework与PHP和Apache一起使用时未找到URL_Php_Apache_Slim_Ubuntu 18.04 - Fatal编程技术网

尝试将slim framework与PHP和Apache一起使用时未找到URL

尝试将slim framework与PHP和Apache一起使用时未找到URL,php,apache,slim,ubuntu-18.04,Php,Apache,Slim,Ubuntu 18.04,我在linux上使用slim框架和带有apache2的php编写了以下代码: <?php use \Psr\Http\Message\ServerRequestInterface as Request; use \Psr\Http\Message\ResponseInterface as Response; require '../../vendor/autoload.php'; $app = new \Slim\App; #doesn't work results in URl n

我在linux上使用slim框架和带有apache2的php编写了以下代码:

<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

require '../../vendor/autoload.php';

$app = new \Slim\App;

#doesn't work results in URl not found in browser
$app->get('/hello','sayhi');

#works, when i just type in 'localhost/' into my webbrowser
$app->get('/',function()
{
return 'testing';
});





$app->run();

#functions
function sayhi()
{
  echo 'hello world again';
}
000-default.conf将documentroot设置为我的php文件和.htaccess文件所在的目录

在web浏览器中键入“localhost/”时,将执行匿名功能。因为如果服务器接收到“/”它就会这样做

但是,当我输入'localhost/hello'时,它会导致找不到URL,而当服务器接收到这种类型的URL时,它应该执行'sayhi'函数

为什么要这样做?我的代码中是否有错误,因为我不知道如何对其进行排序

我还尝试将该选项设置为php文件的目录

允许超越所有

但是,当我设置此选项时,这将导致500个内部错误。我试着遵循这个指南:没有用


我不知道如何对其进行排序,帮助?

我认为您需要配置apache,以便所有请求都进入代码所在的index.php。似乎当您请求
localhost/hello
时,您的web服务器会尝试查找文件hello。

您可以告诉Apache将所有路由重定向到索引。请在vhost或.htaccess文件中尝试以下操作:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php [QSA, L]

您使用的是哪个版本的操作系统Slim?它看起来像slim 3,但你的应用实例很奇怪(slim 3需要提供配置)我使用的是slim 3.12版本
.htaccess
文件的内容是什么?这个文件存在吗?是的,我已经更新了我的问题并将其包含在问题描述中。@Entilore我有3.12版本,并遵循slim版本3的代码示例,该版本与网站的实现风格完全相同:我该怎么做?我对apache不是很在行,但您可以尝试这样做:`` AllowOverride None Order Allow,Deny Allow from All FallbackResource/index.php``这就像在vhost中为symfony添加的apache配置中一样:
AllowOverride All
它将表示apache接受。htaccess尝试了它,会导致500个内部错误。知道为什么吗?你能发你的邮件吗?你有apache错误日志吗?
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php [QSA, L]