1

I'm hosting a website on Linux server and the folders is like that

/var/www/html/agitoriosul.com.br/web/

/web is the public folder

I want put core and app folder one leve before web folder and webroot inside web folder.

I know i need configure index.php inside webroot but i've tried a lot of things and nothing works.

Now all the folders is inside web(public folder) but, first i know core and app folder cant stay inside web(public folder), second, all links created with Html->link helper is pointing to physic path(/var/www/html/agitoriosul.com.br/web/) and not virtual(agitoriosul.com.br/) path.

Daniel Faria
  • 1,476
  • 5
  • 24
  • 45

2 Answers2

0

/web is the public folder

Therefore using the standard folder layou there would be the following:

/var/www/html/example.com
    app
        webroot
    lib
    plugins
    vendors

But instead want this:

/var/www/html/example.com
    app
    lib
    plugins
    vendors
    web

Move and edit

The steps to achieve that are pretty simple:

move the folder

with a command such as:

$ cd /var/www/html/example.com
$ mv app/webroot web

correct the ROOT path and APP_DIR constants

I.e. the web/index.php file would contain:

//define('ROOT', dirname(dirname(dirname(__FILE__))));
define('ROOT', dirname(dirname(__FILE__)));

//define('APP_DIR', basename(dirname(dirname(__FILE__))));
define('APP_DIR', 'app');
// cannot be derived, as the app folder is not a parent

Or, if preferred:

//define('ROOT', dirname(dirname(dirname(__FILE__))));
define('ROOT','/var/www/html/example.com');

//define('APP_DIR', basename(dirname(dirname(__FILE__))));
define('APP_DIR', 'app');

Alternatively

Don't move anything around, and just symlink the webroot like so:

/var/www/html/example.com
    app
        webroot
    lib
    plugins
    vendors
    web -> app/webroot

with a command such as:

$ cd /var/www/html/example.com
$ ln -s app/webroot web

This requires no modifications to the app webroot files.

AD7six
  • 63,116
  • 12
  • 91
  • 123
  • Webroot stay inside web(public folder) or just the content of webroot? i.e: web/webroot/**files here or web/**files here ? – Daniel Faria May 27 '14 at 12:36
  • I moved folders to stay exactly how you said and the site is working(good) but urls generatade with Html->link still pointing to physic path instead virtual path, if you access [this link](http://agitoriosul.com.br/home) you can follow what I'm saying. – Daniel Faria Jun 01 '14 at 14:41
  • I don't remember a specific cause for that it's down to [how the base url is determined](https://github.com/cakephp/cakephp/blob/1.3.18/cake/dispatcher.php#L317-L374) - it indicates an environment problem and is not likely to be directly related to the question. You can maybe ignore it and [force the base url](http://stackoverflow.com/a/23811073/761202) - or otherwise you'll need to identify why, apparently, your application thinks that it's root url is a file path. – AD7six Jun 01 '14 at 15:56
  • For my own piece of mind [I verified the above](https://gist.github.com/AD7six/fa70a71da6ce6b36e984) using the latest stable release. It does come to mind that there have been issues reported in the past for *old* versions of CakePHP (the question does not mention what version you're using) *if* the webroot is not in the app dir. – AD7six Jun 01 '14 at 18:19
-1

I have created two applications by using the same lib and plugins and vendors folder

Please see the folder structure as mentioned below:

Main Folder

/var/www/cake
/var/www/cake/lib
/var/www/cake/plugins
/var/www/cake/vendors

Application 1

/var/www/cake/cake1/app
/var/www/cake/cake1/webroot

Edits in:

/var/www/cake/cake1/webroot/index.php (only three edits)

if (!defined('ROOT')) {
    //define('ROOT', dirname(dirname(dirname(__FILE__))));
    define('ROOT', dirname(dirname(__FILE__)));
}

if (!defined('APP_DIR')) {
    //define('APP_DIR', basename(dirname(dirname(__FILE__))));
    define('APP_DIR', 'app');
}

define('CAKE_CORE_INCLUDE_PATH', dirname(dirname(dirname(__FILE__))) . DS . 'lib');

Application 2

/var/www/cake/cake2/app
/var/www/cake/cake2/webroot

Edits in:

/var/www/cake/cake2/webroot/index.php (only three edits)

if (!defined('ROOT')) {
    //define('ROOT', dirname(dirname(dirname(__FILE__))));
    define('ROOT', dirname(dirname(__FILE__)));
}

if (!defined('APP_DIR')) {
    //define('APP_DIR', basename(dirname(dirname(__FILE__))));
    define('APP_DIR', 'app');
}

define('CAKE_CORE_INCLUDE_PATH', dirname(dirname(dirname(__FILE__))) . DS . 'lib');

this is working for me for two virtual hosts on ubuntu

http://cake1/
http://cake2/
Vikram
  • 281
  • 1
  • 5
  • maybe I'm missing something - where in the question does it ask to handle multiple applications? It looks like you've put an answer to a completely different question -1. – AD7six May 27 '14 at 08:18