zend framework 2 in a subdirectory

放肆的年华 提交于 2019-12-11 03:53:55

问题


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.

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.

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


回答1:


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

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>

Location for app:

/var/www/zf2_app

Symlink:

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

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.

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

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.




回答2:


I had added the environment variable in the .htaccess file like this, set the first line of your .htaccess with the ZF2_PATH environment variable (which is at the root of your application folder)

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


来源:https://stackoverflow.com/questions/14403071/zend-framework-2-in-a-subdirectory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!