在共享主机子目录上部署Laravel

时间:2017-10-23 13:04:47

标签: php wordpress laravel .htaccess shared-hosting

我正在尝试在共享主机上的WordPress子目录中部署laravel 5.5。我从谷歌尝试了太多的建议,但我仍然无法使它工作。它总是返回404错误。 WordPress安装在/public_html内 我需要在/public_html/my-laravel-app上安装Laravel 这是我的.htaccess文件的外观:

/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';

2 个答案:

答案 0 :(得分:1)

我忘了更新这个问题,但我已经解决了这个问题。 实际上并不是关于WordPress&#39; .htaccess,我摆脱了我的自定义.htaccess设置。 我做的是,在我public_html/laravel-applaravel-app创建一个新文件夹, 这是我克隆回购的地方,所以它成了,public_html/laravel-app/my-app 然后,我复制my-app/public目录中的文件(文件夹除外)并将其移至laravel-app/。然后我通过运行

my-app/public内的目录创建了一个符号链接
ln -sf /path/to/file /path/to/symlink

然后,最后,我修改了public_html/laravel-app/index.php 在第22行和第36行,

require __DIR__.'/my-app/bootstrap/autoload.php';
$app = require_once __DIR__.'/my-app/bootstrap/app.php';

然后就完成了。

答案 1 :(得分:0)

Laravel没有开箱即用的子文件夹。您需要调整一些文件才能使其正常工作。请查看laravel-news.com

上的以下文章

我的建议是重新考虑您的方法,看看是否有不同的方法来实现您的目标,并不需要子文件夹。

编辑:

我希望在文章中包含更多步骤,以防将来删除,但步骤太多。

相关问题