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

What is the best way to setup a view plugin in Zend Framework 2?

model-view-controller zend-framework plugins view zend-framework2

I'm trying to setup a view plugin to expose the route matches in Zend Framework 2.

Only parsing outer element

html ruby nokogiri

I am writing a scraper with Nokogiri, and I want to scrape a large HTML file.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.