Laravel remote server error 500, site doesn't works - php

It's my first upload to a remote server of a Laravel site.
Local I have configured a vhost so my access to my site is like:
site.domain.com //it's pointing htdocs/laravel-proyect/public
I have uploaded my site to my remote server, then:
Change permisions on storage and all its directories
Change permisions to bootstrap
Change configuration of app.php
'url' => 'http://site.domain.com',
Change configuration in database.app with new parameters (as well as in email.php)
Load all tables and data in the data base
Then I try to load my site and get a 500 Internal Server Error
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
It works a little, I have this code in routes.php:
// Begins in the login view
Route::get('/', function()
{
if (!Sentry::check()) {
$data = array();
if (Session::has('email')) {
$data = array('email' => Session::get('email'));
}
return Redirect::route('login', $data);
}
else
return Redirect::route('users');
});
/ ========================================
// LOGIN, LOGOUT AND ACTIVATION SECTION ==========
// // ============================================
// show the login page
Route::get(MyHelpers::textLang('login','routes'), array('as' => 'login', function()
{
if (Sentry::check())return Redirect::route('users');
else {
$rules = User::$rules_login;
// show the login page (app/views/frontend/login.blade.php)
return View::make('frontend.login', compact('rules'));
}
So at first time mo url look like:
site.domain.com/entrar
'entrar', (login in spanish), y set by MyHelpers::textLang('login','routes'), access to my class MyHelpers and to lang files to translate 'login' in to 'entrar', but dont load the template.
Begins to :
Read documentation, making some changes: deleting Multiviews from
.htaccess (deprecated), adding RewriteBase to .htaccess too.
Copy /public content to base dir and change paths in bootstrap/paths and
in the index.php files.
Reinstall in two remote servers to verify is not my provider failing (same error). Talking to my provider, supouse
there are no errors on the server.
I create a new htaccess in the base dir redirecting routes to /public.
Try with php 5.4, 5.5 and 5.6
Actually my .htaccess is:
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
And I have no more ideas and cant find other solutions as related here.
Any idea? Please, I'm getting crazy, on wensday I have to beguin a new proyect and still working with this one.
Thanks

I have to add
RewriteBase /
to the .htaccess

I have a demo laravel application on heroku Simple Blog.My .htaccess file is:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
#other lines for gzip
It seems that there is no issue with your .htaccess file. It may be problem with you code logic. If you are getting no error with same code on localhost, then check your config again. For laravel 4, there is already a similar issue on stackoverflow Laravel 4 Virtual Host and mod rewrite setup
Note that laravel 5 (if you are using it) takes input (database connection and other setting) from .env file.
If you are still getting error then try to send simple response on index page like:
Route::get('/','basic configurations are correct');
and then make it complex step by step. It will help you in finding error.

Answer from #kikerrobles really works.
your final .htaccess file should look like following
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /
# 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>

Related

Laravel 5.3 Cannot find login page

I am just beginning to learn laravel and I have been looking all over for this answer. I was following a tutorial step by step to get it started and I have it running the welcome screen but if I click login or register it says that the file doesnt exist. However if I make the route.
Route::get('/', function() {
return view('auth/login');
});
It finds the page and displays it.
here is the link to the login page.
<div class="panel panel-success">
<div class="panel-heading">List of Game of Thrones Characters</div>
#if(Auth::check())
<p>Success</p>
#endif
</div>
<?php
echo getcwd() . "\n";
?>
#if(Auth::guest())
You need to login to see the list 😜😜 >>
#endif
In the href tag I have tried /auth/login, /login, and any combo you can try and it will not find the file no matter what. Here is the route I am trying to get this to work.
Route::get('/login', function() {
return view('auth/login');
}
Can anyone explain why this isnt working? I have looked everywhere and it seems to be the correct way to call this. Remember I have just gotten the beginning templates to work.
You need to setup web server rewrites in your webserver.
The simplest way to handle that is to use a .htaccess file in your public/ directory. This is the default .htaccess file for Laravel 5.3:
<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>
You also need to ensure that the mod_rewrite Apache module is enabled. You can do that by running these two commands which enable the module and restart Apache:
a2enmod rewrite
service apache2 restart

Laravel - How to remove index.php from Laravel in windows xampp

Problem:
my routes not working except the root home page, I'm searching for two days to find a solution to this problem and what I found that I should change .htaccess file but solutions didn't fix any for my case, at first the url localhost/quotes/public was working well with me, but at some point I'm not sure what is it this issue showed up
what I tried:
create another route and I made sure that no routes are working only
home route, still not working except home
tried to change OverrideMode on my XAMP from None to All, didn't fix any
tried to type manually localhost/quotes/public/index.php BOOM everything
works ..
my htaccess 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>
working on:
Windows 10
XAMP
Laravel 5.2.35
The problem is that your .htaccess is rewriting everything to the frontcontroller, which is normally located at {host}/index.php. In your application however it is located at {host}/quotes/public/index.php.
So you have 2 options:
1. virtual host
Set up a virtual host in your XAMPP Apache that points ie. myapp.local to htdocs/quotes/public Here is an example of how to achieve this: how to create virtual host on XAMPP. (Don't forget to add the host to your hosts file and have it point to your local macine on 127.0.0.1) You can then access your application on myapp.local/whatever-route-you-define. Alternatively you forget about XAMMP and install the homestead virtual machine, which comes preconfigured for this.
2. rewrite rule
Change you rewrite rule to rewrite all requests to quotes/public/index.php in stead of index.php. I'm no htaccess expert, but I believe it should be as simple as changing this:
RewriteRule ^ index.php [L]
to this:
RewriteRule ^ quotes/public/index.php [L]
Do note that you'll still need to access your application trough localhost/quotes/public/whatever-route-you-define which is not ideal imo. Your dev version should be as close to your live version as possible, and if you start working with absolute and relative paths and stuff in your code things will become a mess sooner rather then later.
Personally I would go for Homestead, I use it all the time and it works great once you have it running.
Btw, the reason why localhost/quotes/public/index.php is working for you right now is because RewriteCond %{REQUEST_FILENAME} !-f tells Apache not to rewrite any requests to files that actually exist (otherwise you wouldn't be able to access static assets like your css).
The .htaccess file must be at the root of the application.
Add this in this file :
RewriteEngine On
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
Assuming you haven't touched the original architecture of Laravel, and that public data is still in the same place : the public/ folder
You can also follow this good tutorial
Let me give you an example of the way I have my routes setup.
In app\Http\routes.php, here are three sample routes that I have.
Route::get('/', function () {
$values = app('App\Http\Controllers\KeywordController')->index();
dd($values);
return view('welcome');
});
Route::get('googlefile', function () {
$output = app('App\Http\Controllers\KeywordController')->printToFileGoogle();
dd($output);
});
Route::get('bingfile', function () {
$output = app('App\Http\Controllers\KeywordController')->printToFileBing();
dd($output);
});
I have WAMP setup on my environment. I have made a controller at app\Http\Controllers\KeywordController.php. If my browser is set to localhost/googlefile, then it will goto the method printToFileGoogle() in KeywordController.php.
Please try something similar to this and tell me if you get an error and if you do what error you get.

Redirect to php script using htaccess

For a web-application I would like to rewrite the URL.
From:
http://example.com/api/logger/all
To:
http://example.com/api/index.php/logger/all
So I tried the following:
RewriteEngine On
RewriteCond %{REQUEST_URI} !/index.php/
RewriteRule ^api(.*)$ api/index.php$1 [L]
I also testet it successfully with http://htaccess.madewithlove.be/.
On the server I get a 404.
My project struct looks like following:
--api
----index.php
--htaccess
--index.html
Update:
I found a solution for external redirects.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !(index\.php)
RewriteRule ^api/(.*)$ /api/index.php/$1 [R=302]
But I need a internal redirect and if remove [R=302] I get 404 with "No input file specified." as response.
Following htaccess file works for
http://example.com/logger/all.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !(index\.php)
RewriteRule ^(.*)$ /api/index.php/$1
But adding api again results in "No input file specified."
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !(index\.php)
RewriteRule ^api(.*)$ /api/index.php/$1
mod_rewrite is a double-edged sword that is incredibly easy to misuse.
Apache 2.2.16 and later provide the extremely useful but surprisingly seldom used FallbackResource directive.
So use the following layout:
--api
----.htaccess
----index.php
--index.html
And use the following contents for your .htaccess file:
FallbackResource /api/index.php
The main difference with the mod_rewrite based solutions is that there is no substitution in the URI, so you have to parse the URI in PHP using $_SERVER['REQUEST_URI'].
For example here, if you access http://example.com/api/logger/all, your index.php file will see the following value:
echo $_SERVER['REQUEST_URI']; // prints /api/logger/all
The main interest of putting the .htaccess file in the api directory is that it ensures that only URLs under the /api prefix are handled by FallbackResource. Any URL that would cause a 404 error in the document root folder will not trigger a call to /api/index.php.

Apache Alias / PHP / Laravel oddity

The problem description is very specific, but i have no idea about its source
The project uses Laravel 5.1
I have a project copy on my computer and remote server. Local server is configured to remove /public from URL with VirtualHost. On remote server, project is located in subdirectory. E.g. /project. To get rid of public, there is an alias in httpd.conf and line RewriteBase /project in /project/public/.htaccess
The problem appears when using Laravel's pagination mechanism:
There are links to pages in the page with navigation. On local machine everything is OK, but on remote server clicking on link with URL like http://<server_ip>/project/navigationPage?page=N causes redirect to http://<server_ip>/navigationPage?page=N. Of course, 404 error appears.
What is the problem and how to fix it?
Full .htaccess in /project/public:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /project
# 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]
</IfModule>
Ok, problem was in slash that was added to links by paginator. Link was looking like http:///project/navigationPage/?page=N, but must look like http:///project/navigationPage?page=N (without slash). Bug fixed by editing AbstractPaginator's url function:
public function url($page)
{
if ($page <= 0) {
$page = 1;
}
$parameters = [$this->pageName => $page];
if (count($this->query) > 0) {
$parameters = array_merge($this->query, $parameters);
}
return rtrim($this->path, '/').'?'
.urldecode(http_build_query($parameters, null, '&'))
.$this->buildFragment();
}

Laravel route directing to Home instead of throwing a NotFoundHttpException

I'm experiencing some unexpected behaviour in my laravel (4.2) routes.
Let's say my server is available at https://example.com. If I enter https://example.com/whatever/index.php I would expect laravel to throw a NotFoundHttpException, because a route to "whatever" is not defined. Instead laravel shows me the start page, indicating that my "home" route was catched.
If I solely enter https://example.com/whatever everything is fine (i.e. I get the NotFoundHttpException as expected). I neither have the problem on my localhost. Here https://localhost/laravel/whatever/index.php throws the NotFoundHttpException as expected.
My routes.php file:
// Home
Route::get('/', array( 'as' => 'home', function() {
return View::make('home');
}));
Maybe someone can give me a hint where to start searching what's causing that behaviour: Apache config, PHP config, Laravel config?
Ammendment as answer to S. Safdar:
At first I thought of a .htaccess redirect issue, too. In laravel's public folder (the web servers root dir) lays a .htaccess as follows:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
As you can see, the redirect here is handled correctly. The requested "whatever/index.php" is no real file therefore it is redirected to be handled by laravels index.php. If I remove the Rewrite Conditions (plus Rule) I get a regular apache 404 error page. In my case that's of no help as I want laravel to correctly(!) handle all error pages. But for some reason laravels home route matches every url ending on /index.php.
It seems this issue is present with both nginx and apache servers. A few steps I took to mitigate the issue with apache:
Change the index.php filename:
public/index.php to public/start.php
Change .htaccess to read:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ start.php [L]
Change the reference to index.php in the server.php file to have:
require_once $paths['public'].'/start.php';
why not you your route use this like?
// Home
Route::get('/', function() {
return View::make('home');
}));
i think problem is coming from as that you used in your route array.

Categories