Ramesh Thapa

Sharing my personal opinion and notes

Moving Laravel website from Localhost to live server

Moving Laravel website from Localhost to live server

After building laravel apps or website in local server(localhost/xampp), in the time of server migration there is alot of things you must know. Some time even you run your laravel apps in local server that is perfectly fine but you moved your all coding in live server haveing cPanel you have a problem to server configure it. Some time you don’t know what happen to my server, how can I configure this correctly?. So this article I am going to share something that might help when you are in trouble.

In this article, I am going to solve problem when you migrate local server to live server with cPanel( having public_html).In laravel, default public folder is used for storage and other asset, so we can configure this in public_html folder.

Problem: When you just upload all your code and folder outside public_html folder, and check server then surely you will find there is

This page isn’t working www.sososystem.com is currently unable to handle this request.
step 1:check .htaccess file in public_html
This is hidden file, so you must enable to show all hidden file. If laravel .htaccess file is outside public_html folder then move inside public_html. If you don’t, then create yourself and put belows code there.

<IfModule autoindex>
IndexIgnore *

<IfModule mod_rewrite.c>
# Prevent Directory Listing
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes

RewriteEngine On

# Prevent Direct Access to Protected Files
<FilesMatch “(?i)(^artisan$|\.env|\.log)”>
Order deny,allow
Deny from all

# Prevent Direct Access To Protected Folders
RewriteRule ^(app|bootstrap|config|database|resources|routes|storage|tests)/(.*) / [L,R=301]

# Prevent Direct Access To modules/vendor Folders Except Assets
RewriteRule ^(modules|vendor)/(.*)\.((?!ico|gif|jpg|jpeg|png|js|css|less|sass|font|woff|woff2|eot|ttf|svg).)*$ / [L,R=301]

# 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}]


step 2:check you index.php file.
If you run after step 1, what do you see, your site may have problem. one is you do not have index.php in public_folder, this you will give file not found error. By default in laravel, index.php is on public folder move all this folder in public_html.

step 3: if you have still have problem of server then do this.
if you have still This page isn’t working www.sososystem.com is currently unable to handle this request.
then go to index.php and change this like this.
// Register the auto-loader
require __DIR__.’/../vendor/autoload.php’;
// Load the app
$app = require_once(__DIR__.’/bootstrap/app.php’);
$app = require_once __DIR__.’/../bootstrap/app.php’;

then check your url, this will works.

Leave comment

Your email address will not be published. Required fields are marked with *.