laravel app generating an internal server error on shared hosting - php

I'm trying to deploy a laravel app on shared hosting. Here is what I did.
I zipped the entire laravel-app directory on my local machine.
I uploaded it and then unzipped the app in the public_html folder on the server.
I changed the file permissions of the public_html/larvel-app and public_html/laravel-app/storage and public_html/laravel-app/public to 777.
I removed the line 'public' in the .gitignore file.
I then copied the index.php and .htaccess file from laravel-app/public to the homepage and pointed to the necessary autoload folders (the ones about require and the $app variable to laravel-app/public).
Problems: If I navigate to my-website homepage, all the HTML for the homepage is being pulled in but no CSS or JavaScript or images. If I navigate to my-website/laravel-app/public, I see an internal server error message (error 500). However I have been able to view the files of other folders in the laravel-app subdirectory.
I include a copy of my .htaccess file code here.
<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>

Related

Laravel 8 Cpanel Deploy - 404 Errors

I am trying to deploy my Laravel 8 app to a folder in CPANEL (first time I've deployed Laravel). I have searched the forum and made changes as the many posts direct. I am getting 404 errors across all pages apart from the homepage and login and register pages. This is a common error but I cant find a solution. Dont shoot me.
1.All files uploaded to url/laravel/blog
Public folder moved outside and renamed public_html
The /laravel folder now has two directories /blog and /public_html
index.php in the public_html folder updated:
require DIR.'/../blog/vendor/autoload.php';
$app = require_once DIR.'/../blog/bootstrap/app.php';
New .htaccess file added to the root of the public_html and set to chmod 755 (detailed below)
Renamed the cache folder in the /bootstrap folder so that new cache is created (I hope)
Database is linked within the .env file
I am out of ideas, I have created a test html file in the public folder and I can see this in the browser when I navigate to it. I am learning and any help will be appreciated.
<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>
I needed to point the subdomain/add-on domain to the public folder. No need to move anything or change Htaccess etc.... Credit to https://stackoverflow.com/users/2325620/james-clark-developer
Try this in your .htaccess
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^$ public/index.php [L]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
</IfModule>

Files in Public folder don't show up [Laravel]

I have a website in production that cannot access some folders in public/css. I checked permissions on all folders, checked my .htaccess in public folder, I cannot find the reason why some folders show up in my local version Local, but not in my production version Prod.
For example for this :
<link rel="stylesheet" href="{{ asset('css/directives/gallery.css') }}"/>
In my local version, it works because the folder directives shows up, but in production I get a 404 error.
Failed to load resource: the server responded with a status of 404 (Not Found)
This is how it looks on my production server Production Files, and inside directives
Website is written in PHP using Laravel 5.4, below is my .htaccess file in production, it is the same as in my local version.
Thanks
<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>
Give all permissions to the public folder
chmod -R 777 public
Is the owner and the group of 'directives' directory the same as in other directories ?

Laravel Showing Index Of / after uploading the site but works fine on localhost

I am trying to upload a basic site made under Laravel FW. I uploaded the site outside the public_html folder in a folder called laraveltest. I moved the public folder from here to the public_html folder. In this folder I have the index.php file and I changed two lines to :-
inside (public_html/public/index.php)
require __DIR__.'/../laraveltest/vendor/autoload.php';
$app = require_once __DIR__.'/../laraveltest/bootstrap/app.php';
I also changed my .env files that located outside public_html folder, and there a is a folder in the root called laraveltest. I changed the username/ database name and also the password.
When i load the site now, i used to get the page says Index Of / .
After doing some research and youTube videos, I then added a .htaccess file inside the (public_html) 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]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ public/index.php [L]
</IfModule>
Now when I reload the page, I get an error
This page isn’t working mylivewebsite.com is currently unable to handle
this request. HTTP ERROR 500
I have also checked the permission and it is all set to 0777 as well.
Please let me know how can I make my website run correctly.

Deploying laravel 5.4 project in shared host

I‘m facing some problems with my Laravel 5.4 project. I’ve created my project on localhost everything is working, no problems. Now I need this project to work on shared host. So, I rent a server, create database, create a folder in the same level as public_html, upload all files and folders (except public folder and its content) in this folder. Public folder content I put in public_html folder. I also make changes in my index.php file in public folder and changed two lines:
require __DIR__.'/../my_folder/bootstrap/autoload.php';
$app = require_once __DIR__.'/../my_folder/bootstrap/app.php';
In .env file besides database connection lines, I’ve also changed line DB_HOST=127.0.0.1 to DB_HOST=localhost
When I try to run my project on shared host, the starting page works perfect, but when I try to navigate to other pages, I‘m getting error connecting with routes (NotFoundHttpException in RouteCollection.php)
My .httacces file content is:
<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>
Maybe I need some changes here? I really appreciate any help.

An issue while hosting laravel project in server(local and live)

I want to host a laravel project in a dedicated server(aws, ubuntu 14.04).
So I placed the project in /var/www/html. When I go to 11.111.11.111/projectFolder/public the default welcome page is showing up,
but when I move to 11.111.11.111/projectFolder/public/login, I get an error - Page not found, interestingly 11.111.11.111/projectFolder/public/index.php/login, the login page is showing up but styles and jss files are missing.
Failed to load resource: the server responded with a status of 404 (Not Found)
http://11.111.11.111/js/app.js Failed to load resource: the server responded with a status of 404 (Not Found)
All these css and js files are present in public folder of laravel app.
These work perfectly when I run project using php artisan serve
The .htaccess file is as 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}]
I just want to change the .htaccess file, so when I type 11.111.11.111shows the application as when run normally.
If you want to see your project directly with http://11.111.11.111, you must change the DocumentRoot setting in your httpd.conf file.
In your /etc/apache2/sites-available/000-default.conf file, change the directory root to:
DocumentRoot /var/www/html/projectFolder/public

Categories