Laravel 5.2 Error 500 (Internal Server Error) - laravel-5

I am trying to deploy a laravel project to a shared hosting platform but it keeps giving me this error 500 -Internal Server Error. It is currently working in my localhost. I have checked other site but with no avail even though .htaccess has been said to be the course but i am yet to figure it out. I have been trying for 5days but have not gotten it.
This is my .htacess file
<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>
If any other file is needed, i would provide. I need to deliver to a client.

If you cannot check the logs ( what would be the prefered way ) you can put this in your code
error_reporting(E_ALL);
ini_set("display_errors", 1);
Simply add it to the index.php of your public folder - if this is not working add it within the bootstrap of your app ( basically the very first thing called )
Then open the page and you will see the error.
Do not forget to remove these lines when the error is resolved
Usually the problem is missing access rights to the storage folder. If you use Filezilla for example simply rightclick the storage folder of your app and select File permission Ensure 777 is set and cascade it for every file and folder.

Related

Laravel migrations issue - remove the word 'public' in url

I moved my laravel instance to a new server.
I have updated the env file and the database connection file and the instance is working with the small exception of the url.
When I type the url: https://domain-name.com
"Forbidden
You don't have permission to access / on this server.
Apache Server at domain_name.com Port 443"
When I type: https://domain-name.com/public (I have to use the domain/public convention on all routes)
It all works fine. I have searched the forums etc and there are a few proposed solutions, none of which seem to work (The solutions range form updating the .htaccess file, to registing the url in the bootstrap/app.php files) none of which are making a difference.
Has anyone experienced this issue and can recommend a fix?
I have experienced this one, but I don't know if this will work for you.
1) Navigate to bootstrap folder and delete all the contents inside the cache folder.
2) Create an .htaccess file to your project's directory. If .htaccess file is already present, proceed to Step 3. You don't need a duplicate one.
3) In the .htaccess file, copy and paste this code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
4) Navigate to public folder (not the public_html folder). Public folder is present inside your Laravel's project. Create an .htaccess file and paste this code. Again, if .htaccess file is already present, just edit that file and copy the code 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]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
5.) That's it. Hopefully, this one will for you. Cross fingers

Why do I get a 404 to laravel 5.7 public subfolders?

I have a Laravel 5.7 project and I can't seem to understand why I get a 404 error to the subfolders in the public directory.
Directory structure
public
icons
css
file.css
Example of routes that work just fine:
localhost/images/image.png
localhost/css/main.css
However when i try to request a file deeper that the first subdirectory, i get a 404. For exaple:
localhost/pugins/common/common.min.js
file located in public/pugins/common/common.min.js
localhost/icons/weather-icons/css/weather-icons.min.css
file located in public/icons/weather-icons/css/weather-icons.min.css
Anything after localhost/FOLDER/ gets a 404 eror, even if it exists.
Any ides why?
This is the default .htaccess file:
<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 have noticed just now that the first level of the subdirectories of the public folder get a 403 (Forbidden) error while try to list that directory.
Example:
localhost/js => 403, Forbidden
localhost/js/dashboard/intro-inde.js => 404, Not found
localhost/js/script.js => 200, Working fine
Each file and directory exists in the examples above, and there is no problem with the permissions.
My guess is that it has something to do with the .htaccess, but i have no idea how that works >.>
I remembered i had no problems in previous projects using laravel 5.1 ~ 5.5. So I have copied the .htaccess file from those projects to this one. Now everything works fine, but for one folder and its subfolders : public/icons; I solved this problem by creating a new folder and moving everything from "icons" to "fonts-icons"
Behold the power of the new .htaccess. Maybe it will help someone.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# 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>
This one solved the problem...without the new for new routes. :D I still have no idea how it works and why, though.
Just for curiosity, maybe someone will enlighten me d=(^_^)=b
You should first define that route in the routes/web.php file.
Error 404 is when we do nnot find any pages. Which means we have to define route in our web.php file first so as to view desired content written in the blade.php file, This error may also appear if we have not saved the file in our views in .blade.php extension

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

Laravel on a shared hosting server returns error 500

I'm using a shared hosting server, I installed my first Laravel 5.4 application and everything is still working fine. A few days ago I installed another Laravel 5.4 application on a different domain, but same server, but when I try to access the URL, I get 500 INTERNAL SERVER ERROR.
Below is my .htaccess code
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
I also tried the following, but same error:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
### Add two lines for fix error 500 ###
Options -Indexes
php_flag xcache.cacher 0
#######################################
# 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>
You moved everything inside your public_html folder which you should not do. Only files inside /public needs to be in public_html, hence the name public. The Laravel files should be placed higher directory where it is not accessible from the public.
Install Laravel with Softaculous, or with composer via SSH in /home/username/laravel
Move everything in /home/username/public_html folder to
/home/username/laravel
Move everything in /home/username/laravel/public to /home/username/public_html and delete the public folder after move.
Edit this file: /home/username/public_html/index.php
Change to require '/home/username/laravel/vendor/autoload.php';
Change to $app = require_once '/home/username/laravel/bootstrap/app.php';
Save this file and close window.
Edit this file: /home/username/laravel/server.php
Change to:
if ($uri !== '/' && file_exists('/home/username/public_html'.$uri)) {
return false;
}
require_once '/home/username/public_html/index.php';
Replace username with your hosting username. :)

website.com/index.php/page works but website.com/page doesn't

Here is the website I'm specifically talking about: http://anomet.com.
The home page loads fine, but navigating to another page doesn't, unless it's prefixed with index.php. For example: http://anomet.com/index.php/lighting works, but http://anomet.com/lighting doesn't. The website was created using Laravel 5.4.15. The website is hosted on Bell's server, and when I called them, they said mod_rewrites should be enabled. I have proper permissions set on my storage folder as well (755), since I've read that not having proper permissions on the Laravel folder can cause this problem. Here is my .htaccess file below:
<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>
AddHandler phpCGI .xml .php
Action phpCGI /cgi-bin/php5.6fcgi
# for php5 and securewebexchange
<IfDefine SSL>
AddHandler phpCGI .xml .php
Action phpCGI https://secure9.securewebexchange.com/anomet.com/cgi-bin/php5.6fcgi
</IfDefine>
Is Bell wrong in saying that mod_rewrites is enabled? The tech support person didn't sound confident on the phone, and they didn't actually check the configuration files (i.e. httpd.conf or apache.conf) to see if it had anything like AllowOverride All or Require all granted inside of it.
Lastly, I have the exact same files uploaded to a Namecheap server (https://kdev.solutions/) and everything works on there, which further leads me to believe that the problem is with Bell's server configuration.

Resources