How to change public folder to public_html in laravel 5
Quite easy to find this with a simple search.
See: https://laracasts.com/discuss/channels/general-discussion/where-do-you-set-public-directory-laravel-5
In your index.php add the following 3 lines.
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__.'/../bootstrap/app.php';
// set the public path to this directory
$app->bind('path.public', function() {
return __DIR__;
});
Edit:
As Burak Erdem mentioned, another option (and more preferable) is to put this in the \App\Providers\AppServiceProvider
register()
method.
/**
* Register any application services.
*
* @return void
*/
public function register()
{
// ...
$this->app->bind('path.public', function() {
return base_path('public_html');
});
}
How to change public folder to public_html in laravel 8?
You have to follow 2 steps to change your application's public folder to public_html then your can deploy it or anything you can do :)
Edit
\App\Providers\AppServiceProvider
register() method & add this code .// set the public path to this directory
$this->app->bind('path.public', function() {
return base_path().'/public_html';
});Open
server.php
you can see this codeif ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}
require_once __DIR__.'/public/index.php';
Just Replace it with :
if ($uri !== '/' && file_exists(__DIR__.'/public_html'.$uri)) {
return false;
}
require_once __DIR__.'/public_html/index.php';
Then serve your application with php artisan serve
, you also can deploy it on your Cpanel shared hosting where primary document root public_html
How to change public directory to public_html directory for Laravel Mix
@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]
How to point laravel project to a public folder under public_html in shared hosting
Since you're using shared hosting, you need to change the document root of the domain to public_html/public. Then you need to point index.php to your Laravel project (which must only be located outside the public_html folder) by editing the following code:
require DIR.'/../../MyOtherDomain.com/vendor/autoload.php';
$app = require_once DIR.'/../../MyOtherDomain.com/bootstrap/app.php';
Note- MyOtherDomain.com folder should contain the Laravel project.
How to get public directory?
Use public_path()
For reference:
// Path to the project's root folder
echo base_path();
// Path to the 'app' folder
echo app_path();
// Path to the 'public' folder
echo public_path();
// Path to the 'storage' folder
echo storage_path();
// Path to the 'storage/app' folder
echo storage_path('app');
Related Topics
Notice: Trying to Get Property of Non-Object Error
Find Highest Value in Multidimensional Array
Fpdf Error: Some Data Has Already Been Output, Can't Send Pdf
Trying to Get Property of Non-object In
How to Login in With Curl and Ssl and Cookies
What Does "1" Mean At the End of a PHP Print_R Statement
Redefine Built in PHP Functions
Reference - Composer Error "Your PHP Version Does Not Satisfy Requirements" After Upgrading PHP
How to Combine Two Arrays Together
PHP: Warning: Sort() Expects Parameter 1 to Be Array, Resource Given
Jquery Ui Sortable, Then Write Order into a Database
On Delete Cascade With Doctrine2
Magento - Quote/Order Product Item Attribute Based on User Input
Is Native PHP Support For Web Sockets Available
Best Way to Manage Long-running PHP Script