I'm relatively new to Yii. I've managed to get a sample application up and running but as I am now moving to a real project, I would like to use the following folder structure for increased security:
[Server root (/) ]
- yii
-- framework
-- requirements
[Server htdocs]
- myapp
-- public
--- assets
--- css
--- images
--- themes
--- index.php
-- private
--- protected
All is fine when I leave the protected folder inside the public folder but I don't want to do this.
The only way I can get it to work using my proposed structure is if I create a symlink inside the public folder pointing to the protected folder inside the private folder. If I reference it directly in the private folder it just gives me a blank page upon app load.
I've double checked my configuration paths and permissions.
Any help is appreciated.
You can configure Yii to use the folders you want for your specific needs, eg. protected-folder, assets, themes, etc.
Have a look at "The directory structure of the Yii project site" for an example.
You can put your protected folder where you want, but you have to tell it to index.php. In your case, the line where it says:
$config=dirname(__FILE__).'/protected/config/main.php';
must say:
$config=dirname(__FILE__).'/../private/protected/config/main.php';
And same in index-test.php
There is an open source project called Yii Boilerplate which proposes application structure for Yii to use in large projects that require scalability.
Related
Is there any way of generating a Google : ads.txt file every time i build my SSR project?
There is a module called: sitemap-module from nuxt-community, it is used to generate a sitemap xml file, and that file can be accessed by http://domain.tls/sitemap.xml. and i want something like that.
So currently i'am achieving this by building the project, then manually put ads.txt it in : /var/www/site/.nuxt/dist/client/,
The problem with this is that everytime i rebuild the project i loose /var/www/site/.nuxt/dist/client/ folder then i have to add ads.txt file again.
I would like to know how i can hook up my code to tell nuxt to generate ads.txt file and put it in /var/www/site/.nuxt/dist/client/
Not sure if it makes sense, but i hope someone will understand.
Place your ads.txt file in a directory named static as mentioned here. All the contents of the static directory can be accessed via example.com/{filename.extension}
If you are not using nuxt.js and just using vue js, place it in a public directory right next to src directory.
Haven't found any way of solving this in nuxt, so i decided to redirect all https://domain.tld/ads.txt in Nginx configuration.
/etc/nginx/sites-available/default.conf
#redirect all txt request
location ~* ^.+.(txt)$ {
root /var/www/other.files/;
}
So i think i'll stick to it.
I have laravel 5 and config file in the config folder and My css located in the resources folder which is a same level with public folder where located index.php. Virtual Host Apache config looks to the public folder as a root site directory, but in this situation I cannot declare correct path from /public/index.php to the resources folder.
From one side I can try easy way and just relocate public folder into root of the laravel, but I don't like this way, any ideas?
Use resource_path('path/to/your/css')
https://laravel.com/docs/5.3/helpers#method-resource-path
EDIT
The most logical is to include your stylesheets in your public folder though. If you need to style a page, the style is public anyway. So why not put in the public folder. There's 2 options to do this:
Do it manually by just copying/moving the files
Use an automated tool like Gulp or Laravel's own Elixir, which provides a really easy way to copy your assets.
add this code in public/index.php
$app->bind('path.public', function() {
return __DIR__;
});
I have a dropwizard API app and I want one endpoint where I can run the call and also upload and image, these images have to be saved in a directory and then served through the same application context.
Is it possible with dropwizard? I can only find static assets bundles.
There is similar question already: Can DropWizard serve assets from outside the jar file?
The above module is mentioned in the third party modules list of dropwizard. There is also official modules list. These two lists are hard to find maybe because the main documentation doesn't reference them.
There is also dropwizard-file-assets which seems new. I don't know which module will work best for your case. Both are based on dropwizard's AssetServlet
If you don't like them you could use it as example how to implement your own. I suspect that the resource caching part may not be appropriate for your use case if someone replace the same resource name with new content: https://github.com/dirkraft/dropwizard-file-assets/blob/master/src/main/java/com/github/dirkraft/dropwizard/fileassets/FileAssetServlet.java#L129-L141
Edit: This is simple project that I've made using dropwizard-configurable-assets-bundle. Follow the instructions in the README.md. I think it is doing exactly what you want: put some files in a directory somewhere on the file system (outside the project source code) and serve them if they exist.
Going nuts :-)
I've installed the latest ASP.NET Core (RC2).
I'd like to be able to create a *.sln, with multiple *.csproj: one for server side development, and one for just client side development.
The reason we are keeping them separate is so that we can have the option of giving the the clientside *.csproj to external developers with better UI skills to work on without needing to know much about the server side code. They could work on the client side html/js using Visual Studio Code or other light weight IDE, and not requiring Visual Studio to get involved.
In the client *.csproj, I'd like to serve static files (html/js/css) for an angular project from the root directory, not from the wwwroot directory, so that gulpfile.js relative paths, etc are identical to how one would set up an angular project without Visual Studio.
As I understand it, the rules are now:
* use the webroot setting in hosting.json if hosting.json file exists.
* otherwise, use wwwroot.
* if that's missing, use root.
* See: https://github.com/aspnet/Hosting/issues/450
First, checked that I had set up static page routing. Created a wwwroot/index.html page. Tada! Works.
Now, renamed the directory to app/ and updated hosting.json to point to it. After a reload of the project, the app/ folder changed icon..good...run...no joy. Fight with it for a while. No success...
Then delete the app/ folder and hosting.json file altogether. End up definitely wanting to throw something...
The only way I'm getting static files is if the folder is called wwwroot. Whether I have a hosting.json file or not.
That's contrary to the documentation at: https://github.com/aspnet/Hosting/issues/450
Has anybody else succeeded in getting rid of the wwwroot folder? If so...how?!?!?
Thank you!
Although you can open up the root of your ASP.NET Core app for serving static files, it's not a good idea because once you do, there's nothing preventing someone from navigating to project.json or any other file in the root.
That being said, here's how you would go about serving up static files outside of wwwroot.
First, create a static class that returns IApplicationBuilder. In here you will define what physical path to make accessible along with an optional URL re-write of that path (see comments in the code):
using System.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting.Internal;
using Microsoft.Extensions.FileProviders;
public static class ApplicationBuilderExtensions
{
public static IApplicationBuilder UseRootResources(this IApplicationBuilder app, HostingEnvironment env)
{
//var path = Path.Combine(env.ContentRootPath); // WARNING - this opens up the root of the app
var path = Path.Combine(env.ContentRootPath, "static"); // this would allow for serving up contents in a physical path folder named 'static'
var provider = new PhysicalFileProvider(path);
var options = new StaticFileOptions();
// the below line re-writes the path name of the physical path, it can have the string value of anything you want to call it
options.RequestPath = ""; // in this example, an empty string will give the *appearance* of it being served up from the root
//options.RequestPath = "/static"; // this will use the URL path named static, but could be any made-up name you want
options.FileProvider = provider;
app.UseStaticFiles(options);
return app;
}
}
Next, in the Startup.cs, call that function from the Configure method:
app.UseRootResources((HostingEnvironment)env);
Now you can serve up static files outside of wwwroot! Referencing the static file in HTML will use the path you defined in the Options.RequestPath as set in the ApplicationBuilderExtensions class. Assuming you left the RequestPath to an empty string to simulate the root, you then call the resource like it lived there (even though it really lives in the 'static' folder) thanks to the magic of URL re-writing:
<img src="bus.jpg"/>
I've deployed laravel with this guide.
http://juniorgrossi.com/deploying-laravel-applications-on-a-shared-host/
On my webserver I have a public_html file now containing all my publicly accesable files and a laravel folder containing the rest, so I've split up the default laravel structure for deployment.
On my development server by default the public folder is resting inside the laravel folder instead of being on the same directory level.
The problem I'm getting though is when I use something like this:
// Upload the file
Input::upload('image', 'public/uploads', $filename);
Same with this.
// Upload the file
Input::upload('image', path('public') . 'uploads', $filename);
Instead of trying to use the uploads folder that is inside my public_html folder it tries looking for a public file inside my laravel folder now.
And I get a
Unable to create the "/uploads" directory
Ofcourse on my development server the public folder is still inside the folder so it's logical.
How do I fix this?
You may try this (add a slash after the folder name)
Input::upload('image', path('public') . 'uploads/', $filename);
Maybe try this....just as a test
Input::upload('image', URL::to_asset('uploads/'), $filename);
You can also try
Intervention/image package.
I'm using this and I find it very easy to use. It also has a resize and crop feature.
It's easy as:
Image::make(Input::file('file')->getRealPath())->save('uploads/' . $filename);
Fixed the paths.php to ../public_html
I've done this before but it failed since I accidentaly uploaded a png and my jcrop function wich crops and saves images failed because it currently onlt takes jpg. So that left me thinking my paths.php settings were no good while they actually were.
Thanks for helping out though everybody!
(I feel like a fool.)
In my case, I got the same problem. Then I created it manually, CHMODed the lil' bastard and it worked fine!
Making a long history short (not so long...): just permission!
If you have the permission to Write/Read to the folder, you'll be cool! If you don't, you change the permissions! If you are unable to change it, put the uploaded files where the permissions allows you to access the file.