DEV Community

Deploying Laravel 5 applications on shared hosting without the use of SSH

Abednego Edet on March 03, 2018

First, it is well discouraged to use a shared hosting for your Laravel 5 app. There are other very cheap web hosting starting from USD $7 per month...
Collapse
 
bocanhcam profile image
bocanhcam

It's ok on my local. but when i upload it on my hosting, I have this error.

Forbidden
You don't have permission to access /index.php on this server.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

Can you please tell me how to fix it. thank you.

Collapse
 
rolmax1 profile image
Romax

I had this error. Firstly, there could be a file on the host that is already rerouting you via the .htaccess. After sorting this, then my host required a php.ini in the root directory and this needed to be a "production one" as opposed to a local one. Then bootstrap/cache/config.php had hard-coded references to my local PC, but not compatible with the hosting platform. With that the 500 Internal Service error was gone.

Collapse
 
edetscript profile image
Abednego Edet

Change the file access permissions for public folder, the permission error will disappear, everything should work normally now, unless you missed a step :)

Collapse
 
faryar76 profile image
faryar

also you can use this --> github.com/faryar76/lrm

package to run migrations and upload files without ssh

Collapse
 
_shahroznawaz profile image
Shahroz Nawaz

I never recommend shared hosting for Laravel applications. There are so many problems with it. Instead you can use DigitalOcean, Linode or Vultr. Amazon web services is a good choice. You can also checkout Cloudways for one click deployment of Laravel Applications:

cloudways.com/blog/install-laravel...

Collapse
 
eflames profile image
eflames

Hi,

How about having more than 1 laravel app in the same shared hosting?

I'm trying to upload a second app using a subdomain for example:

test.mydomain.com points to public_html/test

But does not works for me... but if I upload a HTML file with dummy text and I type mydomain.com/test it's ok!

How can I have more than 1 laravel app (different files, different public folder, different everything) in the same shared hosting (CPANEL)

Thanks u and sorry for my poor english.

Collapse
 
marvelxy profile image
Marvelous Akpotu • Edited

You can do this with a subdomain or addon domain. When you have your subdomain or addon domain ready, follow the author's step. The only difference is that you do everything in the directory created by your subdomain or addon domain.

Don't forget to edit these two lines of codes to match your directory structure:

require DIR.'/../vendor/autoload.php';
$app = require_once DIR.'/../bootstrap/app.php';

I strongly recommend setting this up on a local server like xampp before uploading it to your server.

Collapse
 
mahmudulhassan5809 profile image
Mahmudul Hassan

Hello did you solve it if any one have more than one app

Collapse
 
eflames profile image
eflames

Nope, I didn't. :(

Collapse
 
arif98741_47 profile image
Ariful Islam • Edited

Great man. I finally uploaded using this way. Everything was ok. But server gives me error 500. I didn't find out. So I go to config/app.php and made debug true to find out error and set up app-key by hard coding. Then running ok

Collapse
 
edetscript profile image
Abednego Edet

Great!

Collapse
 
vicoerv profile image
Vico

I have error Class 'PDO' not found, is that exception related to this tutorial?

Collapse
 
edetscript profile image
Abednego Edet

Nah, I think this is as a result of bad PDO installation or php.ini config file, try to install or reinstall PDO extension then restart server.
The error actually means PDO class does not exist,

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
rownak1812 profile image
Rownak Afrin

Illuminate \ Database \ QueryException (1045)
SQLSTATE[HY000] [1045] Access denied for user 'rozeline_row'@'localhost' (using password: YES) (SQL: select * from users where nid = 55555555 limit 1)
... I have got stuck here. rozeline_row is granted with all the privileges. what to do now?

Collapse
 
edetscript profile image
Abednego Edet

The error is self explanatory, it means you’re using a wrong password for the specified database user, make sure the password matches the database configuration in your .env file

Collapse
 
riyadhahmed profile image
Riyadh Ahmed • Edited

Hello,
I have developed a laravel project first time. It works fine in local.

I have VPS-1000 hosting from inmotion inmotionhosting.com/managed-vps-ho...

Which method i should follow. is it a shared hosting?

So far i tried your mentioned technique

create a folder in root folder laravel and upload all my projects files into it
then move public folder to public_html/subdomain folder

change the autoload and bootstrap path in index file (followed this 4. change the following lines (22 and 36))

update my env and config/database file with my database credential

it given an error : SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema =

used localhost instead 127.0.0.1 and also tried to change port 3306 to 33060 but failed

also i have tried.. upload full projects into public_html/subdomain folder and use htaccess to locate public index file. But same error.

Can you please tell me how to fix it. thank you.

Collapse
 
nepktoab profile image
Aneel

It seems to be working fine but one problem is that while I am trying to delete some resource lets say Post. I have used:

if($editor->image != null) {
unlink(public_path().'/uploads/editor/'.$editor->image);
}

I am unable to go to that path where the image is located. How to reach that path so that I can unlink it.

Collapse
 
silverman42 profile image
Sylvester Nkeze

After using your method to deploy my laravel app, all the pages loaded clean and easy. Big thanks for that bro. Although i have an issue with files i store in the storage/app/public directory. Uploading images to that directory is always successful but it seems impossible for me to view images from that directory to the blade view

Storage::disk('local')->url('file.jpg') seems to work on my local server but does not work on the remote server.

I did not use asset('storage/file.jpg') because I am not permitted to create a symlink on the host with ssh or php artisan

Collapse
 
edetscript profile image
Abednego Edet • Edited

Let us take a look at the default Laravel 5 application structure:

app //directory
contains restricted server-side application data

app/storage //directory
contains a writeable directory used by Laravel 5 and custom functions to store data ( i.e. log files, etc... )

public //diectory
this directory is accessible to anyone on the web.

If I were you, I would upload the file to the public directory directly.

Try this:

  1. Store image here: public_path() . 'img/filename.jpg'
  2. Save the 'img/filename.jpg' in database
  3. Generate the image URL with url('img/filename.jpg') Output // http://www.your-domain.com/img/filename.jpg
Collapse
 
mpchirania profile image
MP Chirania

how to generate key ,

as per instructions this command is needed Run this command for key generation
php artisan key:generate
Migration and seeding
php artisan migrate --seed
Installing dependencies
composer install
Folder Permissions
sudo chmod -R 777 storage bootstrap/cache

Collapse
 
saddamhussainn profile image
saddamhussainn

Hello dear i appreciate the team effort here and i found this community very helpful,
i have an issue and i hope i will get it here very soon
i upload the vpn app laravel project to a subdomain directory and make the database and assign the user to database but when i am run the domain than the error i got is

You don't have permission to access this resource.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

please help me

Collapse
 
himwkd profile image
himwkd

HI,
Thank you for the tutorial. But as I did the same that you have mentioned, all my css, js, images are not getting displayed on the browser. What should I do, as I have checked my path also. Please help.

Collapse
 
hemilndr profile image
hemilndr

SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (SQL: select * from sessions where id = eRLLuTsdfGhYugsApdfgsdfgujtikyuh2ygfiAZ9ePXig limit 1)

Collapse
 
jef311211998 profile image
jef311211998

i am trying to deploy a laravel application on hostinger.in. everything is working fine except one thing.the image uploaded by the user is stored on my files but cannot be viewed.i have stored all the files in the public folder into public_html folder and rest of the files are on the root directory i tried symlink yet it was of no use,please help

Collapse
 
iqbaltld profile image
iqbaltld

Hi, Thanks for saving my day...!
I have an ultimate (goDaddy) plan where i host multiple web apps. That is add on domains are added and those directories are inside public_html. What will I do in this case? Where i need to put project folder and contents in public directory?

Collapse
 
saddamhussainn profile image
saddamhussainn

i didn't use to check it on my local server like using apache and my sql i straight forward upload the laraval app to my subdomain directory
i upload the vpn app laravel project to a subdomain directory and make the database and assign the user to database but when i am run the domain than the error i got is

You don't have permission to access this resource.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

please help me

Collapse
 
hafizmdm profile image
Info Comment hidden by post author - thread only accessible via permalink
hafizMDM • Edited

This is very hard for continuous integration and continuous deployment. The right way to deploy should be according to this article 👇

medium.com/@hafizmohammedg/how-to-...

Collapse
 
pukhtoonyar profile image
Irfan

I am deploying on a sub domain using laravel 5.7, but I am unable to locate the index.php file in root directory of subdomain.

Collapse
 
pukhtoonyar profile image
Irfan

Ok, the index.php is located in public directory, but the listed changes is not making the app running.

Collapse
 
mikennani profile image
Micheal Uchenna Nnani

Thanks a lot. I was having a problem deploying a laravel project of mine. But now it's fixed.

Collapse
 
edetscript profile image
Abednego Edet • Edited

You are welcome, am glad to hear that,
Cheers :)

Collapse
 
ijsucceed profile image
Jeremy Ikwuje

This really help me on a no-framework php I created.

Collapse
 
edetscript profile image
Abednego Edet

Glad this is working for us 😊

Collapse
 
ssmusoke profile image
Stephen Senkomago Musoke

Totally works like a charm ... Thanks for sharing

Collapse
 
edetscript profile image
Abednego Edet • Edited

Am glad it also worked for you. Cheers :)

Collapse
 
awwal1999 profile image
AKANBI TUNDE LAWAL

Nice! This article really helped out, Thanks

Collapse
 
edetscript profile image
Abednego Edet • Edited

Cheers. Am glad it worked for you

Collapse
 
tottranrotate profile image
Trần văn tốt

Thank you!

Collapse
 
edetscript profile image
Abednego Edet

Anytime mate 🙋‍♂️

Collapse
 
gregorgonzalez profile image
Gregor Gonzalez

Thank you! I needed it to start a project. I explain to clients that a shared hosting has its limitations, it is good to start but I also make recommendations to improve over time.

Collapse
 
rajanish93 profile image
Rajanish kumar singh

when i'm public folder content move public_html but more than 2 project how to handle this

Collapse
 
osaigbovoemmanuel1 profile image
Osaigbovo Emmanuel

add

Order allow,deny
Deny from all

to the .htaccess file to prevent your .env file from being publicly accessible

Collapse
 
edetscript profile image
Abednego Edet

Awesome!

Collapse
 
vikctar profile image
vikctar

Life saver!! Thanks a lot, man.

Collapse
 
edetscript profile image
Abednego Edet • Edited

You're welcome

Collapse
 
abhishek6262 profile image
Abhishek Prakash

If we're making changes to the path of Laravel's public directory. Wouldn't it be wise to let Laravel know about it by binding the paths as discussed in the given below article?

shade.codes/how-to-deploy-laravel-...

Collapse
 
xpir3dbr4in profile image
xpir3dbr4in

The login is not valid, the contents are correct!
Anyone knows how to solve it????

Collapse
 
xpir3dbr4in profile image
xpir3dbr4in

No help from anyone!!!

Collapse
 
nenadsavkic profile image
Nenad Savkic

Do you have tutorial for deploying Laravel app on Digitalocean?

Collapse
 
adelinghanaem profile image
Adelin

First, it is well discouraged to use a shared hosting for your Laravel 5 app, Why ?

Collapse
 
officialnqt profile image
Nurudeen Qoyyum Timi

Nice piece of write up, but you didn't remember to mention setting up .env configuration variables.

Collapse
 
ssnatu profile image
ssnatu

I've Laravel 5.6 application and I was following your steps, but there is nothing showing when I open my application site in browser. It's blank. Can you please help me?

Collapse
 
edetscript profile image
Abednego Edet

Try to view source code in browser emulator

Collapse
 
rdmngithub profile image
rdmngithub

There is a small php script that can do the job for laravel 7. I already tried it and it saved me a lot of time. Here is the link: laravel-deployer.planethoster.world/

Collapse
 
russisunni profile image
Jonathan Dyason

thanks!

Collapse
 
edetscript profile image
Abednego Edet

Glad it worked for you.

Collapse
 
kimsean profile image
thedevkim

Hi. I tried this. but when i open the page, it is blank. I checked source, and It did not render my component

Collapse
 
udemethegrtman profile image
Udeme Samuel

Nice article, it worked for me in my laravel app 5.2 but the rest pages apart from the homepage is not working.

Some comments have been hidden by the post's author - find out more