CakePHP HTML helper CSS tag and Apache Alias

As a relative newcomer to CakePHP, I'm hoping for some advice on the "right" way of configuring Apache and CakePHP to find included files (CSS, JavaScript, etc).

If my server's DocumentRoot is set to /var/www and I install and configure CakePHP in /var/www/somepath/cakeapp I can access the application as expected at the URL

However, if I use the HTML helper to generate the CSS link tag in my default layout, I start to run into trouble. For example, the code

echo $html->css('styles');

produces this tag:

<link rel="stylesheet" type="text/css" href="/somepath/cakeapp/css/styles.css" />

However, the CSS actually lives in /somepath/cakeapp/app/webroot/css.

If the CakePHP app were the only thing on my domain, I could point the DocumentRoot at /var/www/somepath/cakeapp/app/webroot as the documentation suggests and all would (presumably) be well. However, that's not an option for me.

Is there a generally accepted correct way of configuring Apache and CakePHP so that the HTML helper can produce the correct link tag?

Edit: I feel there must be some combination of CakePHP configuration and Apache Aliases that I haven't run across yet.


/somepath/cakeapp/css/styles.css is actually the correct path that needs to be displayed in the links.

The reason why it gets displayed as such is because of the .htaccess file in your cakeapp directory that redirects (rewrites) requests to the cakeapp/app/webroot directory.

Now, the reason why this structure even exists is because generally, you have "public" and "non-public" parts in your application. The "non-public" parts contain the PHP code including controllers, models, views, plugins, cake library, etc. The "public" parts include the css, scripts, and image files.

Now, you could make your /var/www/html folder as your app directory to make it secure. In order to completely configure your application to your liking, check the cakeapp/app/bootstrap.php file and change the relevant settings. You can learn more about that here.

In short, no worries. The path you see is right!

Try defining RewriteBase in your .htaccess files in Cake's root directory, /app and /app/webroot to point to your subdirectory. Set them to the respective paths, /somepath/, /somepath/app/ and /somepath/app/webroot/

Need Your Help

How do you read your very first message with someone?

messages facebook-messages

I want to read my first messages with someone on Facebook, but I think our VERY first messages were reported to be "moved" because we had so many. I am not sure how if it's even possible to read them

How to write CSS for parent DIV needing height dictated by child DIVs that are also anchored bottom?

css html

Basically, I want an outer DIV's height to be dictated by its inner DIVs (specifically a left and right inner DIV) and I want any inner DIV less than that height to be anchored to the bottom of the...

frame.setResizable(false) does not work

java swing jframe jpanel

How do I disable the feature of resizing my JFrame?