Installing CakePHP 2.4.7 on Windows - cakephp

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.

Related

Error message when navigating through react website after uploading it on bluehost

Full error message: Not Found
The requested URL was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
My problem is when I uploaded my build file to cpanel(via bluehost) I started getting this error when I try to navigate to different pages within my react. The homepage works and displays all that it's supposed to. My local host doesn't have this problem because according the react documents the development server knows how to handle the requests. I have researched everywhere on the internet for the answer to this problem, but nothing seems to work.
This is the configuration in my .htaccess file in my public directory:
<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>
This is my package. json file:
My build file was uploaded as a zip file into cpanel > public_html. All files were extracted from the build folder and moved into public_html. Like previously stated my homepage works but when I navigate to other pages it does not.
npm run build without a .htaccess file
In cpanel in the top right corner there is a settings option. Choose settings and check the option "show hidden files." (also make sure you're in the document root)
In the top left corner there is the option to add a file. Click that and create a new .htaccess file.
Paste this in the new file, save it and you should be able to move through your website without the error message. Hopefully I just saved you the 5 days it took me to figure this out.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>

Error 403 forbidden when using React Router with Apache

When I deploy my website built with React and React-router the landing page of my website works fine but when I try to navigate into my website I run into 403 forbidden response. I use Apache as an HTTP server and the general config of my server is the following :
<IfModule mod_php.c>
php_value date.timezone Europe/Brussels
</IfModule>
<IfModule mod_userdir.c>
UserDir /var/www/users/staff/*
</IfModule>
For your information, the website is located under /var/www/projects
I added the following .htaccess to my project :
<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>
Despite those configurations the 403 forbidden error when navigating in pages managed by react-router. Did I miss some configurations?
It seems that the settings you have applied are not enough, You should change some parameters in apache.conf too...
open the apache main config file, Its path varies depending on your distribution, that's located in one of these locations:
1- /etc/apache2/httpd.conf
2- /etc/apache2/apache2.conf
3- /etc/httpd/httpd.conf
4- /etc/httpd/conf/httpd.conf
look for "AllowOverride" parameter like the example below:
<Directory "/var/www/blahblah">
AllowOverride All
</Directory>
And give the "All" value to that.
Then create a .htaccess file in the root folder of the webserver & set the following configs:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
NOTE: Before performing these things you have to enable the rewrite module, By entering the following commands you can do this:
debian base: sudo a2enmod rewrite
centos: uncomment mod_rewrite.so in /etc/httpd/conf/httpd.conf
Finally, restart your web server... Now expected there is no anymore problem.
If you got any permission/server error take a look at the webserver logs which are located in one of these locations:
1- /var/log/httpd/
2- /var/log/apache2

CakePHP not working, showing PHP Code inline PHP

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. :)

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