2

I've been building on localhost and all this stuff works perfectly. Now trying to load the site on a shared host. I've worked through most of the issues and actually have a working site but without any css.

Layout: My app is in: /home/cake/app

public_html is in: /home/public_html

In public_html/index.php, the only way I was able to get rid of missing file errors was to do this...

require '../cake/app/webroot' . DIRECTORY_SEPARATOR . 'index.php';

The .htaccess in public_html:

 <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

My app was baked from the command line. All of the index.php and .htaccess files up through the chain are untouched.

/cake
/cake/webroot
/cake/app
/cake/app/webroot

It just can't find the path to all the css and js files. in my default.ctp, I used the standard html helper links.

echo $this->Html->css('default');

I'm at the end of the proverbial rope. Any help appreciated. On localhost, I point the apache directory at /cake/app, but I'm pretty sure I don't have access to apache config files on a shared host, hence the reason I pointed the public_html index.php at /cake/app. Probably not right, but it felt like I was moving in the right direction since the site started working.

1

4 Answers 4

6

All your CSS & JS should be inside the app/webroot directory.

It sounds like you've setup your virtual hosts incorrectly. (This is why the CSS works in public_html but not in the webroot directory).

Basically, We only allow access to our application through app/webroot/. This will load the index.php inside the webroot which is provided by cakePHP to load the controllers for every request.

Your virtual host file should look like this:

<VirtualHost *:80>

    # Correct: Notice the "/app/webroot/"
    DocumentRoot "/path/to/app/public_html/app/webroot/"

    # Below is INCORRECT
    # Incorrect: DocumentRoot "/path/to/app/public_html/app/"

    ServerName yourdomain.com

</VirtualHost>

Now.. the ONLY directory accessible from the outside world is everything in webroot, this can be JS, CSS, Images, Files or whatever other assets you require.

This is how it should be setup, you dont want people to be able to access files outside of your webroot (ie all other CakePHP files).


On shared hosting providers, you will require a slightly different setup (you wont have access to the vhosts of the shared server). This explains the slightly different directory structure the OP has said. Read here for more info on deploying cakephp on a shared host.

http://bakery.cakephp.org/articles/gedm/2009/08/29/installing-cakephp-on-shared-hosting

Instead of including the index.php from the webroot in another index.php (inside your public_html), consider changing the webroot folder entirley to your public_html.

View here for more info on change cakephp webroot folder: CAKEPHP - Change default path to webroot

Sign up to request clarification or add additional context in comments.

4 Comments

hmm, thats a bit of a weird structure, I was using the actual structure of a fresh new CakePHP install, you can check it at cakephp.org (click download).
I understand we only want access through /app/webroot. And on my local machine, that's how I do it. However, on this shared host, (client site) I don't have access to the vhosts file. (I'm checking to see if they can edit that file for me.) Within public_html, I have an index.php file that requires ../cake/app/webroot/index.php. The aforementioned .htaccess. and now I have copies of just the /app/webroot folders that contain the css and js files. So, from a security perspective, this should functionally be about the same. Yes, the css/js/img files are in public_html, but nothing else is.
I will digest that post and perhaps try what he is suggesting. Seems harder though. I simply copied my entire out-of-the-box cake app into the root and didn't have to edit any other files or path statements. Thank you for your insight though. I do appreciate it.
I was going to suggest to do that, but wasn't sure if cakephp would pick it up without modifying any files, Thanks for letting us know!..
2

Change AllowOverride none to AllowOverride FileInfo in /etc/apache2/sites-available/default.

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /home/user/app/
    <Directory />
        Options FollowSymLinks
        AllowOverride FileInfo
    </Directory>
    <Directory /home/user/app/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride FileInfo
        Order allow,deny
        allow from all
    </Directory>

It worked for me.

Comments

2

Finally this one was the command wich worked for me to enable mod_rewrite:

$ a2enmod rewrite

Comments

-1

Well, not sure whether this is all "right" or not, but I copied all the folders with the css and js files into public_html, which kind of makes sense. All of those assets need to be publicly accessible. Site works now.

1 Comment

this is not cakephp standard.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.