在共享主机子目录上部署Laravel [英] Deploying Laravel on a shared hosting sub-directory
问题描述
我正在尝试在共享主机上的WordPress子目录内部署laravel 5.5.我从Google尝试了太多建议,但仍然无法使用.它总是返回404错误. WordPress安装在/public_html
内部
我需要在/public_html/my-laravel-app
上安装Laravel
这是我的.htaccess
文件的外观:
I'm trying to deploy laravel 5.5 inside a WordPress sub-directory on a shared hosting. I tried too many suggestions from google but I still can't make it work. It always returns a 404 error. WordPress is installed inside /public_html
and I need to install Laravel on /public_html/my-laravel-app
Here's what my .htaccess
files look:
/public_html/.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# protect wpconfig.php
<files wp-config.php>
order allow,deny
deny from all
</files>
# protect the htaccess file
<files .htaccess>
order allow,deny
deny from all
</files>
# disable the server signature
ServerSignature Off
/public_html/my-laravel-app/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /my-laravel-app/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /my-laravel-app/public/index.php [L]
</IfModule>
/public_html/my-laravel-app/public/.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
/public_html/my-laravel-app/public/index.php(属于index.php的一部分)
require __DIR__.'/../bootstrap/autoload.php';
/*
|--------------------------------------------------------------------------
| 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';
推荐答案
我忘记更新此问题,但是我已经解决了此问题.
实际上与WordPress的.htaccess无关,我摆脱了自定义的.htaccess设置.
我所做的是,在public_html/laravel-app
上创建一个新文件夹,然后在我的laravel-app
内,
这是我克隆存储库的地方,所以它变成了public_html/laravel-app/my-app
然后,我将文件(文件夹除外)复制到my-app/public
目录中,并将其移至laravel-app/
.
I forgot to update this question, but I already solved this problem.
It's not actually about WordPress' .htaccess, I get rid of my custom .htaccess settings.
What I did was, create a new folder on public_html/laravel-app
then inside my laravel-app
,
this is where I cloned the repo, so it became, public_html/laravel-app/my-app
then, I copied the files(except the folders) inside my-app/public
directory and moved it to laravel-app/
.
$ cd /public_html/laravel-app
$ cp -a my-app/public/*.* ./
然后我通过运行
$ ln -sf my-app/public/*/ ./
然后,最后,我修改了public_html/laravel-app/index.php
在第22行和第36行,
Then, lastly, I modified the public_html/laravel-app/index.php
on line 22 and line 36,
require __DIR__.'/my-app/bootstrap/autoload.php';
$app = require_once __DIR__.'/my-app/bootstrap/app.php';
然后就完成了.
这篇关于在共享主机子目录上部署Laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!