Laravel 500 |server error on shared hosting - laravel

I'm trying to upload my Laravel project to my shared hosting cPanel its not my first time that I've uploaded the Laravel project but this time I think I'm out of luck I'm facing 500 server error.
here is the screenshot
I already try all the solution even I turn on debug too but nothing seems to work.
what I did is upload public files into my subdomain folder and rest into an other folder outside of subdomain folder I also try php_info(); and everything is enabled. could you please help me out.
Also nothing is in error log for this error.

The way i deploy on shared hosting. I do have the files in the public folder in the root directory. while in the index.php i point it to the laravel folder.
Here is how the directory will look like, take for example my laravel project is called willa:
willa
favicon.ico
.htaccess
index.php
My index.php look like this:
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* #package Laravel
* #author Taylor Otwell <taylor#laravel.com>
*/
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| I removed the comments.
|--------------------------------------------------------------------------
*/
require __DIR__.'/willa/vendor/autoload.php';
$app = require_once __DIR__.'/willa/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
My .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>

Related

Deploy Laravel project in server without changing the public folder path

I have found a solution for laravel Deployment
Most of us are stucked in the laravel deployment in server, most reason is changing the public path and modified the server.php
Please find the answer below:-
Just Change the .htaccess and the problem is solved:
Change Two files in root 1..htaccess, 2. .index.php
And Change Two files in public folder 1..htaccess, 2. .index.php
Root Folder
.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php
Root Folder
index.php
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* #package Laravel
* #author Taylor Otwell <taylor#laravel.com>
*/
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
/*if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}*/
require_once __DIR__.'/public/index.php';
Public 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]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Public Folder
index.php
<?php
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Check If The Application Is Under Maintenance
|--------------------------------------------------------------------------
|
| If the application is in maintenance / demo mode via the "down" command
| we will load this file so that any pre-rendered content can be shown
| instead of starting the framework, which could cause an exception.
|
*/
if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) {
require $maintenance;
}
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| this application. We just need to utilize it! We'll simply require it
| into the script here so we don't need to manually load our classes.
|
*/
require __DIR__.'/../vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/
$app = require_once __DIR__.'/../bootstrap/app.php';
$kernel = $app->make(Kernel::class);
$response = $kernel->handle(
$request = Request::capture()
)->send();
$kernel->terminate($request, $response);
Find the solution and cheers...
Happy Coding..

Laravel url method post not point to project folder?

why my laravel url not working when method is post
example the url api must be : http://localhost/PROJECTNAME/api/loginWeb
but when i click post button it always direct to http://localhost/api/loginWeb
but when method is get this okay. i use xampp
here is my 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>
When we're using session based laravel setup, all the route generator functions(url(), route()) use hostname http://localhost as root url, not http://localhost/PROJECTNAME. To resolve this issue please do following changes in laravel app.
Define APP_URL in .env file as APP_URL="http://localhost/PROJECTNAME"
Go to RouteServiceProvider which is located at app/Providers/RouteServiceProvider and force laravel to use APP_URL as root url for your app.
public function boot()
{
parent::boot();
// Add following lines to force laravel to use APP_URL as root url for the app.
$strBaseURL = $this->app['url'];
$strBaseURL->forceRootUrl(config('app.url'));
}
Same issue occurred to me when I used same domain and a suburl to identify different projects.
Linux: Nginx serves multiple apps with two different locations
Windows: Multiple Laravel Applications Using Nginx - Windows

All the APIs the laravel middleware is not working

I am using an auth middleware in laravel. If I am calling the routes which does not have middleware('auth:api') then it is working fine But routes under middleware('auth:api') not working.
I have tried to update htaccess file and tried approx all the solutions, but no results.
My Route code is -
Route::group(['middleware' => 'auth:api'], function(){
Route::post('unregistered', 'API\InterestController#getUnregistered');
Route::post('new-campaign-listing','API\CampaignController#new_campaign_list');
Route::post('registered-campaign-listing','API\CampaignController#registered_campaign_list');
Route::get('past-campaign-listing','API\CampaignController#past_campaign_list');
Route::get('getcampaignhistory','API\CampaignController#getCampaignhistory');
Route::post('register-for-campaign', 'API\CampaignController#register');
Route::post('top-campaign-photos', 'API\CampaignController#topPhotos');
Route::get('user-detail', 'API\PassportController#getdetails');
//update profile
Route::post('update-profile', 'API\PassportController#update_profile');
//update profile
Route::post('shared-post-data','API\CampaignController#shared_post_data');
Route::post('vip-campaigns','API\CampaignController#vip_campaigns');
Route::post('vip_client','API\CampaignController#vip_client');
Route::post('add_user_interests', 'API\InterestController#add_user_interests');
Route::get('user-interests', 'API\InterestController#user_interests');
Route::post('update-user-interests', 'API\InterestController#update_user_interest');
//polls
Route::post('polls-for-vote', 'API\PollController#pollsForVote');
Route::post('vote', 'API\PollController#vote');
Route::post('contact-us', 'API\PassportController#contactmail');
Route::get('campaignpostimage','API\PassportController#campaignpostimage');
Route::post('firebase-token', 'API\PassportController#get_token');
//notifications
Route::post('notifications', 'API\InterestController#notifcations');
Route::post('unread_notifications', 'API\InterestController#unreadNotifications');
Route::get('coupons','API\CampaignController#coupons_list');
Route::post('redeem','API\CampaignController#redeem_points');
Route::post('campaign-detail','API\CampaignController#campaign_detail');
Route::get('rewards_history','API\CampaignController#rewards_history');
});
My function in passportcontroller is :
public function getDetails()
{
dd("hello");
}
My htaccess file 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}]
# RewriteCond %{HTTP:Authorization} ^(.*)
# RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
# 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>
Even dd in controller is not printing. means API URL is not working
What is the error message?
Note:You should put the routes inside api.php
Please provide more info about how you are consuming your API?
if you are consuming the API's from different domain (Cross domain) than you will face the CORS issue, in that case you need to add the following package to your laravel application
and if you are on same domain tha you can follow the
documentation.
In my case this
git hub reported issue solved my problem

How to upload the laravel project on cpanel?

How to upload larval project on cpanel using only.Htaccess file. I saw already more of the example, but not worked properly. This is throwing the error is This page isn’t working. I put my project inside http://www.domainname.com/laravelproject. Inside this we change the index.php file in the public folder.
file is 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>
public/index.php
require __DIR__.'/../filename/vendor/autoload.php';
$app = require_once __DIR__.'/../filename/bootstrap/app.php';
from my experience so far, when you are done with coding your project
create a folder outside of public_html. you can call it maybe "project"
copy all your project files and upload to the project folder created.
open the public folder in your laravel project and copy all the files including the .htaccess and index.php files to the public_html folder.
then open index.php files and change the following pointing to the project folder you created.
define('LARAVEL_START', microtime(true));
require DIR.'/../project/vendor/autoload.php';
$app = require_once DIR.'/../project/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
in your case, http://www.domainname.com/laravelproject
1. create a folder name "project" outside of the public_html and place all the laravel files inside it.
2. also create a folder name laravelproject inside public_html/laravelproject.
3. then open the laravel public folder inside "project" folder and copy all the files to the public_html/laravelproject.
4. open index.php inside public_html/laravelproject and change the
require DIR.'/../../project/vendor/autoload.php';
$app = require_once DIR.'/../../project/bootstrap/app.php';
or
require DIR.'/../project/vendor/autoload.php';
$app = require_once DIR.'/../project/bootstrap/app.php';

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. :)

Resources