laravel 5.4 not working on subdomain - laravel

Steps I followed till now:
create sub-domain.
uploaded project files of public inside public_html/subdomain-name/
create a folder subdomain-name in root
upload every files of laravel project except public folder inside subdomain-name folder
change 2 lines of index.php which is inside public_html/subdomain-name/ as to:
require __DIR__.'/../../../staging/bootstrap/autoload.php';
and
$app = require_once __DIR__.'/../../../staging/bootstrap/app.php';
And my htaccess files looks like:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I am getting error as:
This page isn’t working
staging.mydomain.com is currently unable to handle this request.
HTTP ERROR 500
Can somebody guide me with this? Thank You

2. uploaded project files of public inside public_html/subdomain-name/
When you create a subdomain, a folder appears in your root directory, you should upload project files of public into created subdomain folder. ie (example.your site.com) and not into public_HTML/subdomain
You should also try this in your .htaccess
Options -MultiViews
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]

Related

Hostinger web share shoting giving back 403 forbidden error

I am trying to deploy my laravel project through git hub on hostinger. The deployement through git actually work out and all the files are installed in subdomain where I want to deploy the project which is in public_html/absolute. The deployment on the surface installed all the files including the files in the public folder to the absolute subfolder. But when I got to the link https://coffeesojava.xyz/absolute/ it says 403 Forbidden, Access to this resource on the server is denied!. I am not sure what went wrong.
public_html/absolute/public/.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]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Copy the .htacces file from the public folder and paste it outside of the public folder
Rename server.php to index.php

After uploaded in the cPanel my Laravel project it's showing the 403 - Error message. How to solve the issue?

I have uploaded a Laravel project in cPanel. Project file uploaded in sub folder. I have created the .htaccess file [reference by forums and tutorials] but issue not solve. I am the beginner in Laravel, Please help me.
Folder Path : example.com->public_html->lrvproject->.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]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
go to the path lrvproject/public and inside public(folder copy all file and paste outside public folder) here step1 completed.
Step2 . example.com->public_html->lrvproject open index.php file here change the vendor and bootstrap file path like(/../lrvproject/vendor/autoload.php and
/../lrvproject/bootstrap/app.php

how to access website from a sub folder inside the root folder?

I am about to deploy a laravel project. I uploaded all the files and the website is working fine but the only problem is when i try to access my website i.e for example if i try to write mywebsitename.com in the url then public directory is shown which is because i have symblinked my laravel's public folder to the public_html folder. I don't have any idea about how to edit the .htaccess file in order to load the website with mywebsitename.com and not mywebsitename.com/public. My htacess files code 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]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
my file directory structure is shown in this image
please help me
I am guessing it is an apache server. If yes;
Ensure your domain mywebsitename.com points to the public_html
Add a .htaccess file in your root directory(public_html) and paste this in
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
I found a solution to this question.
1.Copy all the laravel files inside the public_html folder including the .htaccess file and the index.php file which is suppose to be inside the public folder(keep both the files inside the public folder).
2.Then link your storage to the public folder using SSH, for that open your SSH enter id and password and change directory using "cd domains/yourdomainname.com/public_html"
then give the php artisan command i.e "php artisan storage:link"
(note:- after changing the directory you can give all the php artisan commands like migrate and config:cache or clear:cache as you wish.
3.Now after the all the necessary commands are given you can access your fully functional website including the image display function if you type yourdomainname.com/public on the URL but if you type just your domain name then all the laravel files will appear on the browser to avoid this and to to jump inside the public folder directly create one more .htaccess file outside the public folder but inside the
public_html folder the copy the below given code and then if you just your domain name on the URL then your website will be directly displayed
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^ public [L]
You can use it with RewriteBase directive,
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /public_html/ # or '/' only depends on your vhost config
# 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 ^ index.php [L]
</IfModule>
I'm not familiar with apache server but the problem should be in the default index file.
For long terms considered, I advise you to use nginx or openresty, it's easier to configurate.

Laravel 5.8 showing 404 Not Found errors

I change the index.php file path public to root. After adding a .htaccess file in the root path (laravel 5.7) every page working fine. But in laravel 5.8 when I click another page, it's showing 404 Not Found.
My .htaccess file is below.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
#Send request via index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d``
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
The content of a Laravel .htaccess file should look like this:
<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 ^ index.php [L]
</IfModule>
Your webroot has to be set to the /public directory. Don't try to search for other solutions that move the index.php and .htaccess file from /public to the root directory of your Laravel application. There is absolutely no reason why you want to move the webroot from /public to /. index.php sits in /public for a reason. If your webhost does not offer the ability to move the web root to another directory switch your hoster.
It might be that you have created your folder as Example and trying to access it via example
ie
localhost/Example/public
yet accessing it like
localhost/example/public

Laravel showing directory file instead of redirecting to public/index.php

I am kinda new to Laravel and I am trying to do the next thing:
I have a Centos 7 running Apache and PHP on which I have different web apps running.
I have all apps in /var/www/html under folders and index.php links them all. Now i installed composer, Laravel and added a new Laravel project in /var/www/html/play/play1.
The problem is that when I try to access https://example.com/play/play1 I should get the Laravel index page (the one under public/index.php) correct?
Instead I get a directory with all Laravel project files.
If I access https://example.com/play/play1/public I can see the index page.
I've searched it over and I checked if AllowOverwrite all is present, if mod_rewrite is on. Inside public folder there is a .htaccess file.
Can anybody who dealt which such a problem help me please ?
Within the root of the project folder (where you see app/ resources folders etc) create a .htaccess file and paste the below:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
# 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 ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Laravel's root directory should not be the one accessed publicly - you have to point to public/ directory (where the index.php and .htaccess are located).
So in your server config http://example.com/play/play1 should point to var/www/html/play/play1/public

Resources