Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
505 views
in Technique[技术] by (71.8m points)

php - Deploying Laravel on a shared hosting sub-directory

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 (some part of 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';
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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/*.* ./  

Then I created a symbolic link for the directories inside my-app/public by running

$ ln -sf my-app/public/*/ ./

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

Then it's done.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...