我想将 zend Framework 2 放在子文件夹中。骨架应用程序开箱即用,将整个应用程序放在子目录中,然后使用domain.com/path/to/public/index.php,但我想避免使用长网址,并且我不希望除公共(public)文件夹之外的所有其他内容都位于我的 DocumentRoot 中。
我考虑过拥有多个模块,但我的域下有其他类型的应用程序,并且不能将公共(public)文件夹作为 DocumentRoot,也不想重新创建我必须成为模块才能提供静态页面的所有内容。理想情况下,最好保留骨架应用程序使用的常规目录结构。
我正在使用带有 RHEL 和/或 CentOS 的典型 LAMP 堆栈。
最佳答案
我不知道这是否是最好的方法,但这是对我有用的方法。
Apache virtualhosts.conf(您可以将其放入 httpd.conf 中并进行一些修改):
<VirtualHost *:80>
ServerAdmin <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f18694939c9082859483b1959e9c90989fdf929e9c" rel="noreferrer noopener nofollow">[email protected]</a>
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
符号链接(symbolic link):
ln -s /var/www/zf2_app/public/ /var/www/html/apps/subdirectory
有几点需要注意:Directory 指令基于文件系统路径而不是 URI;这是 Apache 文档中的一行,我忘记了,因为如果您在 VirtualHost 指令中使用 mod_rewrite,它是基于 URI 的。此外,必须打开 Options FollowSymLinks 才能使符号链接(symbolic link)正常工作,并使 mod_rewrite 在目录指令中正常工作。
重新加载 httpd 后,我可以使用以下命令浏览到我的 zf2 应用程序: apps.domain.com/subdirectory/module
这使我能够保留常规的 zf2 骨架应用程序结构。另外,通过将它们放在一起,我可以使用 git(或其他源代码控制)进行推送,而不必将它们分开。
关于zend-framework2 - zend框架2在子目录中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14403071/