views:

2829

answers:

7

I'm trying to install cakePHP on a shared hosting setup. After extracting the files to a location like ~/public_html/dev/cake and visiting the appropriate URL (in this case http://hostname/~username/dev/cake/), I receive a 404 error:


Not Found

The requested URL /usr/home/username/public_html/dev/cake/app/webroot/ was not found on this server.


I suspect that the reason for this is that upon closer inspection, the absolute path to ~/public_html is not in fact /usr/home/username/public_html, but rather /usr/www/users/username/.

Here's what I've been trying (but obviously it's not working): (~/public_html/dev/cake/app/webroot/.htaccess)

<IfModule mod_rewrite.c>  
    RewriteEngine On  
    RewriteBase /usr/www/users/username/dev/cake/app/webroot/ 
    RewriteCond %{REQUEST_FILENAME} !-d  
    RewriteCond %{REQUEST_FILENAME} !-f  
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]  
</IfModule>

Unfortunately, this doesn't seem to change anything (the 404 message remains that same). Thoughts?

A: 

Why not just extract the files to /usr/www/users/username/?

David Zaslavsky
So I looked around and I _think_ that's where the files actually reside.If I understand Pair (my host) correctly, there's a Home (/usr/home/username) and a Web directory (/usr/www/users/username), which is symlinked to /usr/home/username/public_html (aka ~/public_html).
A: 

i think the .htaccess is reading that '~' and thinking you are refering to your home folder (which is something of a shortcut in linux).

fastest way to get your app running is to go to cake's config/core.php and disable use of rewrite (it tells u to uncomment some stuff and delete some .htaccess file). the other way is to edit your .htaccess and somehow tell it '~' is not refering to home directory. maybe a simple \ will work.

Disabling rewrite definitely works, thanks. I think I'll just run with that for now.
That's probably not the problem: I have a similar setup on my box (localhost/~user/cake) and it works alright.Try enabling the rewrite log: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritelog . If your host didn't disable the directive, it could help you see what's going wrong.
Xr
A: 

You're modifying the wrong file. The .htaccess file you need to modify is found in /dev, you shouldn't be modifying the one in /dev/cake/app/webroot/.htaccess

Farid
+3  A: 

Shouldn't

RewriteBase /usr/www/users/username/dev/cake/app/webroot/

be

RewriteBase /~username/dev/cake/

RewriteBase cares about mapping real urls to virtual ones, and I think that's what you want.

artlung
Yes, RewriteBase refers to the logical/virtual URL, not to the filesystem location
Chris Thompson
A: 

I am hosting on pair and I was able to get the rewrite rules to work but, I am having problems with the HTML->link getting the sort parameters for all links in the pages. Same code runs fine on my local machine running window but on pair sorting or too many query parameters (Edit or Update pages) causes problems.

A: 

Yes you have to give the DOCUMENT_ROOT(somthing like var/www/html/) path in the following files,(Please refer phpinfo() of your server to get correct DOCUMENT_ROOT path)

1) .htaccess = Outside the app,cake,vendors folder

RewriteEngine on RewriteRule ^$ ) DOCUMENT_ROOT/app/webroot/ [L] RewriteRule (.*) DOCUMENT_ROOT/app/webroot/$1 [L]

2) .htaccess inside the app folder

RewriteEngine on RewriteRule ^$ DOCUMENT_ROOT/app/webroot/ [L] RewriteRule (.*) DOCUMENT_ROOT/app/webroot/$1 [L]

3) .htaccess insode the webroot folder

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ DOCUMENT_ROOT/app/webroot/index.php?url=$1 [QSA,L]

It worked for me.Please try this.

A: 

Hi All,

I had similar problem with 'advanced installation' from the official CakePHP Cockbook. After couple of hours I managed to get it working.

OS: Mac OS X

Cake core directory: /usr/lib/cake
My application app directory: /Users/myuser/dev/myapp
My application webroot directory: /Users/myuser/Sites/myapp

Modification of /Users/myuser/Sites/myapp/index.php

if (!defined('ROOT')) {
    define('ROOT', DS.'Users'.DS.'myuser'.DS.'dev');
}
if (!defined('APP_DIR')) {
    define('APP_DIR', 'myapp');
}
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
    define('CAKE_CORE_INCLUDE_PATH', DS.'usr'.DS.'lib');
}

Modification of /Users/myuser/Sites/myapp/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /~myuser/myapp/
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

As for /Users/myuser/dev/myapp/.htaccess - this file is not needed in this configuration so I deleted it. The most tricky part with this configuration is enabling mod_rewrite in Apache. On Mac editing /private/etc/apache2/httpd.conf seems to be pointless (for this task). Additional Apache configuration file is created for each user.

Modification of /private/etc/apache2/users/myuser.conf

<Directory "/Users/myuser/Sites/">
    Options FollowSymLinks
    AllowOverride All
</Directory>

By default AllowOverride is set to None, so mod_rewrite will not work in this configuration.

After this changes http://localhost/~myuser/myapp works properly.

PS. Quick permission fix for tmp directory.

sudo chgrp -R www /Users/myuser/dev/myapp/tmp
sudo chmod -R g+w /Users/myuser/dev/myapp/tmp
Copter