新手 - 我需要如何处理 httpd.conf 才能使 CakePHP 正常工作?
(不确定这是否属于这里或网站管理员;如有必要,请移步。)
我是 Cake 的新手,对 apache 也好不到哪里去;我已经做了 很多 PHP,但总是使用已经设置好的服务器 他人。所以我正在学习基本博客教程,它 说:
关于 mod_rewrite 的注释 有时新用户会遇到 mod_rewrite 问题,所以我会 在这里稍微提一下它们。如果 Cake 欢迎页面看起来有点 有趣(没有图像或 css 样式),这可能意味着 mod_rewrite 不是 在您的系统上运行。这里有一些提示可以帮助您站起来并 运行:
确保允许 .htaccess 覆盖:在您的 httpd.conf 中, 您应该有一个部分为每个目录定义一个部分 你的服务器。确保将 AllowOverride 设置为 All 以获得正确的结果 目录。
确保您正在编辑系统 httpd.conf 而不是用户或 站点特定的 httpd.conf。
由于某种原因,您可能已经获得了 CakePHP 的副本 没有所需的 .htaccess 文件。有时会发生这种情况,因为 某些操作系统处理以“.”开头的文件作为隐藏的,并且 不要复制它们。确保您的 CakePHP 副本来自下载 网站或我们的 SVN 存储库的部分。
确保您正确加载 mod_rewrite!你应该看到 类似 LoadModule rewrite_module libexec/httpd/mod_rewrite.so 和 httpd.conf 中的 AddModule mod_rewrite.c。”
我在 Linux 上使用 XAMPP。我在 opt/lampp/ 中找到了我的 httpd.conf 文件 等等,但不确定我需要用它做什么。我已经寻找过 “rewrite”,只有一行:
LoadModule rewrite_module module/mod_rewrite.so
AddModule mod_rewrite.c 没有任何内容。
我是否只为我安装的目录创建一个目录部分 合并并将 AlllowOverride 设置为 All? (我创建了一个单独的 我的 wwwroot 的子目录并安装在那里,因为我也有 安装 Joomla 和 CodeIgniter。)还有什么我需要的吗 做?我下载的 Cake 确实附带了两个 htaccess 类型的文件 (._.htaccess 和 .htaccess) - 我需要对它们做些什么吗?
感谢您为这位非服务器管理员提供的任何帮助。
编辑以添加虚拟主机示例:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /www/docs/dummy-host.example.com
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
(Not sure if this belongs here or on webmasters; please move if necessary.)
I'm a total newbie to Cake and not much better with apache; I've done
a lot of PHP but always with a server that's already been set up by
someone else. So I'm going through the basic blog tutorial, and it
says:
A Note On mod_rewrite
Occasionally a new user will run in to mod_rewrite issues, so I'll
mention them marginally here. If the Cake welcome page looks a little
funny (no images or css styles), it probably means mod_rewrite isn't
functioning on your system. Here are some tips to help get you up and
running:Make sure that an .htaccess override is allowed: in your httpd.conf,
you should have a section that defines a section for each Directory on
your server. Make sure the AllowOverride is set to All for the correct
Directory.Make sure you are editing the system httpd.conf rather than a user- or
site-specific httpd.conf.For some reason or another, you might have obtained a copy of CakePHP
without the needed .htaccess files. This sometimes happens because
some operating systems treat files that start with '.' as hidden, and
don't copy them. Make sure your copy of CakePHP is from the downloads
section of the site or our SVN repository.Make sure you are loading up mod_rewrite correctly! You should see
something like LoadModule rewrite_module libexec/httpd/mod_rewrite.so
and AddModule mod_rewrite.c in your httpd.conf."
I'm using XAMPP on linux. I've found my httpd.conf file in opt/lampp/
etc, but am not sure what I need to do with it. I've searched for
"rewrite", and there's only one line:
LoadModule rewrite_module modules/mod_rewrite.so
There's nothing about AddModule mod_rewrite.c.
Do I just create a Directory section for the directory I've installed
Cake in and set AlllowOverride to All? (I created a separate
subdirectory of my wwwroot and installed in there, since I also have
installs of Joomla and CodeIgniter.) Is there anything else I need to
do? My download of Cake did come with two htaccess-type files
(._.htaccess and .htaccess) - do I need to do anything with them?
Thanks for any help you can provide to this non-server-admin.
EDIT TO ADD virtual host sample:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /www/docs/dummy-host.example.com
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
步骤 1. 您应该启用 mod_rewrite,使用
检查
步骤 2. 检查 AllowOverride
步骤 3. 检查您的默认
.htaccess
文件是否存在目录/mypro
、/mypro/app
、/mypro/app/webroot
。步骤 4.
.htaccess
可能需要修复路径,具体取决于您的 cake 项目安装。编辑
如果您尝试将其设置为本地域,请设置配置了 WAMP 的本地域(在 Windows 上)
注意:这可能会针对不同类型的安装进行一些调整
找到你的hosts文件(我的位于C:\WINDOWS\system32\drivers\etc\hosts)
将其插入底部
要测试主机名,请打开命令提示符并运行 ping mypro.localhost
# If ping is good then move on
保存并关闭文件
创建目录 C:/wamp/www/mypro (如果您没有) t之前创建)
Step 1. You should have mod_rewrite enabled, check using
<?php phpinfo();
Step 2. Check AllowOverride
Step 3. Check your default
.htaccess
files are there in directories/mypro
,/mypro/app
,/mypro/app/webroot
.Step 4.
.htaccess
may need path fixes depending upon your cake project installation.EDIT
If you are trying to setup it as local domains, Setup local domains (on windows) with WAMP configured
Note: this may be tweaked a little for different kind of installations
Find your hosts file (mine is located at C:\WINDOWS\system32\drivers\etc\hosts)
Insert this to bottom
To test hostname open command prompt and run ping mypro.localhost
# If ping is good then move on
Save and close files
Create directory C:/wamp/www/mypro (if you haven’t created before)
ModRewrite 使 Apache 能够在处理请求之前操作请求 URL。例如,如果您想将图像存储在
/website_images
中,但希望在 HTML 中将它们引用为/img/donkey.jpg
,您可以使用 ModRewrite 来更改所有内容从/img/*
到/website_images/*
的请求。它处理这个问题的方式是通过正则表达式,有整本书都是关于正则表达式的。就 Apache 而言,有很多配置“指令”(也称为选项或设置)。当您运行自己的服务器时,最需要了解的最重要的是虚拟主机。它们允许 Apache 处理对服务器 IP 地址的请求,并根据主机名(本质上是域)将它们路由到正确的网站。您应该将任何特定于网站的指令放置在该网站的 VirtualHost 配置中,包括您的 ModRewrite 规则。注意:您还可以从网站目录中的 .htaccess 文件加载其他指令,但这并不是最理想的(并且需要设置AllowOverride)。如果您有权访问httpd.conf 和相关的VirtualHost 指令,则应该使用它们。
看起来 Apache 已经配置为加载 ModRewrite 模块,因此您无需更改新 CakePHP 网站的 VirtualHost 指令,您可以在
设置 ModRewrite:它看起来又大又吓人,但它的作用是告诉 Apache 将所有它无法处理的请求(因为资源不存在)定向到 index.php当这种情况发生时,CakePHP 会接管并将请求路由到适当的控制器和操作,
我不熟悉 XAMPP 的配置方式,因此我无法告诉您这些 VirtualHost 定义可能在哪里。在这里插话……
ModRewrite enables Apache to manipulate request URLs before it handles the request. For example, if you wanted to store your images in
/website_images
but you wanted to reference them in your HTML as/img/donkey.jpg
you could use ModRewrite to change all requests from/img/*
to/website_images/*
. The way that it handles this is through Regular Expressions, which have entire books written about them.As far as Apache goes, there are lots of configuration "directives" (aka options or settings). The most crucial to learn about when you're running your own server are going to be the VirtualHost ones. They allow Apache to handle requests to your server's IP address and route them to the correct website based on the hostname (the domain, essentially). You should place any website-specific directives within that website's VirtualHost configuration, including your ModRewrite rules. Note: you can also load additional directives from a .htaccess file in the website's directory, but this is suboptimal (and requires AllowOverride to be set. If you have access to httpd.conf and the related VirtualHost directives, you should use them instead.
It looks like Apache is already configured to load the ModRewrite module, so you don't need to change that. In the VirtualHost directives for your new CakePHP website, you can use the following directives under the
<Directory /path/to/your/website>
to setup ModRewrite:It looks big and scary, but what that does is tells Apache to direct all requests that it can't handle (because the resources don't exist) to index.php. When that happens, CakePHP takes over and routes the request to the appropriate controller and action.
I'm not familiar with how XAMPP is configured, so I can't tell you where those VirtualHost definitions are going to be. Perhaps someone else can chime in here…