3

How do I install CakePHP 3 in a subdirectory? So far, I've only found that I should set my App.base variable in config/app.php file, but I've tried every path I can think of, but only get 500 error.

Overview of how it should end up:

User goes to www.example.com and gets my 'app1' CakePHP 3 application. User goes to www.example.com/app2 and gets my 'app2' application (standard PHP for now, but eventually another Cake app).

Here's my general file structure:

/
.htaccess *see contents below
application1/
    bin/
    config/
    logs/
    plugins/
    src/
    ...etc
application2/
    index.php - just does an: echo 'APP2!';

I've tried changing my App.base to each of these:

'App' => [
    'base' => '/application1',
    //'base' => '/example.com/application1', 
    //'base' => '/vhosts/example.com/application1', 
    //'base' => '/www/vhosts/example.com/application1', 
    //'base' => '/var/www/vhosts/example.com/application1', 

My .htacess file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^application2/?$ /application2/$1 [R=301,L]
</IfModule>

What am I missing? Are there other steps I need to take? Is what I've done so far incorrect?

Dave
  • 28,833
  • 23
  • 113
  • 183
  • Seeing as it's your app1 that's being relocated, why not rewrite that instead of app2 that's actually in the correct place? – Deanna Feb 24 '16 at 22:04
  • @Deanna not sure what you mean. They're both in the "correct" place. – Dave Feb 24 '16 at 22:47
  • Yes, but you're trying to make the contents of `/app1/` appear in `/` (without `app1/` showing)? Or is your question badly phrased? :) – Deanna Feb 24 '16 at 22:50
  • It very well could be badly phrased. I want two apps. One in the `/application1` directory, and the other in the `/application2` directory. Seems a lot cleaner than having one in the root, and another Cake project within the first Cake project. I assumed I would handle by sending the root directory to one of them (either), and using htaccess to point to the other. – Dave Feb 24 '16 at 23:34
  • Well, the "other" is already in the place where it's going to be accessed,no need for a redirect. App1, you want to appear in the root, so use mod rewrite to handle App1, rather than just a `include() `. – Deanna Feb 25 '16 at 00:02
  • I expect the `include()' is what's confusing it as the script location and all paths around it are no longer what it expects. – Deanna Feb 25 '16 at 00:03
  • I've removed the index.php file with require, but lost as to what to do next. Are you suggesting I just add another RewriteRule to handle "everything else"? – Dave Feb 25 '16 at 00:08
  • Have you checked your logs to see what exactly the 500 error is caused by? What I can see from here is an invalid rewrite rule pattern, the stray closing parenthese would cause Apache to trigger a 500. – ndm Feb 25 '16 at 12:40
  • this kind of thing is a lot easier if you make application1/webroot the document root, and put application2/webroot into it. Note that you can put your code wherever you want and use symlinks to achieve that. – AD7six Apr 28 '16 at 07:42

1 Answers1

0

In www.example.com/app2

Modify yur .htaccess to the following:

RewriteEngine On
RewriteBase /application2/
RewriteRule    ^$    webroot/    [L]
RewriteRule    (.*) webroot/$1    [L]
ConquestXD
  • 754
  • 1
  • 8
  • 18