Laravel Project - After upload hosting server faced the issue for 500 Server Error and website menu link issue - laravel-8

I have faced the issue for website not working properly.[Project file uploaded in sub folder].
Folder Path : example.com->public_html->lrvproject
Please note the below issues:
Home Page - 500 Server Error. https://www.example.com/lrvproject/
Sub Pages open - I have manually enter page path it's showing page.
Example: https://www.example.com/lrvproject/contact
After loading subpages Menu link URL showing is "https://www.example.com/contact".
I have refer the tutorial inside public(folder copy all file and paste outside public folder).
index.php [https://www.example.com/lrvproject/index.php]
if (file_exists(__DIR__.'/../storage/framework/maintenance.php')) {
require __DIR__.'/../storage/framework/maintenance.php';
}
require __DIR__.'/../lrvproject/vendor/autoload.php';
$app = require_once __DIR__.'/../lrvproject/bootstrap/app.php';
$kernel = $app->make(Kernel::class);
$response = tap($kernel->handle(
$request = Request::capture()
))->send();
$kernel->terminate($request, $response);
web.php (routes)
use Illuminate\Support\Facades\Route;
//use App\Http\Controllers\UserAuthController;
Route::get('/','HomeController#index');
Route::get('/about', function () {
return view('pages/about');
});
Route::get('/gallery','ImageGalleryController#index');
Route::get('/contact','ContactController#index');
Route::post('/contact','ContactController#sendmail');
server.php [https://www.example.com/lrvproject/server.php]
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}
require_once __DIR__.'/public/index.php';
//require_once __DIR__.'/index.php';
.htaccess [https://www.example.com/lrvproject/.htaccess]
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
# Disable Directory listing
Options -Indexes
# block files which needs to be hidden, specify .example extension of the file
<Files ~ "\.(env|json|config.js|md|gitignore|gitattributes|lock)$">
Order allow,deny
Deny from all
</Files>
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>
Already Server Folder Permission enabled. PHP extensions enabled.
How to solve the issue. please help.

I have solved the issue. I have updated the below steps.
.env file database details updated, now my home page worked.
index.php [https://www.example.com/lrvproject/index.php] -Edit
require DIR.'/vendor/autoload.php';
$app = require_once DIR.'/bootstrap/app.php';
Web menu links URL-Edit
href="/lrvproject/contact" link path update "Contact US"
Clear Cache in Server
My Laravel Application Running in Server (Sub-folder directory)

Related

Laravel Project Not Running On Server

I have deployed my laravel project on server. When I hit the url it gives me error but no log is generated in log folder.
This page isn’t working
[Domain Name] is currently unable to handle this request.
HTTP ERROR 500
I have moved the public folder contents to root directory and edited the index.php.
I checked the permission for storage, vendor and bootstrap folder and they have required permission.
index.php
<?php
define('LARAVEL_START', microtime(true));
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/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);
Server.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';
.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>
The project is hosted on shared hosting and I've used filezilla to upload it on server. What else I need to do to make it work. This is my first uploading the project on the server.

yii2 rest api url rewriting (hide directories)

I would like to use clean urls on my yii2 rest api.
I'm having clean urls for my frontend application but I'm failing to create clean urls for my yii2 rest api application.
I created the rest api by following the tutorial (Yii2: RESTful api: tutorial). The rest api uses a module for versioning.
Two .htaccess files have been created.
One file in my root and an another one in my "api/web" directory.
root .htaccess file
RewriteEngine on
# prevent directory listings
Options -Indexes
IndexIgnore */*
# follow symbolic links
Options FollowSymlinks
RewriteCond %{HTTP_HOST} ^api.localhost [NC]
RewriteRule ^(.*)$ api/web/$1 [L,PT]
'api/web' .htaccess file
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule ^(.*)\?*$ index.php?r=$1 [L,QSA]
Browsing to 'http://api.localhost.com/v1/music' gives a 404 page not found error.
While 'http://api.localhost.com/api/web/v1/music' returns results
(I would like to hide 'api/web/' in my url)
'request' => [
'baseUrl' => str_replace('/api/web', '', (new \yii\web\Request())->getBaseUrl()),
],
Add this request component config in your main api config
Configure the host file to look in /project_folder/api/web

Allow php files to be accessed in laravel public folder

I have a Laravel project that using Roxy Fileman as file manager. I put the files of Roxy Fileman under the public folder
/public/fileman
so I can access it by
<ifarame src="my.domain/fileman/index.html"></iframe>
the iframe will load data from PHP files in the plugin folder which located at
/public/fileman/php
It works well on my local XAMPP server but says E_LoadingAjax php/dirtree.php on my linux server, and returns 404 when I try directly access these files
I assume it is because PHP files are blocked from direct access for security reasons.
Then how can I allow this specific folder to be accessed? or what is a better approach to use Roxy Fileman in laravel?
.htaccess comes with Laravel:
<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]
</IfModule>
Open up composer.json and find section with autoload, and add files array, see example below (I created folder folder inside public folder which contains file tst.php) so I have public/folder/tst.php
Now when I visit 1.1.1.1/folder/tst.php PHP interprets me the code.
.
.
.
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
},
"files": [
"public/folder/"
]
},
.
.
.

Htaccess mod rewrite don't work

I have a project with two applications: a frontend (in AngularJs) and a backend (in Phalcon). I my server document root i have two folders and one htaccess:
public_html
- api
- controllers
- index.php
- app
- .htaccess
The .htaccess have the next configuration:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^api/(.*)$ api/index.php?_url=/$1 [QSA,L]
</IfModule>
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
So, when i send a POST request (for example) to http://mydomain/api/sessions, the result is 404 not found. The router configuration is:
$router->addPost('/sessions', array(
'controller' => 'sessions',
'action' => 'post'
));
In my localhost works fine with this configuration. But, in my VPS not.
Any ideas ?
Update 1:
If i don't use any REST service, accessing via http://mydomain/api the Phalcon index controller is loaded.
Update 2:
If i try to access a REST service using a Phalcon url like http://mydomain/api/index.php?_url=/licenses works fine.
i found the problem. the virtual host configuration file had not the next lines:
<Directory "/var/www/domain/public_html">
Options All
AllowOverride All
Allow from all
</Directory>
You can sometimes get away with relative path substitutions in the document root, however, you should make the RewriteRule substitution root-relative (starts with a slash), or specify a RewriteBase / directive after you enable the rewrite engine in order to explicitly specify the URL prefix.
RewriteRule ^api/(.*)$ api/index.php?_url=/$1 [QSA,L]
Becomes:
RewriteRule ^api/(.*)$ /api/index.php?_url=/$1 [QSA,L]

Laravel: 404 Not Found or 403 Forbidden

I tried for the first time the Laravel Framework on my VPS.
In a folder where I have a other project folder (without any access problem) I create a project with "laravel new Test"
I changed the permission on "storage" and "bootstrap/cache".
Now I go to the page and...
"/Test/" => returns 403 Forbid
"/Test/index.php" => returns 404 Not Found
The mod_rewrite is enabled.
I set "AllowOverdrive All" to the main folder.
the .htaccess in the Test/public is the default one and i tried to change it to:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Restart httpd. restart all the vps... nothing changed...
What I miss?
The default documentRoot for access the content is in the folder /public
So you can access with www.example.com/public/
You should change the default root for example.com to the public folder.