Laravel 部署共享托管子域
Laravel deployment shared hosting subdomain
嗨,我花了几个小时让我的网站在共享主机上运行,但什么也没发生(本地没问题),
搜索了几个主题并遵循了教程,但无法解决无法加载 bootstrap 和 livewire 组件的问题。
我按照经典步骤将 public 文件夹复制到我的子域的根目录,其他文件位于子域路径内的单独文件夹中,例如 Laravel 文件夹
我更改了 public/index.php,我得到了类似 this
的内容
如您所见,livewire 和 bootstrap 不起作用。
我还尝试让文件夹保持原始状态,并将路径设为 public,结果就像 this,一切正常!
无效的索引路径 css 和 livewire:
<?php
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Check If Application Is Under Maintenance
|--------------------------------------------------------------------------
|
| If the application is maintenance / demo mode via the "down" command we
| will require this file so that any prerendered template can be shown
| instead of starting the framework, which could cause an exception.
|
*/
if (file_exists(__DIR__.'/../storage/framework/maintenance.php')) {
require __DIR__.'/../storage/framework/maintenance.php';
}
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| this application. We just need to utilize it! We'll simply require it
| into the script here so we don't need to manually load our classes.
|
*/
require __DIR__.'/laravel/vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/
$app = require_once __DIR__.'/laravel/bootstrap/app.php';
$kernel = $app->make(Kernel::class);
$response = tap($kernel->handle(
$request = Request::capture()
))->send();
$kernel->terminate($request, $response);
我知道我没有放 /../,因为如果我放它,我会收到无法识别路径的错误,可能是因为它是子域,并且没有 public_html 文件夹。
是什么导致了这个问题? bootstrap 的路径是正确的..
Web.config :
<!--
Rewrites requires Microsoft URL Rewrite Module for IIS
Download: https://www.iis.net/downloads/microsoft/url-rewrite
Debug Help: https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules
-->
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)/$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="/{R:1}" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
htaccess :
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
来晚了,但希望对未来的观众有用
根据我看到的评论,您正在使用 Hostinger,
这是一个快速解决方法,
在您的主机帐户中 > select
Hosting Account > Domains > SubDomains
输入子域名并
check the custom folder for subdomain
输入项目的路径,然后输入 laravel
的 public 目录
例如,
/home/u796769252/public_html/<subdomain>/public
瞧,
您现在可以将 laravel 核心文件粘贴到 suddomain 并将 public 文件夹文件粘贴到 public 文件夹。
我写了一篇 blog,其中提到了如何在不编辑 laravel 核心文件的情况下将 laravel 应用程序发布到共享主机。
嗨,我花了几个小时让我的网站在共享主机上运行,但什么也没发生(本地没问题), 搜索了几个主题并遵循了教程,但无法解决无法加载 bootstrap 和 livewire 组件的问题。
我按照经典步骤将 public 文件夹复制到我的子域的根目录,其他文件位于子域路径内的单独文件夹中,例如 Laravel 文件夹 我更改了 public/index.php,我得到了类似 this
的内容如您所见,livewire 和 bootstrap 不起作用。
我还尝试让文件夹保持原始状态,并将路径设为 public,结果就像 this,一切正常!
无效的索引路径 css 和 livewire:
<?php
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Check If Application Is Under Maintenance
|--------------------------------------------------------------------------
|
| If the application is maintenance / demo mode via the "down" command we
| will require this file so that any prerendered template can be shown
| instead of starting the framework, which could cause an exception.
|
*/
if (file_exists(__DIR__.'/../storage/framework/maintenance.php')) {
require __DIR__.'/../storage/framework/maintenance.php';
}
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| this application. We just need to utilize it! We'll simply require it
| into the script here so we don't need to manually load our classes.
|
*/
require __DIR__.'/laravel/vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/
$app = require_once __DIR__.'/laravel/bootstrap/app.php';
$kernel = $app->make(Kernel::class);
$response = tap($kernel->handle(
$request = Request::capture()
))->send();
$kernel->terminate($request, $response);
我知道我没有放 /../,因为如果我放它,我会收到无法识别路径的错误,可能是因为它是子域,并且没有 public_html 文件夹。 是什么导致了这个问题? bootstrap 的路径是正确的..
Web.config :
<!--
Rewrites requires Microsoft URL Rewrite Module for IIS
Download: https://www.iis.net/downloads/microsoft/url-rewrite
Debug Help: https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules
-->
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)/$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="/{R:1}" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
htaccess :
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
来晚了,但希望对未来的观众有用
根据我看到的评论,您正在使用 Hostinger,
这是一个快速解决方法,
在您的主机帐户中 > select
Hosting Account > Domains > SubDomains
输入子域名并
check the custom folder for subdomain
输入项目的路径,然后输入 laravel
的 public 目录例如,
/home/u796769252/public_html/<subdomain>/public
瞧,
您现在可以将 laravel 核心文件粘贴到 suddomain 并将 public 文件夹文件粘贴到 public 文件夹。
我写了一篇 blog,其中提到了如何在不编辑 laravel 核心文件的情况下将 laravel 应用程序发布到共享主机。