【问题标题】:zend framework 2 in a subdirectoryzend framework 2 在子目录中
【发布时间】:2013-01-20 02:09:46
【问题描述】:

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

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

我正在使用带有 RHEL 和/或 CentOS 的典型 LAMP 堆栈。

【问题讨论】:

  • 所以你想保留 Skeleton-Structure 只是一个简短的 url,就这样吗?
  • 好吧,基本上文件存储在哪里都没关系,您只需要配置您的 Apache 以将您的 VirtualHost 设置为公共目录。然后您需要做的就是致电domain.com。我不喜欢 linux,所以我不能给你指示,但对我来说,这似乎就是你要找的全部
  • 我认为可以通过符号链接来完成
  • 我在 DocumentRoot 中有其他应用程序,想将其添加到子目录下。
  • Other app表示其他域,其他域表示其他VirtualHost?

标签: zend-framework2 subdirectory


【解决方案1】:

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

Apache virtualhosts.conf(您可以将其放入 httpd.conf 并稍作修改):

<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 的。此外,必须打开 Options FollowSymLinks 符号链接才能工作,并且 mod_rewrite 才能在目录指令中工作。

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

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

【讨论】:

    【解决方案2】:

    我已经像这样在 .htaccess 文件中添加了环境变量,将 .htaccess 的第一行设置为 ZF2_PATH 环境变量(位于应用程序文件夹的根目录)

    SetEnv ZF2_PATH /home/homefolder/zendpath
    RewriteEngine On
    RewriteRule ^\.htaccess$ - [F]
    ....
    ...
    

    【讨论】:

    • 我认为这可以改变 Zend 库的位置,但我想将我的整个应用程序放在一个子目录中。
    猜你喜欢
    • 2016-03-17
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 2013-03-06
    • 1970-01-01
    • 2014-05-02
    • 1970-01-01
    • 2011-10-10
    相关资源
    最近更新 更多