简体   繁体   English

在Apache2 / Cake PhP中定义文档根目录

[英]Defining Document Root in Apache2/Cake PhP

I have a broken Cake PHP site that I did not write, but am charged with fixing. 我有一个破碎的Cake PHP网站,我没有写,但我负责修复。 I have the main controller up, however no css/js/images, and when I click a link I get a 404 not found. 我有主控制器,但没有css / js /图像,当我点击链接时,我得到404未找到。 I believe something is incorrect with mod_rewrite or the docroot config in apache. 我相信mod_rewrite或apache中的docroot配置有些不对劲。

While reading through Cake documentation, I came across this: 在阅读Cake文档时,我发现了这个:

"app/webroot In a production setup, this folder should serve as the document root for your application. Folders here also serve as holding places for CSS stylesheets, images, and JavaScript files." “app / webroot在生产设置中,此文件夹应作为应用程序的文档根目录。此处的文件夹也可用作CSS样式表,图像和JavaScript文件的保留位置。”

In my /etc/apache2/sites-enabled/this-site, I see this: 在我的/ etc / apache2 / sites-enabled / this-site中,我看到了这个:

DocumentRoot /u02/data/docroots/this_site
    <Directory /u02/data/docroots/this_site>
            Options -Indexes
            AllowOverride none
            Order deny,allow
            Allow from all
    </Directory> 

So, my question: does the above config block need to have: /u02/data/docroots/this_site/app/webroot as the DocumentRoot and ? 所以,我的问题:上面的配置块是否需要:/ u02 / data / docroots / this_site / app / webroot作为DocumentRoot和?

Anywhere else you can think to look for troubleshooting this? 您可以考虑在其他任何地方寻找故障排除吗?

Since you have access to edit the apache config files - it's most appropriate to make a standard production install. 由于您可以编辑apache配置文件,因此最适合进行标准生产安装。

Fixing the docroot 修复docroot

does the above config block need to have: .../app/webroot as the DocumentRoot 以上配置块是否需要:... / app / webroot作为DocumentRoot

Assuming that path exists: yes. 假设路径存在:是的。

This will fix the broken css/js/images. 这将修复损坏的css / js / images。

Fixing mod rewrite 修复mod重写

Put the rewrite rules in the virtual host config: 将重写规则放在虚拟主机配置中:

DocumentRoot /u02/data/docroots/this_site/app/webroot
<Directory /u02/data/docroots/this_site/app/webroot>
        Options -Indexes
        AllowOverride none
        Order deny,allow
        Allow from all

        // added
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
</Directory> 

This will then route requests for anything that's not a file to the application. 然后,这将把对非任何文件的任何请求路由到应用程序。

Verify that the rewrite rule used is compatible with the version of CakePHP in use, the above is based on the rule for the latest release - it changed over the years and using the wrong rewrite rule may have unexpected side effects. 验证所使用的重写规则是否与正在使用的CakePHP版本兼容,以上是基于最新版本的规则 - 它多年来发生了变化 ,使用错误的重写规则可能会产生意想不到的副作用。

What's actually broken 究竟是什么打破了

AllowOverride none

This prevents the .htaccess files from being read by apache. 这可以防止apache读取.htaccess文件。 If you were to change this to AllowOverride all , and assuming the currently-ignored .htaccess files exist, the site would work - but as a development install. 如果您要将此更改为AllowOverride all ,并假设当前忽略的.htaccess文件存在,则该站点将起作用 - 但作为开发安装。

Try this: 试试这个:

<VirtualHost *:80>
ServerAdmin xxxxxx@test.ro
ServerName test.ro
ServerAlias www.test.ro
DirectoryIndex index.php
DocumentRoot /u02/data/docroots/this_site
ErrorLog /u02/data/docroots/this_site/error.log
CustomLog /u02/data/docroots/this_site/access.log combined

<Directory "/u02/data/docroots/this_site">
Options -Indexes FollowSymLinks MultiViews
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>

</VirtualHost>

And you should have 3 .htaccess files: 你应该有3个.htaccess文件:

/u02/data/docroots/this_site/app/webroot/.htaccess /u02/data/docroots/this_site/app/webroot/.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

/u02/data/docroots/this_site/app/.htaccess /u02/data/docroots/this_site/app/.htaccess

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule    ^$    webroot/    [L]
RewriteRule    (.*) webroot/$1    [L]
</IfModule>

/u02/data/docroots/this_site/.htaccess /u02/data/docroots/this_site/.htaccess

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

Hope this helps ;) 希望这可以帮助 ;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM