CakePHP 2.x on CentOS 6 - cakephp

I am having issues with CakePHP 2.4.3 (tried on 2.5.2 too, same problem) installation on CentOS. Database can be accessed (read/write) from cakephp.
Tried for the past few hours to fix it, but here is where I am stuck :
1) This error keeps on appearing. "URL rewriting is not properly configured on your server"
- I have check, and the file is accessible from the site, "www.mysite.com/cake/app/webroot/css/cake.generic.css"
- I have updated httpd.conf to have "LoadModule rewrite_module modules/mod_rewrite.so"
- The files ".htaccess" are in 3 folders :
/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
/app/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
/app/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
httpd.conf
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
2) My controllers cannot be called directly. It needs the "index.php" to be there.
Example :
Works on : "www.mysite.com/cake/index.php/grabs/myFunction"
Unable to work on : "www.mysite.com/cake/grabs/myFunction"
Please advise.

An important notice for people like me, who struggled with problem exactly like this one.
One of the POSSIBLE REASON for this behavior is when there are two or more CakePHP apps residing on one server. Anyway, try changing this line:
// Prefix each application on the same server with a different string, to avoid Memcache and APC conflicts.
$prefix = 'myapp_';
From your /app/Config/core.php to something distinct, let's say:
$prefix = 'coolRpgGame_';
It really saved my life and it worked immediately.

Related

My React JS app crashes when I realod the page using subdomain apache ubuntu server 20

could someone else help to me how I would configure apache/htaccess/reactapp in order to avoid the webapp crashes
My subdomain is eg. https://subdomain.example.com (it's working fine) the page loaded well if I refresh the page the page loaded well too. I think just right it is because the index.html is serving route home page.
But if I go to eg. https://subdomain.example.com/about (it's working fine as well) but here is the problem when I reload the page "Not Found - The requested URL was not found on this server". all pages after the domain crashes when I refresh the page
my htaccess
`
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
`
Server Ubuntu server 20.04
virtual host
`
<VirtualHost IP:443>
ServerName subdomain.example.com
DocumentRoot /var/www/my-app
<Directory /var/www/my-app>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
`
I just added this one in my htaccess root folder of ReactJS app
The credits for this guy: https://putridparrot.com/blog/react-router-dom-direct-url-or-refresh-results-in-404/
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>

prerender.io .htaccess variable - Reactjs CRA

I set up prerender.io for CRA and it works well, but when bot hits URL without parameters it puts in the end of URL - string ".var"
I tried variations of (.*) but it seems not working. Any ideas?
Here is .htaccess file
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
<IfModule mod_headers.c>
RequestHeader set X-Prerender-Token "TOKEN"
RequestHeader set X-Prerender-Version "prerender-apache#2.0.0"
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
<IfModule mod_proxy_http.c>
RewriteCond %{HTTP_USER_AGENT} googlebot|bingbot|yandex|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest\/0\.|pinterestbot|slackbot|vkShare|W3C_Validator|whatsapp [NC,OR]
RewriteCond %{QUERY_STRING} _escaped_fragment_
RewriteCond %{REQUEST_URI} ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.m4v|\.torrent|\.ttf|\.woff|\.svg))
RewriteRule ^(index\.html|index\.php)?(.*) https://service.prerender.io/%{REQUEST_SCHEME}://%{HTTP_HOST}/$2 [P,END]
</IfModule>
</IfModule>
Lately #MrWhite gave us another, better and simple solution - just add DirectoryIndex index.html to .htaccess file will do the same.
From the beginning I wrote that DirectoryIndex is working but NO!
It seems it's working when you try prerender.io, but in reality it was showing website like this:
and I had to remove it.
So it was not issue with .htaccess file, it was coming from the server.
What I did was I went into WHM->Apache Configurations->DirectoryIndex Priority and I saw this list
and yes that was it!
To fix I just moved index.html to the very top second comes index.html.var and after rest of them.
I don't know what index.html.var is for, but I did not risk just to remove it. Hope it helps someone who struggled as me.

vhosts conf for single page app

I have an angular app that I'm serving locally using apache. My vhosts.conf is:
<VirtualHost *:80>
ServerName my.app.com
DirectoryIndex index.html
DocumentRoot /export/www/app
<Directory "/export/www/app">
order allow,deny
allow from all
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html/$1 [L]
</Directory>
</VirtualHost>
If I go to the root of the app everything loads fine. I do some navigation within the app which brings me to my.app.com/some/location and still no problem.
However if I reload the page at this point I get a 404 error. To get back to the point I want I need to either go back to the root and navigate via the app again or else search by url my.app.com/#/some/location
Is there something that I can do with a rewrite rule so that I don't need the hash to reload the route? I tried to edit my existing rule to:
RewriteRule ^(.*)$ index.html/#/$1 [L]
Any ideas greatly appreciated
C
The issue was that I was using a newer version of apache where the config rules have changed. My updated vhosts now reads
<VirtualHost *:80>
ServerName my.app.com
DirectoryIndex index.html
DocumentRoot /export/www/app
<Directory "/export/www/app">
order allow,deny
allow from all
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /index.html [NC,L]
</Directory>
</VirtualHost>
It's weird that my.app.com/some/location works. With AcceptPAthInfo ON, httpd would serve index.html and pass PATH_INFO of /some/location but that shouldn't do the right thing on the client-side JS.
The rewrite you attempted seems like it shiould replace your existing rewrite entirely. But, you'd want to redirect explicitly to non-relative /index.html and add the [R] flag to make sure the redirect goes all the way to the client. Otherwise, it's just an internal substitution, and you need your browser to read the # because that's only handled on the client side.

CSS not working with CakePHP App

I'm having a problem with CakePHP, the CSS is not found. When I view the source code in my browser I can see the cake generic CSS link in the head section. But when I click on it to see the actual source code, I get a 404 not found error.
Update:
I've followed the instructions here:
http://book.cakephp.org/2.0/en/installation/url-rewriting.html
to make sure the mod_rewrite is setup correctly but I'm still having trouble viewing the CSS file.
Update:
THis is what .htaccess looks like in my root folder:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
This is what .htaccess looks like in my app folder:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
and this is what it looks like in my webroot folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Regards,
Stephen
I managed to solve it. The problem was with the way I set up my virtual host, my httpd-vhosts.conf file now looks like this:
<VirtualHost *:80>
ServerAdmin webmaster#invoice.dev
DocumentRoot "/Users/stephenxconnolly/Documents/Websites/invoice-new"
ServerName invoice.dev
<Directory "/Users/stephenxconnolly/Documents/Websites/invoice-new/">
AllowOverride All
</Directory>
# ServerAlias www.dummy-host.example.com
ErrorLog "/private/var/log/apache2/invoice.dev-error_log"
CustomLog "/private/var/log/apache2/invoice.dev-access_log" common
</VirtualHost>
This solved the problem.
Are you letting CakePHP create the link to the CSS? Like this:
echo $this->Html->css('cake.generic');
If Apache is pointing at webroot, and your CSS is in webroot/css/cake.generic.css, then you should be able to browse it at
http://website/css/cake.generic.css
If you put the CSS file in webroot can you browse it ok?

Running a CakePHP project on Localhost

I have downloaded a CakePHP project from an online server and need to make it work locally, to do some changes.
I'm facing a problem similar to this one and have tried all possible solutions, with no luck.
Here's the situations:
Site home is in localhost/xpto (c:\xampp\htdocs\xpto) -> here, the site appears unformatted (no CSS) and too slow.
If I access localhost/xpto/something, I get the site with the CSS, but some links wont work.
I have mod_rewrite loaded (phpinfo()) together with the 3 .htaccess files, but still experience this problem.
Is there any known issue that I can explore to fix my site?
Please redirect me to any guides or tutorials that you may feel relevant to my issue
Use RewriteBase directive in .htaccess.
e.g my dev space is on my localhost, is located in /home/ati/public_html/cakerbs, under a subdir in my userdir. The rewriteBase looks like as follows in the root of the cake:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /~ati/cakerbs
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
in the app directory .htacces:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /~ati/cakerbs
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
in the webroot directory:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~ati/cakerbs
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
Check your XAMPP apache settings, it's very likely your current config is blocking things like the .htaccess files (I know EasyPHP does this by default with Cake). What I do to get around this error is to add a VirtualHost to my config like such:
<VirtualHost *>
DocumentRoot "C:/xampp/htdocs/xpto/"
ServerName xpto.dev
ServerAlias www.xpto.dev
ErrorLog "logs/xpto-error.log"
CustomLog "logs/xtpo-access.log" common
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
It may be better to update your whole config properly, but seeing as it's a dev environment for me, this does just fine. (Don't forget to add any hosts to your windows hosts file)
Then just open your favourite browser and go to http://xpto.dev/ and it should load up.
This may help your more: http://ailoo.net/2008/07/set-up-multiple-virtual-hosts-on-xampp-for-windows/

Resources