how to configure virtual hosts for cakephp on ubuntu server 12.04 LTS with apache 2

3

I have problems in having two web app running on the same server. The error shown is:

Missing Controller

Error: SchoolController could not be found.

Error: Create the class SchoolController below in file: app/Controller/SchoolController.php

<?php
class SchoolController extends AppController {

}

Notice: If you want to customize this error message, create app/View/Errors/missing_controller.ctp
Stack Trace

    APP/webroot/index.php line 110 → Dispatcher->dispatch(CakeRequest, CakeResponse)

The configuration file is the following:

virtual host 1

<VirtualHost *:80>
    ServerName localhost
    ServerAlias localhost1
    DocumentRoot /var/www/webapp1/app/webroot

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    <Directory /var/www/webapp1/app/webroot>
         Options -Indexes
            AllowOverride none
         Order deny,allow
            Allow from all

            RewriteEngine On
         RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^ index.php [L]
    </Directory> 


       #Mod_Rewriter
       RewriteEngine on
    RewriteRule ^index\.html$ /index.php [L]


    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

virtual host 2

<VirtualHost *:80>
    ServerName localhost
    ServerAlias localhost2
    DocumentRoot /var/www/webapp2/app/webroot

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    <Directory /var/www/webapp2/app/webroot>
         Options -Indexes
            AllowOverride none
         Order deny,allow
            Allow from all

            RewriteEngine On
         RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^ index.php [L]
    </Directory> 


       #Mod_Rewriter
       RewriteEngine on
    RewriteRule ^index\.html$ /index.php [L]


    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>
    
asked by mark 15.06.2016 в 18:09
source

1 answer

1

In general, each web server has a unique identification formed by the IP address and by the port that listens to the requests of the users (there is a third identifier element that is the protocol). This means that there can only be one server in each IP: Port combination.

In your configuration, the first line of both virtual servers

<VirtualHost *:80>

says something like "listen to port 80 of all the addresses that exist on this server" , these addresses can be real or virtual. But note, that they both hear the same port .

The second line, of both servers , is as follows:

ServerName localhost

that indicates the server address.

Remember that localhost is not an ordinary name, it refers to your own machine with an easily recognizable name that corresponds to the IP 127.0.0.1 .

Now yes, both virtual servers have the same address and listen to the same port:

127.0.0.1:80

That's why when you ask for the second site you can not see anything, because the first one to listen to the request is the one who attends it.

The solution is to change the port of the second virtual server or if you have another IP address,

<VirtualHost *:80>
  ServerName localhost
  ServerAlias localhost1
  DocumentRoot /var/www/webapp1/app/webroot

  # El resto de directivas
</VirtualHost>

<VirtualHost *:88>
  ServerName localhost
  ServerAlias localhost2
  DocumentRoot /var/www/webapp2/app/webroot

  # El resto de directivas
</VirtualHost>

In case you have two IP addresses on your server, you can use the same port (in this case 80, which is the standard), but you have to specify the IP of each virtual server.

<VirtualHost 10.0.0.1:80>
  ServerName 10.0.0.1
  ServerAlias localhost1
  DocumentRoot /var/www/webapp1/app/webroot
  # El resto de directivas
</VirtualHost>

Remember that changing the listening port of your virtual server can change the programming of your site. Identify the changes you need to make.

    
answered by 16.06.2016 в 21:52