Cakephp assets not fetching from webroot folder.. missing js & css,
.htaccess, cakephp-2.0, php, virtualhost
Solution
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
Problem
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.