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 (CS开发者_开发问答S, 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 http://example.com/somepath/cakeapp.
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/
精彩评论