how to setup cakephp that runs from url path

110 views Asked by At

So I'm building microservice architecture and I have separate cakePHP installations for Administration and Partners. So https://example.com is going to be served for normal users and that works fine as it's a standard installation.

But I can't figure out how to set up other two that they work as https://example.com/admin and https://example.com/partners. I use nginx to direct traffic to the correct docker container running admin and partners cakephp. Problem is how to let CakePHP know that his root website path is /admin and not just \? Because all the routing gets messed up.

I'm using CakePHP 4.x and PHP 7.2.x

2

There are 2 answers

2
RiTeSh On

I think it's not a good option to create multiple projects for different AUTH (Partner/Administration). Cakephp allow multiple authentication for different roles. Example: for a school project I had created Admin/School/Teacher/Students using different AUTH and AUTH storage , which never conflict with each other.

In your case there is a solution . Assuming that you want to use https://example.com/ and Partner and https://example.com/admin as administrator.

1.First host your Partner project in ROOT.

  1. Create a folder , named "admin" in Partner root projects folder.

  2. Copy/Move your admin project code to your "admin" folder.

  3. Change/update your ".htaccess" files in Partner root folder(FOR APACHE).

APACHE CODE

# Uncomment the following to prevent the httpoxy vulnerability
# See: https://httpoxy.org/
#<IfModule mod_headers.c>
#    RequestHeader unset Proxy
#</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    admin    admin/    [L]
    RewriteRule    ^(\.well-known/.*)$ $1 [L]
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
</IfModule>

After "RewriteEngine on " a new line added to bypass the PARTNER cakephp.

NGINX

# nginx configuration by winginx.com

location / {
  rewrite admin /admin/ break;
  rewrite ^/(\.well-known/.*)$ /$1 break;
  rewrite ^/$ /webroot/ break;
  rewrite ^(.*)$ /webroot/$1 break;
}
1
Stefano On

I think you can simply change the App.baseUrl in the cakephp configuration. For more info check the official documentation