问题
I am trying to find the way to organise my Laravel Application same as share hosting directory.
Example inside "server" folder
1.Install fresh laravel application
composer create-project laravel/laravel main-app --prefer-dist
2.Move "Public" directory up and next to main-app folder.Rename to public_html
3.Inside public_html folder also create new "app" folder to keep all the files like inside index.php
Summary
server
│
└───main-app
│ │ app
│ │ bootstrap
│ │ ......
│
└───public_html
│ app
│ │─── index.php
│
This is what I need to do.But I couldn't make this work! Each time I try to run artisan I got
chdir() no such file or directory (errno 2)
With Laravel 4 I was able to edit path.php and thats it.But L5 looks like one step back!
I already tried to extend Application.php class but unfortunately didn't work!
回答1:
Here is Solution !
1.Create MyApp.php class inside app folder to extend Applicaton.php class
<?php
namespace App;
class MyApp extends \Illuminate\Foundation\Application
{
public function publicPath()
{
return $this->basePath.DIRECTORY_SEPARATOR.'/../public_html/app';
}
}
2.Inside bootsrap/app use own class
Make sure comment out old one! , you don't need anymore
// $app = new Illuminate\Foundation\Application(
// realpath(__DIR__.'/../')
// );
$app = new App\MyApp(
realpath(__DIR__.'/../')
);
3.Make changes inside server.php to target index.php
if ($uri !== '/' && file_exists(__DIR__.'/../public_html/app'.$uri)) {
return false;
}
require_once __DIR__.'/../public_html/app/index.php';
4.Make changes inside index.php
require __DIR__.'/../../main-app/bootstrap/autoload.php';
and
$app = require_once __DIR__.'/../../main-app/bootstrap/app.php';
DONE
Now artisan working and Index.php live same as share hosting!
server
│
└───main-app
│ │ app
│ │ bootstrap
│ │ ......
│
└───public_html
│ app
│ │─── index.php
│
来源:https://stackoverflow.com/questions/33690681/install-laravel-5-locally-same-as-share-hosting-directory-deploy-l5-share-hosti