Skip to content

Instantly share code, notes, and snippets.

@shankar-bavan
Created December 25, 2022 14:35
Show Gist options
  • Save shankar-bavan/44ca21f26128581638b6942c96de51cf to your computer and use it in GitHub Desktop.
Save shankar-bavan/44ca21f26128581638b6942c96de51cf to your computer and use it in GitHub Desktop.
Change Laravel public folder to public_html
  • Change your public folder name to public_html
  • Open server.php and change the public name to public_html in the same way as shown below.
<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <[email protected]>
 */

$uri = urldecode(
    parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);

// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public_html'.$uri)) {
    return false;
}

require_once __DIR__.'/public_html/index.php';
  • In the AppServiceProvider.php file, Register a new public path. Replace the register function with the following code. Our public path has changed to public_html.
public function register()
{
    $this->app->bind('path.public', function(){
        return base_path().'/public_html';
    });
}
  • Open config\filesystems.php and replace the following code. The following code of line will help you to create a storage link in the public_html folder by running this command

php artisan storage:link

'links' => [
    base_path('public_html/storage') => storage_path('app/public'),
],
  • Open webpack.mix.js public name with public_html in this file
const mix = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel applications. By default, we are compiling the CSS
 | file for the application as well as bundling up all the JS files.
 |
 */
 mix.setPublicPath('public_html/')


mix.version([
    'front/css/style.min.css',
]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment