【问题标题】:cakePHP File not found when using http://www.example.com/controller使用 http://www.example.com/controller 时找不到 cakePHP 文件
【发布时间】:2011-11-26 21:28:04
【问题描述】:

我正在尝试在我的本地主机中安装 cakePHP。我使用 linux mint、Apache、MySQL

在 /etc/apache2 中,有文件夹 'conf.d'、'mods-available'、'mods-enabled'、'ports.conf'、'sites-available' 和 'sites-enabled'

由于我的 DocumentRoot 是 /var/www 但是,我想将 cakePHP 保留在 /home/works/ 中。 所以,

(1.) 我在 /etc/apache2/sites-enabled 中创建了一个文件名“cakephp”。

(2.) 然后,写

<VirtualHost *:80>
  DocumentRoot /home/works/cakephp/app/webroot
  ServerName local.ttt.cakephp
</VirtualHost>

(3.) 之后我编辑文件 /etc/hosts

127.0.0.1       localhost
127.0.0.1   local.ttt.cakephp

(4.) 试用网址:http://local.ttt.cakephp

结果:它正在工作并且 CSS 也已加载

(5.) 我尝试创建一个简单的控制器名称“测试”。 然后,试试 url:http://local.ttt.cakephp/Tests

结果:显示

Not Found
The requested URL /Tests was not found on this server.
Apache/2.2.17 (Ubuntu) Server at local.ttt.cakephp Port 80

我的解决方法:
(1.) 检查 apache2/mods-available 中的文件 rewrite.load 它有 LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so 并且没有注释 #

(2.) 将文件 apache2/sites-available/default 中的“AllowOverride None”更改为“AllowOverride All”
会是这个

<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

结果:它不起作用,仍然显示“未找到”页面。

有人知道我的错误吗? 非常感谢。

【问题讨论】:

  • 您应该使用 lowercase_underscore 作为 url 中的控制器和操作。但这对您的问题无关紧要。你重启 apache 了吗?

标签: cakephp


【解决方案1】:

你不应该改变目录路径:

<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

<Directory /home/works/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

【讨论】:

    【解决方案2】:

    1.) 将您的目录标签移动到您的 VirtualHost 标签内:

    <VirtualHost *:80>
    
        DocumentRoot /home/works/cakephp/app/webroot
        ServerName local.ttt.cakephp
    
        <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
        </Directory>
    
    </VirtualHost>
    

    2.) 更改目录标签的路径以匹配 DocumentRoot 的路径:

        <Directory /home/works/cakephp/app/webroot/>
    

    3.) 最后你应该有这样的东西:

    <VirtualHost *:80>
    
        DocumentRoot /home/works/cakephp/app/webroot
        ServerName local.ttt.cakephp
    
        <Directory /home/works/cakephp/app/webroot/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
        </Directory>
    
    </VirtualHost>
    

    4.) 这一切都假定 mod_rewrite 已启用。

    我很确定 Mint 有 a2enmod 命令,所以你可能想使用它:

    sudo a2enmod rewrite
    

    5.) 一定要重启 apache。

    sudo service apache2 restart
    

    sudo /etc/init.d/apache2 restart
    

    希望对你有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-16
      • 2020-04-13
      • 2016-11-03
      • 1970-01-01
      • 1970-01-01
      • 2012-08-21
      • 2016-05-09
      • 2015-10-30
      相关资源
      最近更新 更多