【发布时间】:2018-11-22 02:10:56
【问题描述】:
我的 cakephp 项目在 localhost 上运行良好,但当我将其上传到托管服务器时无法运行。
这是我在托管服务器的 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'));
完成此操作后,当我打开 website.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 代码的网站,它似乎根本不起作用。请帮忙!
【问题讨论】:
-
您是否上传了定义必要 URL 重写规则的 .htaccess 文件?
-
@Joni 不,我不知道有一个 .htaccess 文件。有必要吗?
-
您的自动加载是否已针对主机目录设置进行了更新?
-
@Greg 我没有更改我的 autoload.php 文件中的任何内容。
标签: php cakephp cpanel cakephp-3.x