Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

filippo.toso's avatar

Laravel Mix with public folder outside the project folder

Hi,

since a couple of days ago I worked with Elixir. Then I decided to “upgrade” to Mix in order to keep up with the new features of Laravel 5.4.

Currently I have a working solution but it’s far from perfect. My application setup is as follows:

  • /project/ => project root folder (with the app, bootstrap, config folders)
  • /public_html => the document root accessible from the web

I have chosen to move the public folder outside the project root because I’m using Laravel on a shared hosting and I wanted to keep the application scripts and framework code inaccessible from the web. This solution worked fine with Elixir and gulp but with Mix I got into troubles.

This is an excerpt from webpack.mix.js:

const { mix } = require('laravel-mix');

mix.setPublicPath('../public_html');

 mix.styles([
     'resources/assets/metronic/assets/global/plugins/font-awesome/css/font-awesome.css',
     'resources/assets/metronic/assets/global/plugins/simple-line-icons/simple-line-icons.css',
     'resources/assets/metronic/assets/global/plugins/bootstrap/css/bootstrap.css',
     'resources/assets/metronic/assets/global/plugins/bootstrap-switch/css/bootstrap-switch.css',
 ], '../public_html/css/global-styles.css');

The mix.setPublicPath() is required to make sure the mix-manifest.json is saved in the right directory (otherwise the mix() helper will not be able to find the requested asset in the manifest).

The problem is that, with this kind of configuration, the mix-manifest.json file will contain something like this:

{
  "../public_html/css/global-styles.css": "../public_html/css/global-styles.css"
}

The urls are “wrong” meaning that the mix() helper is unable to resolve them correctly whatever input path I give it (the function can’t find the asset or doesn’t return the correct URL due to the “../public_html” part).

Currently I overwritten the mix() helper to handle the situation (namely remove the ../public_html from the input path and output url) but I’m sure there’s should be a better way.

I tried to understand how Laravel Mix works reading it’s source code but it’s a bit beyond my current level of knowledge.

Is there anyone out there that had the same problem and was able to solve it without using strange ninja tricks?

Thanks!

0 likes
5 replies
newbro's avatar

I have the exact same problem. I can get away with using the assets() helper, however if I need to use mix() helper for the cache busting it will failed as mentioned by OP.

Bradley James Ahrens's avatar

I'm having the same problem.

I have tried a lot of different things, such as doing something such as

within the master layout

or

mix.webpackConfig({ output: { path: "public", publicPath: "public_html/myapp" } });

in the webpack.mix.js file.

Neither attempt seems to have worked. Does anyone else have any other ideas?

laraman's avatar

Have any one solved the problem ? I got the same problem.

jlrdw's avatar

Why the concern on compiling assets, rather than loading only the css or js being used by current page. Unless you have a Fedex size site little difference is made.

Taylor gives example of public folder

.example {
  background: url(/images/example.png?d41d8cd98f00b204e9800998ecf8427e);
}
abhaimishra's avatar

In my case Laravel mix with vue js SPA application, I got the same problem. home page is not show anything.

Please or to participate in this conversation.