Cakephp 控制器无法在托管服务器中工作
Cakephp controller not working in hosted server
我的蛋糕php 项目在本地主机上运行完美,但当我将它上传到托管服务器时却无法运行。
这是我的托管服务器 cPanel 文件管理器上的设置:
/home/username/public_html/test
// webroot contents goes here
css/
img/
js/
index.php
/home/username/mycakeapp/
// necessary app directories go here
/config
/logs
/plugins
/src
/tmp
/vendor
我确保在第 52 行 mycakeapp/config/paths.php 中更改 WWW_ROOT:
define(‘WWW_ROOT’, ‘/home/username/public_html/test’ . DS);
我还在以下 3 行中更改了 public_html/test 中的 index.php,以便它正确地需要必要的文件:
require '/home/username/mycakeapp/config/requirements.php';
require '/home/username/mycakeapp/vendor/autoload.php';
$server = new Server(new Application('/home/username/mycakeapp/config'));
执行此操作后,当我打开网站时。com/test,网站会正确打开 home.ctp 文件。但是,在转到 website.com/test/users 等其他页面时,它会给出如下错误消息:
The requested URL /test/users was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
我的 home.ctp 文件只有纯 HTML 代码,所以我想它工作正常。但是,转到其他具有 CakePHP 代码的站点,它似乎根本不起作用。请帮忙!
您应该尝试像这样更改 ./config/app.php
中的 App.base
参数:
'App' => [
// ...
'base' => '/test',
// ...
]
查看文档 here。
上传您的 .htaccess 文件。
不起作用的部分是将对 "pretty" URL(如 /users)的请求重写为对 PHP 脚本(如 /index.php?q=/users)的请求。 .htaccess 文件就是这样做的。
我的蛋糕php 项目在本地主机上运行完美,但当我将它上传到托管服务器时却无法运行。
这是我的托管服务器 cPanel 文件管理器上的设置:
/home/username/public_html/test
// webroot contents goes here
css/
img/
js/
index.php
/home/username/mycakeapp/
// necessary app directories go here
/config
/logs
/plugins
/src
/tmp
/vendor
我确保在第 52 行 mycakeapp/config/paths.php 中更改 WWW_ROOT:
define(‘WWW_ROOT’, ‘/home/username/public_html/test’ . DS);
我还在以下 3 行中更改了 public_html/test 中的 index.php,以便它正确地需要必要的文件:
require '/home/username/mycakeapp/config/requirements.php';
require '/home/username/mycakeapp/vendor/autoload.php';
$server = new Server(new Application('/home/username/mycakeapp/config'));
执行此操作后,当我打开网站时。com/test,网站会正确打开 home.ctp 文件。但是,在转到 website.com/test/users 等其他页面时,它会给出如下错误消息:
The requested URL /test/users was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
我的 home.ctp 文件只有纯 HTML 代码,所以我想它工作正常。但是,转到其他具有 CakePHP 代码的站点,它似乎根本不起作用。请帮忙!
您应该尝试像这样更改 ./config/app.php
中的 App.base
参数:
'App' => [
// ...
'base' => '/test',
// ...
]
查看文档 here。
上传您的 .htaccess 文件。
不起作用的部分是将对 "pretty" URL(如 /users)的请求重写为对 PHP 脚本(如 /index.php?q=/users)的请求。 .htaccess 文件就是这样做的。