Unable to see some pages after laravel deployed into shared hosting - laravel

Successfully deployed my laravel application in shared hosting.
Well some pages also I can see in server.
But unable to see some pages in server, but can see on local host.
I have tried many solutions available .. but could not able to fix it.
domain.com/admin/home can be viewed on server.
but domain.com/admin/postjob has 500 error on server, but working fine in local host.
Laravel folder is copied under root and the contents of laravel/public is copied to public_html/
Lets first check routes.
//Admins Index Page
Route::get('/admin/home', 'admin\AdmhomeController#index')->name('admin.home');
//Job Posting by Admin - View
Route::get('/admin/postjob', 'JobsController#pjbyadm')->name('admin.postjob');
Lets see Controller - JobsController
//Post Job by Admin
public function pjbyadm(Request $request){
$auth = Auth::guard('admin');
if ($auth->check()){
//return view('admin.CRjob_ajob'); tried this first
return \view('admin.CRjob_ajob');
}
else {
return redirect('/mikeadmin');
}
Folder structure for views
Resources --> admin --> CRjob_ajob
.htaccess file in public_html folder looks like following.
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php71” package as the default “PHP” programming language.
<IfModule mime_module>
AddType application/x-httpd-ea-php71 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
server php file has
//require_once __DIR__.'/public/index.php';
require_once __DIR__.'../public_html/index.php';
Using laravel 5.8 version.
Expected to see the page admin/postjob, which is working fine in local host.

Try to run php artisan cache:clear before uploading to server then re upload or another solution is add this to your route
Route::get('/clear-cache', function() {
Artisan::call('cache:clear');
return "Cache cleared";
});
then call domain.com/clear-cache

Related

How to make the Laravel app to be served in Apache?

I have this laravel application deployed on server with apache. Initially the app was released for nginx, so no .htaccess was provided to the app.
I got accross some issues:
in the root of the subdomain there is a file server.php that contains:
<?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';
When I am calling that file in browser https://portal.eofs.dev/server.php I can see the content of the app yet without any style, and there are plenty of errors in console.
Any of the solutions tried do not load the app as it should.
I have also tried to move the subdomain index to public/ and following .htaccess rules:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.php [L,QSA]
and
`RewriteEngine On
RewriteBase /
RewriteRule ^$ public/index.php [L]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]`
Any of the solutions tried do not load the app as it should.

Laravel root directory not public on Hostinger hosting

I currently host my Laravel website on Hostinger, but when I have a image on my page, the url doesn't go to website.com/public/img_url, but it goes to website.com/img_url, does anyone know how this works on Hostinger, and how I can fix this?
Currently my whole project is in my public_html, with no other folders besides it.
The right solution was changing my htaccess to:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
You should need to add a public inside asset function to access a public folder on the shared hosting server.
So you need to change the fetch path of files Example: asset('user/photo.jpg') to asset('public/user/photo.jpg') in each line of code where you need to fetch files from the public directory.

How to hide public from url in laravel 9

I used Laravel 9 and Inertia.js + Vuejs and the project has been deployed to the cpanel. When I access to the site and it threw an error saying Not Found with code 404 so then I added a new file - .htaccess outside the public folder and the error existed. I tried to access to public folder like this https://imapp.asomaningministries.com/public and it worked but I don't want anyone to eventually access to this folder. So can I hide it?
You can try to set the document root directory as 'public' directory on the domain settings page of cPanel.
or you can use .htaccess file like that;
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain-name.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain-name.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]

Routing fail on Laravel app deployed on subfolder

Ok, this is what is happening.
I've created a small laravel app (actually, still it's on the development stage).
When I upload it to the server (shared hosting managed through cPanel) I've deployed it to a subfolder inside the main website.
There is the main website (a WordPress) on the server's public_html folder, so I created a subfolder where I put my app.
Now, when you request http://oursite.com you reach the Wordpress site.
And when you request http://oursite.com/laravelapp you reach the initial page of the laravel app.
However, when I try to browse any page into the app, the routing returns me to routes inside the root web folder.
For example, if I push the login button, the petition to http://oursite.com/laravelapp/login redirects to http://oursite.com/login, and obviously, the page load fails
The funny thing is that if I reach directly public pages, it seems to work fine.
If I directly request http://oursite.com/laravelapp/public/index.php and push the same login button, a request to http://oursite.com/laravelapp/public/index.php/login is made, and it works!! Even JS and CSS links are correctly detected on that request!!
I suspect this is probably something quite stupid that I cannot see now because I'm too tired, but I will really appreciate any insight on the matter.
The index.php on my laravelapp folder is the following:
<?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';
And this is the code of the .htaccess file inside /laravelapp/public 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]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Maybe I would be able to fix this using a subdomain like myLaravelApp.oursite.com?
Ok.
I fixed this problem copying the .htaccess on laravelApp/public to laravelApp.
It seemed that the root folder needed some type of redirection, and this worked like a charm.

Codeigniter 404 not found error when accessing anything inside application folder

I am having a problem after hosting my codeIgniter project on live shared hosting server.
Before doing that, I changed few things on my local server.
.htaccess file-
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
.config.php inside config folder-
$config['base_url'] = '';
$config['index_page'] = '';
to let it work properly on my local server without writing index.php in URL. But when I moved it to live server, I changed base_url as-
http://crm.sachinartani.com
as I am hosting it on my subdomain, but it always output-
404 Page Not Found
The page you requested was not found.
I watched all videos on YouTube and traversed all questions of StackOverflow but none of the solutions helped me. There is a folder aside application folder namely inc which contains CSS and JS files I am using in my project. I am able to access those files by URL as - http://crm.sachinartani.com/inc but I cannot access any controllers and views like this.

Resources