Multiple Zend framework sites on one server

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

For development, I have only one server, and I'm trying to configure sites so that I can access them, for example localhost / app1, localhost / app2, etc.

So, right now, when I go to localhost / app1, it successfully redirects to localhost / app1 / public / index.php, however, when I go to localhost / app1 / index / index, I get 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 / app 1 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 changed the DocumentRoot line in the vhosts file to DocumentRoot "/var/www/app1/public" , then application 1 will work correctly, but I can only access this ... in http: // localhost . Is it possible? I want it to be if / var / www is the document root, and then if I go to localhost / app1, these requests should be redirected to localhost / app1 / public / index.php, and if I go to localhost / app2 these requests must be redirected to localhost / app2 / public / index.php.

Hope I explained it clearly, any help is appreciated.

In the end
I liked Phil's solution in the best way because I did not want to change the local hosts file and use the ServerName directive. This would be good in a production environment if you have a separate domain name for each application, but not for development.

In addition to this, I had a 403 forbidden issue when using an alternate directory to serve web content. As I said, perms seemed correct, the problem was in SE_Linux, and in the security context of files that were not installed on httpd_sys_content_t. I am posting this solution that I found here , as it relates specifically to this problem. Thanks.

+6
source share
2 answers

Here is what I will do ...

  • Install your applications somewhere arbitrarily, but outside the document root, for example /home/sudol/apps/app1 and /home/sudol/apps/app2 . Make sure your Apache user can go this way and read the files.

  • List the public directories in the <VirtualHost> section

     Alias /app1 /home/sudol/apps/app1/public Alias /app2 /home/sudol/apps/app2/public 
  • Configure access and rewrite rules in the appropriate <Directory> sections (one for each application), for example

     <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> 
  • Delete the .htaccess files as you no longer need them.

Adding

Make sure you specify unique session names in the application configuration. You can also set specific cookie paths, but this is optional, for example

 ; 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/" 
+16
source

It is better to use the subdomain ie app1.localhost , then localhost/app1 . Since the way to save cookies (including the session cookie) may give you the last problem. They will be incompatible or may overlap.

Here is a good tutorial on setting your preferred method

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

+1
source

Source: https://habr.com/ru/post/898118/