Setup subdomain in new app directory with Cpanel cakephp - cakephp

I have working domain.kz with cakephp (Cpanel hosting)
www/app
www/cake
www/index.php
how can i setup admin.domain.kz to (app2)
www/app
www/app2
www/cake
www/index.php

The way you want it - will be very difficult; you'll have to change several file/folder paths in several places. Instead, why don't you try to create an admin folder where you've the full cakephp application for admin.
So the resulting folder structure would be like this:
(domain.kz)
www/app
www/cake
www/index.php
(admin.domain.kz)
www/admin/app
www/admin/cake
www/admin/index.php
Then you'll have to point your subdomain (admin.domain.kz) to /www/admin.
Now assuming that you've configured your domain and subdomain correctly, if you try to browse your domain, it'll work with no issues but if you try to access your subdomain, it'll give you a 500 error. DON'T WORRY. It is expected.
The primary .htaccess file is forcing all requests served by primary webroot (www/app/webroot) folder. You'll have to change your primary .htaccess file (www/.htaccess) like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^admin\.domain\.kz$ [NC]
RewriteRule ^ - [L]
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Notice that, I've added two lines which tells that if you're trying to access your subdomain, stop rewriting; otherwise rewrite as usual. Cheers!!!

If the cake apps are totally separate but share a cake library then the following might work:
You could use cPanel's 'Addon Domain' feature, once the DNS has been set up for admin.domain.kz. Instructions can be found here.
Set the document root of the addon domain to the www/app2 folder.
Then just make sure that CAKE_CORE_INCLUDE_PATH in www/app2/webroot/index.php points to ../../../cake

Related

url is not working in live but working fine at local for cakephp project

I am using cake php version 2.4. My project is running well in my local machine and it is a simple test project. I uploaded it in live. It does not work in live and even all css file are not loading. Should I change any server configuration?
You should check below situation in your Online Server :
DocumentRoot is properly set
Example : DocumentRoot /cake_install/app/webroot
.htaccess file is configured properly.
webroot Directory have the correct permissions
Check all other file/folder permissions
Ensure apache rewrite module is on
Note : rewrite module should be enabled from your online server for CakePHP URLs
I used the following code in .htaccess file where app folder is located:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Now it works for me.

LetsEncrypt and CakePhp issue

I'm trying to install LetsEncrypt with cakephp and I'm having some issues.Let me describe:
First I'm installing LetsEncrypt on a server with CentOS 6.
As mentioned on several websites it needs a python upgrade from 2.6 to 2.7 as LetsEncrypt needs Python 2.7. Which I did.
Then if I run ./letsencrypt-auto I get
"No installers are available on your OS yet; try running "letsencrypt-auto certonly" to get a cert you can install manually"
I understand that this is normal as there is no installer for CentOS 6.
So I run ./letsencrypt-auto certonly.A window appears.I have the choice between:
Place files in webroot directory
Automatically use a temporary webserver
So I press 1.Then I enter my domain name.And I see:
Enter a new webroot
I press ok and I see my root directory.I select /root
And then I have the following error:
Failed authorization procedure. www.example.com (http-01): urn:acme:error:unauthorized :: The client lacks sufficient
authorization :: Invalid response from
http://www.example.com/.well-known/acme-challenge/-CnpDIgxBB9EOH-BCssGOyiunFjnMlGLWhWw9roE4Ds:
"
500 Internal Server Error Inter"
IMPORTANT NOTES:
- The following errors were reported by the server:
Domain: www.example.com Type: unauthorized Detail: Invalid
response from http://www.example.com/.well-known
/acme-challenge/-CnpDIgxBB9EOH-BCssGOyiunFjnMlGLWhWw9roE4Ds:
"
500 Internal Server Error
Inter"
To fix these errors, please make sure that your domain name was
entered correctly and the DNS A record(s) for that domain
contain(s) the right IP address.
And here comes cakephp. As mentioned I'm using cakephp. And it seems that for this specific issue you need to modify htaccess files as mentioned here
I need to add "RewriteRule ^(\.well-known/.*)$ $1 [L]" as the first rewrite rule in the root htaccess and the app/.htaccess
Which I did.
root .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(\.well-known/.*)$ $1 [L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
AddDefaultCharset UTF-8
</IfModule>
app/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(\.well-known/.*)$ $1 [L]
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
AddDefaultCharset UTF-8
</IfModule>
But I still have the same problem
Any idea what I did wrong?
Thanks a lot
Cake's webroot has an .htaccess with a RewriteCond %{REQUEST_FILENAME} !-d rule that means cake will not be called in for any request that matches an actual directory inside webroot.
So just place the .well-known directory and everything else that is needed inside the webroot directory, you should be able to access them fine without messing up with .htaccess.
PS. In some cases the file Let's encrypt requires is not served back as text, in which case you should enable the headers apache module (if not enabled already) and put the following rule in your apache or virtualhost config:
<IfModule mod_headers.c>
<LocationMatch "/.well-known/acme-challenge/*">
Header set Content-Type "text/plain"
</LocationMatch>
</IfModule>

How can I change the website document root?

I want to move to my document root from public_html to public_html/new_version/. I did this using .htaccess
RewriteRule ^$ new_version/ [L]
RewriteRule (.*) new_version/$1 [L]
It works fine but the links in my CakePHP application are appearing: domain.com/new_version/the-link-is-shown-here/
I want to either change completely the document root or have the links appear without the "/new_version/" folder name in them.
You can set App.baseUrl config in core.php to /.

redirect to subfolder and then hide subfolder from url

i have a url: www.example.co.za.
when i go to that url i can see my directory structure. This is my document root and needs to remain my document root so that i can access all underlying folders.
inside my document root i have the following folders. "auction","common".
auction contains "www" folder which is where my index.php file is.
My goal is to access example.co.za and then it must load "/auction/www". My url will then be "www.example.co.za/auction/www/index.php" but i dont want "/auction/www"in the url.
Can someone please help me with this. i suck at htaccess :(.
I dont want linked folders, other vhosts etc. I just need what i explained above.
Try:
RewriteEngine On
RewriteRule ^(index.php|)$ /auction/www/index.php [L]
This may now be the "definitive" answer or the "best way" to do it because .htaccess isn't my strongest area, but something like this should get you on the right path:
Be sure to put this in the .htaccess file in the root directory.
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ auction/www/$1 [L]
You can expand on this with alternative paths for a multi-app site, eg:
RewriteEngine on
RewriteBase /
RewriteRule ^auction/(.*)$ auction/www/$1
RewriteRule ^otherthing/(.*)$ otherthing/www/$1 [L]
etc.
So in the second example when you go to www.mysite.co.za/auction you'll be redirected to the content in auction/www, and if you go to www.mysite.co.za/otherthing you'll be redirected accordingly.
EDIT: added second example

Cakephp not loading css and js files

I seriously can't understand what is going on here. I just uploaded my web app from localhost to new domain-name on Windows IIS Server. When I try to access the web app, CSS files and images are not loaded and I get the following error:
"CssController could not be found."
I don't understand why it is doing this.
Although I've written code like this in my default.ctp:
echo $this->html->css('generic');
CSS files are placed in:
app\webroot\css
I have searched on Google and have tried everything, I even uncommented the line:
Configure::write('App.baseUrl',env('SCRIPT_NAME')); in core.php
But I still cannot get this to work. Please help me to resolve this issue.
Double check that you have all the .htaccess files in place.
Also making sure /app/webroot/ has its .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
Your request is trying to get the css file from /css/ but i'm thinking you don't have the proper .htaccess files in place to route it to the webroot and not to a controller!
also check if mod_rewrite is enabled
Edit: and then I saw the IIS part, you need some IIS equivalent to mod_rewrite
In this article you find all the information required for successfully run CakePHP web applications under Microsoft IIS web server: http://bakery.cakephp.org/articles/filippo.toso/2008/01/29/cakephp-on-iis
Here is a related question about getting cake to work on IIS: CakePHP 2.2.2 not working on Windows IIS7

Resources