Laravel giving 500 internal error on Shared hosting - php

I have an laravel app working fine on my local machine. I have just transferred it to my server (Shared hosting) and put everything on a public folder in public_html and everything else in one step above public_html. The problem is now it shows 500 internal error on every route. I have changed .htaccess code to given code on documentation, folder rights to storage and bootstrap are set to 777.
Nothing in error logs and also nothing in laravel log files. when I installed fresh laravel installation it worked on the server as well. Tried updated code with my project but still 500 internal error.

For Laravel 8 / IONOS Managed Server this works for me:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteBase /
Options +FollowSymLinks
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>

If you are using IONOS (or 1and1, maybe works fot other too...), the .htaccess file should be different from the default in laravel public directory.
Replace its content with this:
RewriteBase /
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

The error may be due to the configuration of .env file.As your question is not clear enough. so i wil explain 2 methods
With vendor and .env file (Not Recomended)
- Unzip the main zip file and upload your public_html folder ( upload
vendor folder as well)
Give 777 recursive permission to storage/ and bootstrap/ folder
Create database in phpmyadmin and import .sql file
Set Database in .env file
Now normally for all shared hostings you will have jailed SSH you can contact the hosting provider to get its details.
Once you get access , use command
php artisan cache:clear
php artisan config:clear
php artisan config:cache
The file itself can be found in bootstrap/cache/config.php.
Note that the location of the compiled config file has changed recently. Yours might also be in vendor/config.php or storage/framework/config.php. With a fresh install or if you run composer update the file should be in bootstrap/cache though.
Now Directly from GIT or other Sources without Vendor(Recommended)
Make sure you copy all of the project files including the hidden ones(.env).
if You are using GIT use GIT clone to clone the project.
Check you have all the necessary PHP extensions available in php.ini as in Laravel requirements. Also, watch your PHP version!
Install composer https://getcomposer.org/doc/00-intro.md
When copied, go to your destination folder and run composer install.
Run php artisan key:generate from the command line.
then Run
php artisan cache:clear
php artisan config:clear
php artisan config:cache
http://php.net/manual/en/install.windows.commandline.php
Make sure your webserver is serving pages from project/public folder.
Even after completing these steps if Laravel is still showing error, check
your_project/storage/logs/laravel.log

Laravel default .htacces won't work for IONOS.
This is the perfect .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteBase /
Options +FollowSymLinks
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

500 Server Error when trying to deploy locally on Xampp or Wamp for a repo on GitHub

Hi All I have been trying to deploy the following webapp I found on github.(https://github.com/lpkapil/storemanager.git)
it is written in php using Laravel framework. I followed all the instructions on the readMe however it gives me the following error:
Im not sure what to do from here, I would like to use this to create a personal project that is of interest to me.
here is my virtual host information:
<VirtualHost *:80>
ServerName storemanager2.com
DocumentRoot "C:/xampp/htdocs/storemanager/public/"
</VirtualHost>
Do you have a .htacces file setup? because I see you are running in a production environment.
If you are running in a production environment you'll need a .htaccess.
Try this;
Open phpmyadmin and create a database for your project.
Create a .env file and copy the contents from .env.example and paste into it.
In your .env file replace the following fields with your database credentials
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=yourdatabasename
DB_USERNAME=yourmysqlusername
DB_PASSWORD=yourmysqlpassword
In command line cd to your project directory and follow all installation instructions in repo.
in command line type PHP artisan serve.
if you are in a production environment as above create a .htaccess file and copy the code below to it.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization MemberHeader
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]
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Should work fine now.

links not working when deploying Laravel app to Heroku

I was given a laravel project I need to get up and running. I am new to laravel, but after allot of work, I believe I got everything configured properly and I deployed the project to heroku.
When I do artisan serve on my guest machine in my laravel project and go to the given url everything works fine all the links works.
But I deploy it to heroku and my index page shows but none of the links work.
I get:
Not Found The requested URL /register was not found on this server.
It seems that running php artisan serve kinda activates the links, but how do I make that happen on heroku???
I should note the app is using blade.php files
What am I missing???
This is in the /resources/views
My _htaccess inside my public folder is as follows
<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 tried adding RewriteBase / doesnt help.
I also tried changing htaccess to:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
And my Procfile has:
web: vendor/bin/heroku-php-apache2 public/
Thanks
Well I resolved my issue, it seems that I had some lowercase letters in my web.routes path
that should have been Capital letters. Local host dosen't seem to mind if the words are uppercase or not, but linux does seem to mind.... Not sure if it will help, but i searched a long ass time for something so silly...
I had to restart my dynos for it to work, run heroku restart
Also make sure to have a Procfile in your root with
web: vendor/bin/heroku-php-apache2 public/
I resolved with:
In config/app.php
I changed for:
'asset_url' => env('ASSET_URL', 'https://appcreated.herokuapp.com'),

Deployment of api created in lumen at aws server

I deploy the project in my regular routine but this time while deploying at aws facing some errors. I deployed there using the ssh command and a key pair at ubuntu 16.04. I installed lamp, PHP, and PHPMyAdmin there successfully.
This is the link and error I am facing http://52.60.197.219/api/category, it says error 404 not found
I tried almost all solutions available but no luck.
Suggestions will be highly appreciated.
my.htaccess file `
Options -MultiViews
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 ^ Api_load.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
`
my index.php file named as Api_load.php $app = require __DIR__.'/api/bootstrap/app.php';
$app->run();
structure of a deployed application
API(folder contains all files and codes)
.htaccess,
Api_load.php
yes , its a common error. its all because of conflicting .htaccess file.
Follow these steps.
1)Create Zip of your folder and unzip into the directory you are going to deploy your code.
2)Edit you .env file according to your requirements i.e changing Db username,password and database name.
3).htaccess file and index file in public folder, bring them to the outside of the root directory.
4)now access your baseUrl/endpoint name.
it will work.
Try to solve your problem by adding the config below to /etc/apache2/apache2.conf or site-avaliable/000-default.conf, then restart apache2.
<Directory /home/away/workspace/park/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

Can't deploy laravel 5.6.7 project to a subdomain on a web server

I keep getting 500 error when I try to access laravel application on subdomain of a web server.
I have uploaded entire laravel project into a public_html/laravel directory. Document root points to public_html/laravel/public.
I've added 755 permissions to bootstrap and storage directories.
Laravel version: 5.6.7, php version on my machine: 7.1.11. Web server php version 7.0
What can cause this problem?
Differences between php versions?
.htaccess file:
<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>
Edit:
Now I've changed document root to point to public_html/laravel and when I add /public i get 'no input specified' error and error log file looks like this:
Got error "Unable to open primary script: /home/user/public_html/laravel/public/index.php(no such file or directory)"
Final Edit: The problem was php version.
try
chown -R apache:apache /home/user/public_html/laravel/
It's your PHP version. Laravel 5.6 needs PHP >= 7.1.3.
First of all you should update the php version to PHP>=7.0 and secondly if there is a cache problem then you must run this command php artisan config:cache to clear the old configuration for local server. I faced this issue alot and i hope it will help you and others who would have same issue.

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.

Categories