子目录中的 Zend 框架 2 [英] zend framework 2 in a subdirectory

查看:30
本文介绍了子目录中的 Zend 框架 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 zend framework 2 放在子文件夹中.通过将整个应用程序放在一个子目录中,然后使用 domain.com/path/to/public/index.php,框架应用程序开箱即用,但我想避免使用长网址,我不想要除了我的公共文件夹之外,其他所有东西都在我的 DocumentRoot 中.

I want to put zend framework 2 in a subfolder. The skeleton app works out of the box by putting the whole app in a sub-directory and then using domain.com/path/to/public/index.php, but I want to avoid having the long url and I don't want everything else to be in my DocumentRoot other than my public folder.

我想拥有多个模块,但我的域下还有其他类型的应用程序,并且不能将公共文件夹设为 DocumentRoot 也不想重新创建所有我必须成为模块才能提供静态页面的内容.理想情况下,最好保留骨架应用程序使用的常规目录结构.

I thought about having multiple modules, but I have other types of applications under my domain and can't have the public folder be the DocumentRoot nor do I want to recreate everything I have to be a module just to serve a static page. Ideally, it would be nice to keep the regular directory structure that the skeleton app uses.

我在 RHEL 和/或 CentOS 中使用典型的 LAMP 堆栈.

I'm using a typical LAMP stack with RHEL and/or CentOS.

推荐答案

我不知道这是否是最好的方法,但这是一种对我有用的方法.

I don't know if this is the best way, but this is a way that worked for me.

Apache virtualhosts.conf(你可以把它放在 httpd.conf 中,稍作修改):

Apache virtualhosts.conf (you could put this in httpd.conf with a few modifications):

<VirtualHost *:80>
    ServerAdmin webmaster@domain.com
    DocumentRoot /var/www/html/apps
    ServerName apps.domain.com:80
    ServerAlias www.apps.domain.com
    UserDir Disabled
    ErrorLog logs/domain_error_log
    Options FollowSymLinks

    <Directory /var/www/html/apps/subdirectory/>
            #same stuff in standard zf2 .htaccess file
            RewriteEngine on
            RewriteCond %{REQUEST_FILENAME} -s [OR]
            RewriteCond %{REQUEST_FILENAME} -l [OR]
            RewriteCond %{REQUEST_FILENAME} -d
            RewriteRule ^.*$ - [NC,L]
            RewriteRule ^.*$ index.php [NC,L]
    </Directory>

应用位置:

/var/www/zf2_app

符号链接:

ln -s /var/www/zf2_app/public/ /var/www/html/apps/subdirectory

需要注意的几点:Directory 指令基于文件系统路径而不是 URI;这是我忘记的 Apache 文档中的一行,因为如果您在 VirtualHost 指令中使用 mod_rewrite 它基于 URI.此外,选项 FollowSymLinks 必须打开,符号链接才能工作,并且 mod_rewrite 才能在目录指令中工作.

A couple of things to note: The Directory directive is based off the filesystem path not the URI; it is a one line in the Apache documentation that I forget because if you are using mod_rewrite in the VirtualHost directive it is based off of the URI. Also, Options FollowSymLinks must be on for the symlink to work and for mod_rewrite to work in a directory directive.

重新加载 httpd 后,我可以使用以下命令浏览到我的 zf2 应用程序:apps.domain.com/subdirectory/module

After I reloaded httpd, I was able to browse to my zf2 app using: apps.domain.com/subdirectory/module

这使我能够保留常规的 zf2 框架应用程序结构.此外,通过将它们放在一起,我可以使用 git(或其他源代码控制)进行推送,而无需拆分.

This allowed me to keep the regular zf2 skeleton app structure. Also, by keeping it together, I can use git (or other source control) to push without having to split things up.

这篇关于子目录中的 Zend 框架 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆