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

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.

Related

Sonata admin missing css files

Working on a site with php 7.2, Symfony 4 and Sonata admin 3.
In dev, on my machine, everything works fine, the site itself, and the two admins (user and content).
I have put everything on the final server (unfortunately, file by file, no console with S4 ! so, no "composer:install"...).
Still on dev, the site works fine, all functionalities.
But when I try to use the admin page, I only get a non-formatted page. None of the assets (css and js) seems to work!
However the source code are identical, on localhost and the distant site...
Can anyone help me
Edit : I found where the issue comes from : it's linked to .htaccess.
The http address I use ends in /public/index.php. I use .htaccess to shorten it and when using the .htacces redirection I can't get the assets of the admin page, while it works fine without redirection.
Is there something I should change in my .htaccess code ?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/index.php
</IfModule>

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>

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

URL rewriting is not properly configured on your server. 1) Help me configure it 2) I don't / can't use URL rewriting

I got the cakePHP and I have the following error.
URL rewriting is not properly configured on your server. 1) Help me configure it 2) I don't / can't use URL rewriting
The odd thing is that it is working fine on my laptop and it is not working on my desktop pc. I copy the whole thing from my laptop and paste it on the desktop and that error is shown.
Any ideas to solve? I follow the steps to solve but it is the same problem. My cakePHP version is 2.0 above.
You can Check first your rewrite mode is on or not in apache/conf/httpd.conf file.
check below code in httpd.conf file:
LoadModule rewrite_module modules/mod_rewrite.so
Hash remove in this line and restart Apache server:
#sudo service apache2 restart
After that you can set below code in your cakephp .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /YourPath/
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

Setup subdomain in new app directory with Cpanel 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

Resources