We use CakePHP 2.7.9 and Minify plugin on a CentOS server running Apache 2.2.
https://github.com/maurymmarques/minify-cakephp
The plugin works fine and now we can minify css files like this.
echo $this->Minify->css(array('default', 'global'));
The code above generates URL like this.
http://example.com/min-css?f=default.css,global.css
And now we want to deny access to original files under webroot/css. How can it be done in CakePHP? We want to return 404 or 401 or something like that for direct URL access like this.
http://example.com/css/default.css
And now we want to deny access to original files under webroot/css
Simply don't but non public code and files into the public webroot. It's not recommended in any case. Point your minifier to the files and set its output folder to webroot.
We use task runners and keep the minification code outside of the actual app. This is stuff that doesn't belong into the application itself - IMHO.
We use php Robo and on the JS side Gulp for minification and automatically trigger the tasks on deployment. All our SCSS and JS files are outside of the webroot. We have just a few asset includes in our app code and they almost never change. Robo and Gulp have watchers that rewrite the asset files as we change them on when the app is deployed it automatically generates minified files.
Related
Using latest angular-cli, I created new project and everything works fine. Next, I tried to integrate it in Laravel 5.3. I have this project working with systemjs, but I want to switch to webpack and to take advantage of angular-cli.
Problem is that in angular-cli.json I can't specify that index is index.php, it only accepts HTML.
Basically, I can't start the Angular application at all with this setup.
How can I overcome this?
In the end I separated Laravel and Angular 2, as Cristian Sepulveda wrote in the comment. This is the recommended approach anyway.
I make API with Laravel and use it with Angular 2.
In my case I serve the angular app from laravel. I still use webpack to build my assets but have a gulp task which copies the angular index.html to be index.blade.php of which the laravel app serves.
I also use gulp to copy the built files from /dist to /public
I had the same problem and what I found is this related issue in their GitHub issues:
The output folder will always be entirely replaced. You can use the public/ folder to have your index.php which will be copied to your output folder, or output the app to a separate folder and copy the files yourself.
This is by design and will not change. This is a build output folder, not a deploy folder. You should separate those two steps.
So, you can't really achieve what you exactly want, but this is the only workaround I found.
I found only one solution for me.
create build for client side code by ng build --prod
Using gulp copy generated files into Laravel public dir gulp copy (here you can check if old build files exists remove them)
Using gulp-ingect plugin inject copied files into layout gulp inject
-- This can be used in CI and done with automation tools. In result we have inline.js and three *.**.bundle.js files injected. In same main layout i have statically add <base href="/example"> (you can use any defined in Laravel routes root path here) and inside template file which loaded from this path (in my case 'example.blade.php') add angular 2 root element <st-example>Loading...</st-example>
-- By this set up you have root Laravel layout which have inside required by angular 2 root url href and injected scripts files from build. And your template file for current route have root element inside (it included to main layout by simple blade yeild('content')).
P.S. also you must notice that if you are using some http requests in angular 2, after you integrate it into Laravel project this will add csrf protection middleware to each request... And if you have some new errors in requests which work previously just check headers.
Since angular-cli doesn’t allow you to specify index.php, let it be, simply specify index.html then there…
And add an appropriate route into Laravel routing. Like this one, for instance:
Route::any('{path?}', function () {
return File::get(public_path() . '/index.html');
})->where("path", ".+");
Btw, it’s simply a trap for any unknown routes… But I think you get an idea.
We have a build script that minimizes javascript/css and then copies it into the public folder.
What I'd like is for development boxes to load files from the app folder, where the unminimized scripts are stored on dev boxes, but still run the minimized scripts on production.
WHAT I'VE TRIED SO FAR:
-Changing the public path:
if (App::environment() == 'development') {
App::bind('path.public', function () {
return app_path() . '/unminimized';
});
}
This works for anywhere we use public_path(), but the front-end programmer uses relative paths, not URL::asset() (or whatnot), to load javascript (we use a framework, so this isn't easy to change). His javascript is still loaded from the public folder
-Changing nginx:
I've tried changing the root_path in nginx from /website/public to /website/code. This loads the javascript correctly, but then my routes don't fire.
Does anyone have any ideas how to accomplish this?
If you modify nginx to point to /website/code on the dev box and then copy the index.php file from /website/public to /website/code it should fix your routes.
You will need to modify the following lines in index.php:
require __DIR__.'/../bootstrap/autoload.php';
and
$app = require_once __DIR__.'/../bootstrap/start.php';
to match the new location so they can include those files correctly.
Seems rather round about...
Lemme see if i've something right first, are you writing your stuff in pre-compiler languages (scss/sass/less/coffeescript)?
If so then it shouldn't matter what you're doing with the uncompressed stuff since:
You should be testing your minified code before pushing to deploy
You should not be deploying both your minified code and your dev versions
Easiest way i see you solving this problem is using something like gulp-inject write a gulp task that you can pass a flag --dev or --prod which will manage which versions of files are inserted into your blade templates (have it default to --dev).
Naturally it would also be advantagous to write a similar task to undo those changes.
Then if you want to take it a step further have a dedicated VCS and manage your dev and production versions in different 'branches'.
I have just installed the Yii2 Basic Application Template using Composer.
This is now accessible on my localhost machine at the following URL:
http://localhost/basic/web
In Yii 1.1, it was possible to access a web application by simply going to :
http://localhost/basic
Having done some reading, it appears the only way to achieve the above is to create a new Apache vhosts entry. Whilst this is fine for one or two sites, if like myself you are working on new sites all the time, it is a bid tedious to have to set up vhosts for each and every site.
I have tried creating a .htaccess file to redirect all requests to web/index.php but this does not work. Is this at all possible to do in Yii2?
Move all the content in the /basic folder to eg. /basic-yii instead. Then take the /basic/web folder (now /basic-yii/web) and put all it's content into the /basic folder. Then adjust the paths for the require() calls in /basic/index.php to correctly point to autoload.php, Yii.php and web.php.
I am building a website which uses Apache + PHP on port 80 for the frontend, and Node.js + Socket.IO for dynamic updates on port 3000. There are quite a few shared Javascript resources between the two and I'd like to know how I can share them.
Here's my project layout:
project/
www/ // Apache DocumentRoot
index.php
js/ // Javascript files for the HTML pages
css/
app/
App.php // All the PHP files
node/
node_modules/ // Node modules installed by NPM
app.js // Node.js application
When my PHP application generates HTML code, it needs to put some <script> tags in <head> for things like underscore.js, backbone.js, socket.io.js, etcerea. But these scripts are all somewhere in de node_modules directory.
I have seen various examples but most use Node.js to serve the HTML page as well (usually using the express framework). So, they generate script includes like /socket.io/socket.io.js. But in my case I have two servers running on two ports.
So, how can I load the proper Javascript files without manually copying things from the node_modules directory to the js directory under the DocumentRoot?
There are 2 options:
Create a symlink (pointing from www/js to node_modules)
Create an Apache2 alias in you Apache configuration file (see here)
If you have access to your Apache2 configuration, the 2nd solution is probably the better one. When going for the symlink solution, make sure you double-check the ownership of the folders if you experience problems.
In a Zend Framework 1.10 application, I have a controller UsersController in a module api and in the index view of that controller I would like to reference a static asset (like a javascript file). How can I do that without putting the file in the main public?
so, we have a directory setup like this:
zfproj/
../application/modules/api/controllers/UserController.php
../application/modules/api/views/scripts/users/index.phtml
../application/modules/api/public/javascript/apimodule.js
../application/controllers/
../application/views/
../public/
I want to be able to include the apimodule.js in a view (in this case the users/index view). Ideally, this would able to be done without adding anything into zfproj/public
The intention behind this is to create a module that can be deployed into a ZF 1.10 application that is completely self-contained and does not require adding assets (like Javascript files) into the applications existing public/javascript files.
Typically all your publicly accessible assets go in public. It's meant to be the web root of your application and typically you set the DOCUMENT_ROOT of your apache virtual host to this folder. I'm not sure why you'd want to store client files (javascript, css, etc) outside the webroot. Can you elaborate more on your directory/application structure (maybe hinting at the location of the file you want to include)?
Edit
What you're asking should be possible. To make a standalone module, I think you'd just move "api" inside the primary public folder and the module would have its own bootstrap or you'd have to do something in your primary bootstrap based on the module name ("api" in this case). You'd have to modify your include paths accordingly. You'd need to add an .htaccess file to protect your code directories in this case.
../application/controllers
../public/api/controllers
../public/api/javascript/apimodule.js
../public/api/index.php
You might also create a symlink in your public folder that points to the public folder of api. So,
../public/api > ../application/modules/api/public
This would allow access to public but protect your code files. One thing I often do is check out subversion external into the public folder that just points to the public folder of the module. My CMS looks like this:
application/modules/cms
application/modules/cms/ui (public facing cms UI)
public/ui (svn:external pointing to application/modules/cms/ui)
HTH give you some ideas.