# Cake app running on WAMP sever vs bin\\cake server problems

**URL:** <https://discourse.cakephp.org/t/cake-app-running-on-wamp-sever-vs-bin-cake-server-problems/8708>\
**Category:** Need Help\
**Created:** [December 7, 2020, 10:45pm UTC](https://discourse.cakephp.org/t/cake-app-running-on-wamp-sever-vs-bin-cake-server-problems/8708 "2020-12-07T22:45:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rboatright](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rboatright/32/2060_2.png) [@rboatright](https://discourse.cakephp.org/u/rboatright)\
**Post date:** [December 7, 2020, 10:45pm UTC](https://discourse.cakephp.org/t/cake-app-running-on-wamp-sever-vs-bin-cake-server-problems/8708/1 "2020-12-07T22:45:30Z")

</div>

Before we start, I have searched and read for hours both on this discourse and various google searches about deploying Cake apps. I fully understand that Cake is designed to use mod\_rewrite and that what I am trying to do SHOULD just work. I have read the bits about setting RewriteBase, nothing I have tried from that reading has accomplished anything.

In any event, I tried before I posted here, really I did. I have a fully running app, but I’m having trouble deploying it.

Running Cake version **4.1.6** PHP **7.4.9** Apache **2.4.46** WAMP server **3.2.3 64bit** on Windows 10

The Cake app is in \wamp64\www\myapp

If in command I cd there and type bin\cake server the server starts up and everything works just excellently. I browse to

`http://localhost:8765`  
and the system redirects (as it should) to  
`http://localhost:8765/users/login?redirect=%2Fmyapp%2F`  
and the entire app runs as it should. I can log in, list, edit, view, page, all that good stuff. Very nice. I have not used Cake before but I must say this is very nice stuff. This app went together in near record time.

**Anyway, time for the massive fail…**

I then clear the tmp folder, clear the browser’s cache (or use a different browser), and try to access the app from the WAMP server.

I go to

`http://localhost/myapp/`  
and the server attempts a redirect to  
`http://localhost/users/login?redirect=%2Fmyapp%2F`  
which gives a 404.

If instead I try to open

`http://localhost/myapp/users/login

The login page opens up quite nicely, but the same usernames and passwords that work so well in the cake server (localhost:8765) pop up the box that says that my username or password is incorrect. I presume this because the paths don’t work.

When I deploy this to the client’s server it will have to exist at _[https://www.myclient.com/myapp](https://www.myclient.com/myapp)_ and not at _(what from extensive reading I presume to be the Cake normal)__[https://myapp.myclient.com](https://myapp.myclient.com)_ That would be nice and all, but I don’t have that as an option in this case, so here I am.

I have wondered if this piece of code in webroot/index.php has something to do with it, but I honestly don’t understand what it is trying to tell me.

```
// For built-in server
    if (PHP_SAPI === '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;
    }
}

```

In your collective minds, what have I done wrong, where should I look, what might I try next?

---

<div class="post-metadata">

**Author:** ![rboatright](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rboatright/32/2060_2.png) [@rboatright](https://discourse.cakephp.org/u/rboatright)\
**Post date:** [December 7, 2020, 11:00pm UTC](https://discourse.cakephp.org/t/cake-app-running-on-wamp-sever-vs-bin-cake-server-problems/8708/2 "2020-12-07T23:00:13Z")

</div>

Hmmm or is my problem in Application.php where it says:

```
$authenticationService = new AuthenticationService([
        'unauthenticatedRedirect' => '/users/login',
        'queryParam' => 'redirect',
    ]);

```

Perhaps it should say /myapp/users/login ? I’ll just try that…

OK, cool, that fixes the first redirect, if I browse to [//localhost/myapp](https://localhost/myapp), I get redirected to [//localhost/myapp/users/login](https://localhost/myapp/users/login) Coolness. But, unfortunately, I still can’t log in. Same mysql database, on the same localhost server with the same username and password, so that shouldn’t be it. I’m still confused.

---

<div class="post-metadata">

**Author:** ![rboatright](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rboatright/32/2060_2.png) [@rboatright](https://discourse.cakephp.org/u/rboatright)\
**Post date:** [December 7, 2020, 11:13pm UTC](https://discourse.cakephp.org/t/cake-app-running-on-wamp-sever-vs-bin-cake-server-problems/8708/3 "2020-12-07T23:13:26Z")

</div>

Well, that’s interesting indeed.

I change the unauthenticateRedirect to /myapp/users/login and then further down I change the loginUrl to the same, and STRING MUSIC it lets me log in.

But… it then trys to send me to /myapp/myapp/ which naturally throws a missing controller error.

If I manually then go to /myapp/things manually the authentication succeeds, I did log in, and I get the list of things. I can page, I can view, edit, delete and add things. I can log out. I can log back in. This is all very cool… so, it’s only that first redirect, which has this problem:

```
http://localhost/myapp/users/login?redirect=%2Fmyapp%2F

```

It’s that second myapp. It sticks it on the end of the GOOD redirect. Hmmm. Does that happen in webroot/index.php? Well, if so it’s not hard coded that I can find. I guess it might somehow refer back to the //for built in server code in webroot/index.php – but I don’t see why.

Of course, these changes break the localhost:8765, but I couldn’t care less because of course, that isn’t how it’s going to run on the deployment server.

---

<div class="post-metadata">

**Author:** ![Jawfin](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@Jawfin](https://discourse.cakephp.org/u/Jawfin)\
**Post date:** [December 7, 2020, 11:25pm UTC](https://discourse.cakephp.org/t/cake-app-running-on-wamp-sever-vs-bin-cake-server-problems/8708/4 "2020-12-07T23:25:43Z")

</div>

I may be way off base here, but I have found when referencing parts of the app by path - especially files outside the CakePHP but on the same server (not the case here) - is that the folder you run the cake server from is relevant. Running the cake.php from a folder higher than it (like how the tutorials on WAMP say to do, ie. `cd app` then `bin\cake server`) will break it.

So just to remove that as a possibility of not losing paths relative to root, run the server from the same depth. Personally I run it from webroot as that feels right to me `cd app\webroot` then `..\bin\cake server` - but as the paths are relative there’s no reason you can’t just `cd app\bin` then `cake server`.

This may not help you now, but it could bypass errors you may yet encounter.

---

<div class="post-metadata">

**Author:** ![rboatright](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rboatright/32/2060_2.png) [@rboatright](https://discourse.cakephp.org/u/rboatright)\
**Post date:** [December 8, 2020, 12:07am UTC](https://discourse.cakephp.org/t/cake-app-running-on-wamp-sever-vs-bin-cake-server-problems/8708/5 "2020-12-08T00:07:24Z")

</div>

Sure, but bin\cake server run from the myapp folder works just fine. It’s wampserver that’s screwing up.

Thanks for the idea tho.

---

<div class="post-metadata">

**Author:** ![rboatright](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rboatright/32/2060_2.png) [@rboatright](https://discourse.cakephp.org/u/rboatright)\
**Post date:** [December 8, 2020, 12:14am UTC](https://discourse.cakephp.org/t/cake-app-running-on-wamp-sever-vs-bin-cake-server-problems/8708/6 "2020-12-08T00:14:31Z")

</div>

**OK, we can close this.**

It turns out that authentication 2.0 had a bug with respect to running in subdirectories. It was annoying to discover that in order to update authentication I had to manually adjust version contraints in composer.json, oh well. Upgrading to 2.3.1 fixed the problem. See this post here:

> [@Authentication and root folder mismatch after subfolder implementation](https://discourse.cakephp.org/t/authentication-and-root-folder-mismatch-after-subfolder-implementation/7930):
>
> I have worked with an working app locally, but after putting it online I see a relation between the authentication plugin and encountered errors. The application is stored in a subfolder of a webpage e.g. www.X.y/cakephpapp/. Going to tables indexes correctly routes to /cakephpapp/tablename, but the authentication check redirects to /users/login, which returns in 404. Moreover, while loggin in @ /cakephpapp/users/login, debugging the authenticator result gives the following error: [protected] …
