CakePHP菜鸟问题,请求的URL /pages/andy 在此服务器上找不到
我是第一次安装 CakePHP,我在 Ubuntu 10.04LTS 上运行 LAMP。我不仅是一名 CakePHP 菜鸟,也是一名 Linux 菜鸟。我在网上找到了安装说明,我认为我已经正确设置了所有内容。当我转到 localhost 时,我得到默认的 CakePHP 页面,一切都是绿色的。
问题是当我在 /var/www/app/views/pages 文件夹中创建一个名为 andy.ctp 的通用页面时,当我尝试转到 localhost/pages/andy 时,我得到一个 404 NOT FOUND 页面,上面写着“请求的内容”在此服务器上找不到 URL /pages/andy。”
我确信我在初始设置中错过了一些东西,我只是找不到什么。我已经用谷歌搜索了这个错误,但还没有找到任何可以帮助我的东西。下面是我的默认文件。如果您还需要查看其他内容,请告诉我。感谢您提前的帮助!
.htaccess 文件中是否有某些内容可能需要更改?
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/app/webroot
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
I am installing CakePHP for the first time, I am running LAMP on Ubuntu 10.04LTS. Not only am I a CakePHP rookie, I am a Linux rookie as well. I found installation instructions online and I thought i had everything setup correctly. When i go to localhost i get the default CakePHP page and everything is green.
The problem is when i created a generic page called andy.ctp in the /var/www/app/views/pages folder, when i try to go to localhost/pages/andy I get a 404 NOT FOUND page that says "The requested URL /pages/andy was not found on this server."
I am sure i missed something on the initial setup, i just cant find out what. I have Googled the error and have yet to find anything to get me along. Below is my default file. Please let me know if there is anything else you need to see. Thanks for the help in advance!
is there something in the .htaccess file that might need to be changed?
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/app/webroot
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
让我们先尝试一些事情:
您是否将整个 CakePHP 包安装在同一个目录下。我这么说是因为我看到你有
/var/www/app
,并且 cake 目录也必须在/var/www/
内。即使您拥有这些目录,我也建议您将整个 CakePHP 包设置到另一个子目录中,例如/var/www/your_project/app
。这将使您能够随着时间的推移轻松添加更多项目。 可能希望将文档根目录设置为主目录(即/home/your_name/www/your_project
,以便您可以更轻松地处理文件权限。你是否启用了 mod_rewrite? 进行 Google 搜索;有很多教程。
让我知道这些是否有效。
追问:
您好。
如果您看到带有所有绿色通知的默认 CakePHP 起始页 (看到这个旧的屏幕截图),那么这意味着你的 mod_rewrite 或 htaccess 没有任何问题。但是,我重现了您在虚拟主机配置文件中执行的步骤,并发现了两个问题:
1)您将 DocumentRoot 指向
/var/www/app/webroot
,而它应该指向顶部 -级别目录,在本例中为/var/www/
(即CakePHP 最顶层index.php 所在的目录)。另外,请务必使用此指令:DirectoryIndex index.php
2) 您没有关闭
标记;虽然这实际上可能是错误的复制+粘贴,所以总的来说,尝试从几行开始“调试”您的 VirtualHost 文件,这样您就不必担心配置错误。我将这几个项目用于本地计算机中的任何项目,并且我有多个 CakePHP 项目都在 Apache for Ubuntu 下运行。
服务器名称 dummysite.com
ServerAdmin [电子邮件受保护]
DocumentRoot“/home/yamir/Programming/Projects/dummysite”
目录索引index.php
日志级别警告
错误日志“/home/yamir/Programming/Projects/dummysite/logs/error.log”
CustomLog“/home/yamir/Programming/Projects/dummysite/logs/access.log”组合
Let's try a few things first:
Do you have the whole CakePHP package installed under one same directory. I say so because I saw you have
/var/www/app
, and the cake directory must also be within/var/www/
. Even when you have these directories allright, I recommend that you set the whole CakePHP package into another subdirectory, like/var/www/your_project/app
. This will enable you to add more projects easily as time go. Also, you might want to set the Document Root to a home-level directory (i.e./home/your_name/www/your_project
so that you can handle file permissions more easy.Do you have mod_rewrite enabled? It is required by Cake. Do a Google search; there are plenty of tutorials.
Let me know if any of these work.
Followup:
Hello again.
If you are seeing the default CakePHP start page with all green notices (see this old screenshot), then it means that you dont have anything wrong with mod_rewrite or htaccess. However, I reproduced the steps you took along with your virtualhost configuration file and found two issues:
1) You are pointing the DocumentRoot to
/var/www/app/webroot
when it should point to the top-level directory, in this case/var/www/
(i.e. the directory where CakePHP's topmost index.php is). Also, be sure to have this directive:DirectoryIndex index.php
2) You are not closing the
<VirtualHost>
tag; though this can actually be a wrong copy+paste here in S.O.Overall, try to 'debug' your VirtualHost file by starting with just a few lines so that you have to worry less about misconfigurations. I use these few for any project in my local machine, and I've had multiple CakePHP Projects all running under Apache for Ubuntu.
<VirtualHost dummysite.com:80>
ServerName dummysite.com
ServerAdmin [email protected]
DocumentRoot "/home/yamir/Programming/Projects/dummysite"
DirectoryIndex index.php
LogLevel warn
ErrorLog "/home/yamir/Programming/Projects/dummysite/logs/error.log"
CustomLog "/home/yamir/Programming/Projects/dummysite/logs/access.log" combined
</VirtualHost>
你确定开启了mod_rewrite吗?
Have you definitely turned on mod_rewrite?