CakePHP not working, showing PHP Code inline PHP - cakephp

Edit: I know what is causing the problem now, but still no solution. Basically unless the tmp directory is 777 Cake is unable to write to it so it fails. And if tmp is 777 then because of maybe some weird security setting PHP doesn't work. Any ideas if this is a possibility and how I can fix it?
Edit 2: Is it possible that because of character encoding the tmp is not 777 its showing ? garbage characters.
I just migrated my CakePHP app to Amazon AWS (Using a BitNami LAMPstack). I was getting PHP errors saying Could Not Connect to DB (which means PHP is executing).
When I fixed the DB settings it is now printing inline PHP.
For example:
<title><?php echo $title_for_layout; ?></title>
is showing in the HTML and the document title is hence a snippet of PHP code!
Please help I'm at a loss. Things I've tried doing:
Changing AllowOverride to All in the section in/opt/bitnami/apache2/conf/httpd.conf
Editing my php.ini for short_open_tag=On just in case
Making sure mod_rewrite is enabled in httpd.conf and that my htdocs and app folder have the correct .htaccess files.
Here are my .htaccess files just in case:
htdocs/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Options All -Indexes
htdocs/app/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
htdocs/app/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>

Well all I can say is thank god I paid attention in class last semester when they explained character encoding.
So I opened up all the .ctp files that weren't being exec'd as PHP in vim. I said :set encoding=utf-8 and :set fileencoding=utf-8
and then :x (keeping it newb-friendly just in case somebody wants a quick fix) :)
And its working like it should now. :)

Related

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.

CakePHP project redirecting from localhost to live website

I need to make some changes on an existing CakePHP project, but I can't run it on localhost because every time I try to access http://localhost:8080/{name-of-project}/ it redirects me to http://www.{name-of-project}.com.
Any help would be appreciated.
I also encountered this one when Im still using cakephp2 and still duable using cakephp3
from live .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$ [NC]
RewriteCond %{HTTPS}s ^on(s)|off
RewriteRule ^(.*)$ http%1://www.mydomain.com/$1 [R=301,QSA,L]
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
I change it to this one
.htaccess local
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Most likely in your .htaccess file there is a non-www to www redirect installed.
As Adam notes, it may be useful to clear your browser cache when working with redirects. A cached redirect would no longer hit your server configuration so any changes you do will not be visible.

Installing CakePHP 2.4.7 on Windows

I am facing issue in my first intallation of CakePHP.
I am working on Windows OS and using WAMP. I am able to point my browser to localhost -> phpcake to open my installation of CakePHP.
However I get an error as below:
Missing Controller
Error: PhpcakeController could not be found.
Following are the steps which I followed for installing CakePHP:
Unzipped CakePHP, version 2.4.7 and loaded that in my WAMP
Created database using phpMyAdmin
Updated the app\Config\database.php file with login, password and databasename
The contents of the .htaccess files of cake is as below:
phpcake/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
phpcake/app/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
phpcake/app/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase D:/Vivek/phpcake/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/(app/webroot/)?(img|css|js)/(.*)$
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
The mod_rewrite is disabled on my Apache. If I enable it, then I get 404 error on launching CakePHP install.
Could you guide me as to which step am I missing?
Finally i got it working. This is what i was doing (wrong).
In my WAMP i created an alias directory. Apache -> Alias -> Add an Alias Directory. In this alias i pointed to the location of my CakePHP unzipped folder. I updated the App/Config/Database.php to point to created MySQL database. However on selecting mod_rewrite module in Apache i was getting 404/403 errors. And without mod_rewrite i was getting missing controller error.
Missing Controller
Error: PhpcakeController could not be found.
I tried fresh installations 3 times with same results.
My understanding is that the mod_rewrite, the instructions in Alias file and .htaccess files were creating this trouble.
So this is what i did (Worked):
I copied my CakePHP into WAMP's www directory. That's it, it did the trick. I went through various articles about .htaccess, and mod_rewrite. Frankly speaking it is complex for me.

CakePHP Installation Broke (Probably Apache2 Problem)

I tried to install CakePHP on my home Ubuntu 10.04 desktop for development/testing purposes, and I believe I have gone through all the appropriate steps. However, I am still running into the problem that my layout is broken. I believe this is a DocumentRoot or mod_rewrite problem, but I don't have enough experience in Apache to diagnose and fix it.
/var/www/cakephp/.htaccess
1 <IfModule mod_rewrite.c>
2 RewriteEngine on
3 RewriteRule ^$ app/webroot/ [L]
4 RewriteRule (.*) app/webroot/$1 [L]
5 </IfModule>
/var/www/cakephp/app/webroot/.htaccess
1 <IfModule mod_rewrite.c>
2 RewriteEngine On
3 RewriteCond %{REQUEST_FILENAME} !-d
4 RewriteCond %{REQUEST_FILENAME} !-f
5 RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
6 </IfModule>
Firebug gives this:
404 Not Found
Not Found
The requested URL /cakephp/css/cake.generic.css was not found on this server.
Apache/2.2.14 (Ubuntu) Server at localhost Port 80
I tried setting the permissions of css/ and cake.generic.css to 775. owner is www-data, which is right. tmp is writable too
I also can't access the directory from my browser, 404.
but that will change your default website doccument starting point for your localhost site.
if you add more sites to apache2, you'll have errors.
you might want to save your 000-default as a separate file
/etc/apache2/sites-available/cakephptesting
and configure that file with the proper docroot
and then edit your host file
/etc/hosts
and add an entry as
127.0.0.1 cakephptesting
that will allow you to access the site in a browser at http://cakephptesting
I found the solution. I had to go under /etc/apache2/sites-enabled/000-default and change DocumentRoot to /var/www/cakephp/app/webroot
Now everything loads fine. Thanks!
Sorry,
Signed,
The Apache2 Noob :)

cakephp .htaccess configuration on godaddy with subdomain

I have one domain on godaddy (www.mydomain.com). I have placed my cakephp application on this domain. It is working fine for me.
But i have created a subdomain blog.mydomain.com for this godaddy has created a directory named blog inside the www.mydomain.com now how can i redirect the request coming for blog.mydomain.com to the blog/ folder.
I am trying this,
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog.mydomain.com$
RewriteRule ^(.*)$ blog/$1 [L]
RewriteCond %{HTTP_HOST} ^mydomain.com/$
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
It works for single Rewrite condition like,
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog.mydomain.com$
RewriteRule ^(.*)$ blog/$1 [L]
But when i add another rewrite condition for my cake app it shows 500 Internal server error for blog.mydomain.com
Please help me out .............
Put the blog folder in webroot (under your cake directory) and it should work just fine. Or did you need to do something else more fancy?
Try this: http://digitalmemo.neobie.net/2011/04/19/cakephp-bypassing-for-subdomain/
It use to make all the subdomains to be working correctly instead of defining each of the subdomain.

Resources