Reputation: 611
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.
Upvotes: 2
Views: 2048
Reputation: 1284
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]
....
...
Upvotes: 0
Reputation: 41
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 [email protected]
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.
Upvotes: 3