I just deployed a Laravel app into Hosting site, and place it into their folder like this:
"example.com/public_html/{All files in a laravel directoy}"
Now, if open in a browser, https://example.com it will show error
Fatal error: require(): Failed opening required '/home/customer/www/example.com/public_html/public/../vendor/autoload.php' (include_path='.:/usr/local/php74/pear') in /home/customer/www/example.com/public_html/public/index.php on line 34
my routes/web.php looks like this:
Route::get('/', function () {
return redirect()->route('login');
});
I already ran composer install and add htaccess to the inside public_html folder
The htacess, looks like this
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR] RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]
Is my htaccess wrong, or is there any additional setup for Laravel if using htaccess to point index.php to public folder?
Note: The hosting site, set the default document root to public_html and I can not change it. So in order to point to the public folder, I need to create .htaccess file
CodePudding user response:
Place .htaccess
file to your root folder and activate mod_rewrite
.
Here's an example of what the file should contain without determining specific addresses:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
I think that it doesn't work in your case because of the condition rules.
CodePudding user response:
- Copy the Laravel contents in a directory that's hidden from the outside, one different than
public_html
. Let's suppose that it's/home/user1/myapp
. - Move the contents of the Laravel
public
directory to thepublic_html
. So, you should move/home/user1/myapp/public/*
toexample.com/public_html
- Change the relative routes inside
index.php
to point to the directory of the first step.