Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Zend framework sites on one server

I'm having trouble setting up my httpd.conf or .htaccess files to recognize multiple zend framework sites on one server.

For development, I have just one server and I'm trying to setup the sites so I can access them like localhost/app1, localhost/app2, etc.

So right now, when I go to localhost/app1 it does successfully redirect to localhost/app1/public/index.php, however when I go to localhost/app1/index/index I get a 404.

Here is my vhosts file:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot "/var/www"
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory "/var/www/app1/public">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
    ErrorLog logs/error.log
    CustomLog logs/access.log common
</VirtualHost>

and here is my .htaccess file from the /var/www/app1 directory:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ /app1/public/index.php [NC,R,L]

If I change the DocumentRoot line in the vhosts file to DocumentRoot "/var/www/app1/public" then app1 does work correctly, but I can only access that one... at http://localhost. Is this possible? What I want to happen is if /var/www is the document root, then if I go to localhost/app1, those requests need to redirect to localhost/app1/public/index.php and if I go to localhost/app2 those requests need to redirect to localhost/app2/public/index.php.

I hope I explained this clearly, any help is appreciated.

In the end
I liked Phil's solution best because I didn't want to have to change my local hosts file and use the ServerName directive. It would be fine in a production environment if you own a separate domain name for each app, but not for development.

In addition to that, I was having a 403 forbidden problem when using an alternate directory for serving up web content. As I stated, the perms seemed correct the problem was with SE_Linux, and the security context of the files not being set to httpd_sys_content_t. I'm posting that solution that i found here, as it deals specifically with the issue. Thanks.

like image 657
sudol Avatar asked Sep 27 '11 01:09

sudol


2 Answers

Here's what I'd do...

  1. Install your applications somewhere arbitrary but outside the document root, eg /home/sudol/apps/app1 and /home/sudol/apps/app2. Make sure your Apache user can traverse this path and read the files.

  2. Alias the public directories in your <VirtualHost> section

    Alias /app1 /home/sudol/apps/app1/public
    Alias /app2 /home/sudol/apps/app2/public
    
  3. Setup your access and rewrite rules in the appropriate <Directory> sections (one for each app), eg

    <Directory "/home/sudol/apps/app1/public">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    
        RewriteEngine On
        RewriteBase /app1
        RewriteCond %{REQUEST_FILENAME} -s [OR]
        RewriteCond %{REQUEST_FILENAME} -l [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^.*$ - [NC,L]
        RewriteRule ^.*$ index.php [NC,L]
    </Directory>
    
  4. Delete the .htaccess files as you will no longer need them

Addendum

Make sure you set unique session names in your application config. You can also set specific cookie paths but this is optional, eg

; app1/application/configs/application.ini
resources.session.name = "app1"
resources.session.cookie_path = "/app1/"

; app2/application/configs/application.ini
resources.session.name = "app2"
resources.session.cookie_path = "/app2/"
like image 57
Phil Avatar answered Nov 09 '22 23:11

Phil


Its better to use subdomain i.e app1.localhost then localhost/app1 . Since the way cookies are stored (including session cookie) can give you problem latter . They will mismatch or can even overlap .

Here is a good tutorial to setup the preferred way

http://www.dennisplucinik.com/blog/2007/08/16/setting-up-multiple-virtual-hosts-in-wamp/

like image 27
Mr Coder Avatar answered Nov 09 '22 23:11

Mr Coder