I wanted to deploy my Laravel 5 App on the webhost one.com
I followed along some tutorials on the internet and moved my puplic folders content into the root folder of the host and made the required path changes to the index.php file.
But now I've got the
403 Error: You don't have permission to access / on this server.
I believe it's because of my .htaccess file:
Options -MultiViews
RewriteEngine On
DirectoryIndex public/index.php
# 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 ^ public/index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
I'm new to .htaccess files and maybe you guys can help me! :)
The 403 forbidden status you have, can be triggered by many things. I hope you get started by checking the following:
Create (or access) an existing file with your document root. Is this file accessible? If accessible, something in your .htaccess is off. If not accessible, probably not access is granted (yet), please add to your .htaccess:
Require all granted
When the test file is still not accessible, this could be a side effect of the 'Redirect Trailing Slashes If Not A Folder', please change this to:
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
Another addition to your .htaccess could also solve the issue:
RewriteBase /
Let me know if (or not) your issue is resolved.
Related
I am working on creating a website that converts text into speech. I am using the script from codecanyon which is Developed with PHP 7.4.x and Laravel 8.4.x . The issue I am facing is that I don't want to show /public URL as a permalink to access the website. Now, if I type mywebsite.com/pubic then the website is accessible otherwise if I write mywebsite.com then it only shows the files. I followed some of the previous queries posted on StackOverflow but got no results.
The topic I followed is Laravel 5 – Remove Public from URL
I tried even by renaming server.php , copying .htaccess and rewriting it. But those all resulted in a screen showing up errors or even blank.
My .htaccess file is;
<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]
To remove the /public from the URL you are not going to use the .htaccess file.
What you are going to do instead is set the /public folder as the serving directory for your Server.
If you use Apache, just go to your /etc/apache2/sites-available/000-default.conf file and change the DocumentRoot from {your base folder}/ (usually /var/www) to {your base folder}/public
The content of public folder should go to the public folder of your server (fe it's public_html on my server), and everything else should be stored in a different folder (fe laravel_mywebsite). Then you should go to public_html/index.php and change the folder paths based on where you put your Laravel app.
If you want to only use .htacces, you just need to rewrite all requests from /public to /
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,R=301]
I am trying to upload a basic site made under Laravel FW. I uploaded the site outside the public_html folder in a folder called laraveltest. I moved the public folder from here to the public_html folder. In this folder I have the index.php file and I changed two lines to :-
inside (public_html/public/index.php)
require __DIR__.'/../laraveltest/vendor/autoload.php';
$app = require_once __DIR__.'/../laraveltest/bootstrap/app.php';
I also changed my .env files that located outside public_html folder, and there a is a folder in the root called laraveltest. I changed the username/ database name and also the password.
When i load the site now, i used to get the page says Index Of / .
After doing some research and youTube videos, I then added a .htaccess file inside the (public_html) folder.
.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]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ public/index.php [L]
</IfModule>
Now when I reload the page, I get an error
This page isn’t working mylivewebsite.com is currently unable to handle
this request. HTTP ERROR 500
I have also checked the permission and it is all set to 0777 as well.
Please let me know how can I make my website run correctly.
2 questions actually:
How do I setup a Laravel site in a subfolder?
How do I flush/clear the cache?
My current situation:
I'm on shared hosting (don't mock me....I know dedicated server is better....trying to figure out how much budget to allocate for it so currently using shared since I can pay monthly) and can't use SSH.
URL structure is like this: website.com/v2 where "v2" is the subfolder where the site is installed on.
Is this the way my .htaccess and index.php are supposed to be setup?
.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /v2/
# 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}]
index.php
require __DIR__.'/../v2/bootstrap/autoload.php';
$app = require_once __DIR__.'/../v2/bootstrap/app.php';
For clearing the cache, I got this code in routes.php:
Route::get('/v2/configcache', function() {
$exitCode = Artisan::call('config:cache');
print_r($exitCode);
});
Are all of the codes above setup correctly? When I go to mywebsite.com/v2/configcache, I get an "Under Construction" message.
I need to clear the cache because I updated the database info.
I'm trying to deploy a laravel app on shared hosting. Here is what I did.
I zipped the entire laravel-app directory on my local machine.
I uploaded it and then unzipped the app in the public_html folder on the server.
I changed the file permissions of the public_html/larvel-app and public_html/laravel-app/storage and public_html/laravel-app/public to 777.
I removed the line 'public' in the .gitignore file.
I then copied the index.php and .htaccess file from laravel-app/public to the homepage and pointed to the necessary autoload folders (the ones about require and the $app variable to laravel-app/public).
Problems: If I navigate to my-website homepage, all the HTML for the homepage is being pulled in but no CSS or JavaScript or images. If I navigate to my-website/laravel-app/public, I see an internal server error message (error 500). However I have been able to view the files of other folders in the laravel-app subdirectory.
I include a copy of my .htaccess file code here.
<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>
I have a website with this in the .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?menu=$1 [L,QSA]
#DirectoryIndex index.php
My problem is even, if I change a single letter the website is rendering a 500 Error. Even if I empty complete file, it still shows me the 500 Error.
What I want to do is, there is a page like this on the domain
http://www.example.co.uk/brochure/generate.php
The file generate.php does exist in /brochure/ directory.
But still the generate.php does not load and it is loading the index.php file.
Any help?
Try the following which I know should work:
<IfModule mod_rewrite.c>
#Turn the Rewrite Engine ON
RewriteEngine On
#Set the base where to rewrite the requests
RewriteBase /
#Allow direct file access
RewriteCond %{REQUEST_FILENAME} !-f
#Allow direct directory access
RewriteCond %{REQUEST_FILENAME} !-d
#Disallow certain files.
RewriteCond %{REQUEST_FILENAME} !brochure\/generate\.php$
#Rewrite URLS To GET[menu] and make sure this is the last rule.
RewriteRule ^(.*)$ index.php?menu=$1 [L]
</IfModule>
if you do not see any rewriting taking palce then check to see the module for rewrite is installed.
If an empty file triggers a 500 status code as well, then the error is somewhere else: you are not editing the real .htaccess file being used by Apache, the error comes from the application, etc.
In any case, you should find the error log: that's where the exact details are shown. In Linux, it's normally under /var/log/httpd. In Windows, it can be under %ProgramFiles%\Apache Software Foundation\Apache2.2\logs. If it's a shared hosting account, you'll probably have an "Errors" or "Logs" feature in your control panel.