Laravel helpers return wrong paths on Heroku - php

Laravel paths helpers return wrong paths by adding app at the beggining of every path, like this is a directory here but isn't.
E.g. {{ resource_path('testing') }} returns /app/resources/testing. While it should return /resources/testing.
I do not have any app directory up to resources directory. It's standard almost fresh laravel application.
I did also web vendor/bin/heroku-php-apache2 public/. But still this problem occurs.
I found a few people have this problem, like here public_path() in Laravel 4.2 wrong on Heroku
But couldn't find any answer to this.
Currently I use this .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 ^ index.php [L]
</IfModule>
I never had problem like this and it is really strange for me.
I think it is related to heroku.

Related

Laravel Lighthouse-PHP GraphQL (Server cannot be reached)

I'm using Laravel - Lighthouse-PHP GraphQL server, and when I deploy it to production, I have to write public in the URL in order to work:
https://example.com/graphql (Server cannot be reached) ✗
https://example.com/public/graphql (Server connected) ✓
My .htaccess contains the following:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]
while inside the public folder, there's another .htaccess file, contains the below:
<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>
I tried editing(or removing) this file, but the whole website stopped working.
Any idea what I'm doing wrong?
In your webserver configuration make sure the root directory (the directory that is serving requests) is set tot the public folder instead of the root directory of your app as you have now.
You should only make the public folder publicly accessible, not doing so could result in an attacker to access or execute files they shouldn't or strange errors/behaviour (like what you are experiencing).
I also believe this will also fix the issues you are having since the public folder is not being rewritten which is probably picked up by the Laravel router for some reason.
I don't believe the issue is with Lighthouse but with how you are hosting your Laravel application, try and see if that can be fixed and if the problem persists.

Multiple Laravel project htaccess

I have a problem with .htaccess configuration for multiple Laravel projects on my Apache webserver. One project in the root folder and one project in a subfolder
File structure (/www)
/ <-- Laravel application #1
/anotherProject <-- Laravel application #2
When I'm visiting www.example.com/anotherProject then I get a 404 error (and www.example.com is working. The following .htaccess is activate in /public/ (for Laravel application #1).
/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]
</IfModule>
It feels like I need to change something in the .htaccess file of the project in the root folder. Has someone a suggestion to try?

htaccess problem on laravel, can't load css js and other routes

I have some problem with .htaccess on Laravel 7.16.1,
i have laravel installed on root folder something like this : /var/www/user/
i have renamed server.php on root folder to index.php
the problem is, laravel is index route is working fine but cannot access other route (eg. login, register, and my routes) also can't load assets (css,js) so the web is bare bone because it can't load css and js. but it can load css and js on public folder, like mydomain.com/public/asset.js. etc
i have tried several solution on stack overflow before by changing the .htaccess on root folder and public path, but none of them working !
here is my default htaccess on root folder
<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>
what is the correct .htaccess to solve this problem ? thank you.

Laravel project links not working on heroku

I was given a laravel project I need to get up and running. I am new to laravel, but after allot of work, I believe I got everything configured properly and I deployed the project to heroku.
When I do artisan serve on my guest machine in my laravel project and go to the given url everything works fine all the links works.
But I deploy it to heroku and my index page shows but none of the links work.
I get:
Not Found The requested URL /register was not found on this server.
It seems that running php artisan serve kinda activates the links, but how do I make that happen on heroku???
I should note the app is using blade.php files
What am I missing???
This is in the /resources/views
My _htaccess inside my public folder is as follows
<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 tried adding RewriteBase / doesnt help.
I also tried changing htaccess to:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

403 Forbidden Access to this resource is denied on server- Laravel 5.7

I'm working with a project in Laravel 5.7. Everything works in localhost. But, after uploading in the server, all routes for Backend Part is working. But post routes for Frontend Part is not working. It shows the error -
403 Forbidden Access to this resource on the server is denied
.htaccess in root folder 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>
Have someone face this problem before? What I've missed. In localhost everything is working fine, but not in Server.
I think you are not generating artisan key. Please run these command on server.
composer update
php artisan key:generate
Your htaccess hould be like this
<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 ^(.*)/$public /$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}]
For handling front end stuffs in /public add this to your .htaccess:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
.htaccess looks fine to me
Make sure your post routes are being called with form.
If there is no issue in your backend then
You need to grant permissions to server of these directories
give permissions to bootstrap/ and storage/ directory as shown below
sudo chmod -R 777 storage/ bootstrap/
Then it should work

Categories