Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.1K
Vistas
How to change public directory to public_html directory for Laravel Mix

I'm using Laravel 8 and I wanted to install Sweet Alert. So after downloading it and adding require('sweetalert'); to bootstrap.js, I ran the command npm run production.

Then I have included this in my master.blade.php:

<script src="{{ asset('/js/app.js') }}"></script>
@include('sweet::alert')

Now because I had changed my public directory from public to public_html, Laravel asset() function would call the public_html/js/app.js and this is wrong because Laravel Mix generated app.js and app.css in the public directory.

So the question is how can I change the default generation of Laravel Mix which is public to public_html ?

Here is my AppServiceProvider.php:

public function register()
    {
        $this->app->bind('path.public', function(){
            return base_path() . '/public_html';
        });
    }
over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

@Alfian has answered your question. But the solution you asked for, is not recommended when you are talking about renaming the public folder. You should not really rename your public folder while using Laravel.

But I can understand why you renamed it, to declare the default root folder. But there are better solutions instead of renaming it. And then there will be no such question too.

Best Solution: Upload the Laravel project as it is in the public_html folder. Go to your cPanel and enter Domains/Addon Domains/Subdomains (which type domain you are using) section and just change the Document Root as /public_html/public. You are done.

Update:

If it's a primary domain or addon domain there may not be an option directly to change the document root. Then we can just add a rule in the .htaccess file. Use this:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
over 4 years ago · Santiago Trujillo Denunciar

0

You can change configuration compiled assets directory on webpack config files, by default laravel set webpack at webpack.config.js

Here more documentation about compiling assets laravel

Laravel 8 Compiling Assets

over 4 years ago · Santiago Trujillo Denunciar

0

In .env change ASSET_URL=https://yourdomain.com/public_html. But its a bad practice to have index along with php code(app, vendor, etc..)

You can create symbolic link from public to act as public html like follows

ln -s /full/work/path/laravel-project/public /full/work/path/public_html

But you might need to remove public_html first

mv public_html tmp

I assume your structure would be

full/work/path/
   - laravel-project
       - public
   - public_html
   ...
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda