# Remove cakephp 3.4 from webroot how to

**URL:** <https://discourse.cakephp.org/t/remove-cakephp-3-4-from-webroot-how-to/2335>\
**Category:** Uncategorized\
**Created:** [April 1, 2017, 8:23pm UTC](https://discourse.cakephp.org/t/remove-cakephp-3-4-from-webroot-how-to/2335 "2017-04-01T20:23:26Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimgwhit](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jimgwhit/32/378_2.png) [@jimgwhit](https://discourse.cakephp.org/u/jimgwhit)\
**Post date:** [April 1, 2017, 8:23pm UTC](https://discourse.cakephp.org/t/remove-cakephp-3-4-from-webroot-how-to/2335/1 "2017-04-01T20:23:26Z")

</div>

The documentation does not cover this. How do you remove cakephp from webroot (server webroot, not talking about cakephp webroot), having only the public files under webroot. By webroot I mean, lets us laravel as example and what is done

Here is sample folder structure +++++= a subfolder

apache2  
++++++laravel51  
htdocs  
++++++larpubfolder

in other words htdocs/larpubfolder

so laravel51 is main files out of webroot (htdocs is webroot in apache), directly under apache2

And in larpubfolder is the .htaccess and index.php file

Now how to do this for cakephp 3.4 and what files need modified?

As unbelievable as it sounds, there is nothing on the web about properly moving cakephp (not old version) out of webroot.

Here is laravel example: [https://laravel-news.com/subfolder-install](https://laravel-news.com/subfolder-install)

Mainly what files to modify and how?

---

<div class="post-metadata">

**Author:** ![McScreech](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/mcscreech/32/465_2.png) [@McScreech](https://discourse.cakephp.org/u/McScreech)\
**Post date:** [April 6, 2017, 4:12pm UTC](https://discourse.cakephp.org/t/remove-cakephp-3-4-from-webroot-how-to/2335/2 "2017-04-06T16:12:16Z")

</div>

this is a method i’ve been using since cakePHP 1.2 daze - of course YMMV:

[NOTES]

- these are my NTS (Notes To Self), as such they are changing over time and you MUST intelligently scan and make changes to suit your own local folder/file structure

- i have not looked at this in about a year, so i cannot speak to changes since then that may break it

- pay attention to [xxx NEED CONFIRM xxx] \*\*\* [/xxx NEED CONFIRM xxx] tags where i have not followed thru with full testing of an idea.

- most of the time i will include variable parts inside square brackets, i.e., [ver] for multiple versions of cake

- step 3) is my trace of sorting out paths and the like, i present it this way (rather than simply spelling out changes) to show HOW i sorted things out - THESE ARE EXAMPLES, change to suit your environment. that said, i do list required changes made by listing the error, commenting out the original line and adding the modified line

- some error logs may be in different places as stated in your php.ini and httpd.conf files

---

<div class="post-metadata">

**Author:** ![jimgwhit](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jimgwhit/32/378_2.png) [@jimgwhit](https://discourse.cakephp.org/u/jimgwhit)\
**Post date:** [April 6, 2017, 4:31pm UTC](https://discourse.cakephp.org/t/remove-cakephp-3-4-from-webroot-how-to/2335/3 "2017-04-06T16:31:34Z")

</div>

@McScreech Thanks for answer, I had even saw something similar on stackoverflow where they had changed bootstrap locale

```auto
require dirname(dirname( __DIR__ )) . '/apps/' . basename( __DIR__ ) . '/config/bootstrap.php';

```

But the later versions don’t have such a call: here is the index.php

```auto
<?php
if (php_sapi_name() === 'cli-server') {
    $_SERVER['PHP_SELF'] = '/' . basename( __FILE__ );

    $url = parse_url(urldecode($_SERVER['REQUEST_URI']));
    $file = __DIR__. $url['path'];
    if (strpos($url['path'], '..') === false && strpos($url['path'], '.') !== false && is_file($file)) {
        return false;
    }
}
require dirname( __DIR__ ) . '/../../cake34up/vendor/autoload.php';

use App\Application; ///////////These 2 lines mess things up as main cakephp is in higher folder
use Cake\Http\Server;

// Bind your application to the server.
$server = new Server(new Application(dirname( __DIR__ ) . '/../../cake34up/config'));

// Run the request/response through the application
// and emit the response.
$server->emit($server->run());

```

As you can see I tryed to repoint to the vendor and config folder, get nothing but a 500 error.  
I will go through your answer and try again, thanks.

I wish cakephp had a simple index.php thay you could just point to main install with

```auto
/../../then whatever here

```

---

<div class="post-metadata">

**Author:** ![fiblan](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/fiblan/32/594_2.png) [@fiblan](https://discourse.cakephp.org/u/fiblan)\
**Post date:** [April 11, 2017, 10:47pm UTC](https://discourse.cakephp.org/t/remove-cakephp-3-4-from-webroot-how-to/2335/4 "2017-04-11T22:47:47Z")

</div>

i don’t like it… but you can change constant CAKE\_CORE\_INCLUDE\_PATH in app/config/paths.php

---

<div class="post-metadata">

**Author:** ![jimgwhit](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jimgwhit/32/378_2.png) [@jimgwhit](https://discourse.cakephp.org/u/jimgwhit)\
**Post date:** [April 12, 2017, 1:30am UTC](https://discourse.cakephp.org/t/remove-cakephp-3-4-from-webroot-how-to/2335/5 "2017-04-12T01:30:07Z")

</div>

> [@fiblan](#):
>
> CAKE\_CORE\_INCLUDE\_PATH

I had tried changing values in paths. But the above index file is the very first loaded file, can’t get around those two use statements.

---

<div class="post-metadata">

**Author:** ![dakota](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dakota/32/1421_2.png) [@dakota](https://discourse.cakephp.org/u/dakota)\
**Post date:** [April 12, 2017, 9:33am UTC](https://discourse.cakephp.org/t/remove-cakephp-3-4-from-webroot-how-to/2335/6 "2017-04-12T09:33:55Z")

</div>

It’s right there in the documentation: [https://book.cakephp.org/3.0/en/installation.html#production](https://book.cakephp.org/3.0/en/installation.html#production)

---

<div class="post-metadata">

**Author:** ![fiblan](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/fiblan/32/594_2.png) [@fiblan](https://discourse.cakephp.org/u/fiblan)\
**Post date:** [April 12, 2017, 1:34pm UTC](https://discourse.cakephp.org/t/remove-cakephp-3-4-from-webroot-how-to/2335/7 "2017-04-12T13:34:55Z")

</div>

@dakota jimgwhit wants a single vendor directory for multiple cake applications

---

<div class="post-metadata">

**Author:** ![fiblan](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/fiblan/32/594_2.png) [@fiblan](https://discourse.cakephp.org/u/fiblan)\
**Post date:** [April 12, 2017, 1:39pm UTC](https://discourse.cakephp.org/t/remove-cakephp-3-4-from-webroot-how-to/2335/8 "2017-04-12T13:39:18Z")

</div>

> [@jimgwhit](#):
>
> I had tried changing values in paths. But the above index file is the very first loaded file, can’t get around those two use statements.

You also have to change webroot/index.php (vendor path)

---

<div class="post-metadata">

**Author:** ![dakota](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dakota/32/1421_2.png) [@dakota](https://discourse.cakephp.org/u/dakota)\
**Post date:** [April 12, 2017, 1:44pm UTC](https://discourse.cakephp.org/t/remove-cakephp-3-4-from-webroot-how-to/2335/9 "2017-04-12T13:44:54Z")

</div>

> [@fiblan](#):
>
> jimgwhit wants a single vendor directory for multiple cake applications

That is a very very bad idea and will do nothing but cause issues in the future. You want a separate vendor directory for each application, otherwise you’ll always struggle with upgrading dependencies. Storage space is cheap 🙂

---

<div class="post-metadata">

**Author:** ![jimgwhit](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jimgwhit/32/378_2.png) [@jimgwhit](https://discourse.cakephp.org/u/jimgwhit)\
**Post date:** [April 12, 2017, 5:30pm UTC](https://discourse.cakephp.org/t/remove-cakephp-3-4-from-webroot-how-to/2335/10 "2017-04-12T17:30:16Z")

</div>

No it’s one application, I just want to move main files out of htdocs. Like a laravel install for security.  
The folder structure from docs shows

```auto
/cake_install/
    bin/
    config/
    logs/
    plugins/
    src/
    tests/
    tmp/
    vendor/
    webroot/ //////Only folder I want under htdocs all other above htdocs.
    .gitignore
    .htaccess
    .travis.yml
    composer.json
    index.php
    phpunit.xml.dist
    README.md

```

Main cake is under htdocs, it looks like.

I want webroot (the cake one) under htdocs and main cake files out of htdocs one folder higher “even” with apache folder. Seems there would be good instructions on this somewhere.

---

<div class="post-metadata">

**Author:** ![fiblan](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/fiblan/32/594_2.png) [@fiblan](https://discourse.cakephp.org/u/fiblan)\
**Post date:** [April 13, 2017, 9:02pm UTC](https://discourse.cakephp.org/t/remove-cakephp-3-4-from-webroot-how-to/2335/11 "2017-04-13T21:02:52Z")

</div>

> [@jimgwhit](#):
>
> I want webroot (the cake one) under htdocs and main cake files out of htdocs one folder higher “even” with apache folder. Seems there would be good instructions on this somewhere.

Why can’t you change DocumentRoot to webroot as written[in the documentation](https://book.cakephp.org/3.0/en/installation.html#production6) and remembered by dakota?

In production, with Apache, the best solution is already described in The Cookbook but if you _must_ (?) mantain DocumentRoot to htdocs… install cake out htdocs and use Alias directive to map webroot.
