danielec81's avatar

Hosting on Shared Server Best Practice

Hi, I would like a couple of advices about hosting Laravel on a Shared Server.

I've seen there are some methods, but I would like to better understand which could be preferred.

The method I've found are:

  1. Using .htaccess to change the Document Root through RewriteRule (es https://stackoverflow.com/a/25119567 )
  2. Clone the Repo in a not public folder, copy /public/ content in the public_www folder (or the name on the shared server) anche fix the path in index.php of the two "require" commands.
  3. If the Shared Host use Symbolic link for public directory (es cPanel create a directory named public_www, anche a symbolic link www => public_www ) use SSH to login the server, change the link to the public folder of the laravel application.

I think that there are pros and cons on every point, but I would like some skilled opinions!!

0 likes
19 replies
rsvb's avatar

The easiest way for me is 1:1 webserver : localserver.

extjac's avatar

i host in AWS and 1And1 share hosting...all works out of the box. what issues are you having?

bashy's avatar

Obviously the best solution is number 3. There's no real way that can ever expose your code, unless something seriously changes with the setup (point it to the wrong folder).

If your shared host supports/allows symlinks, great!

bashy's avatar

@jlrdw Yup, it's a shame and I'm not sure what this topic is actually asking really. Pros and cons? So many opinions and endless chat about security :P

rsvb's avatar

Why should the webhost setup be different from the local setup? They should be the same in my opinion. Then this question would be history lol.

rsvb's avatar

Now another thing, in case you do not have local, is the default install 100% right on a webhost?

jlrdw's avatar

@rsvp Please see this image https://imgur.com/Oo6k4Fp

I setup local dev and production just like the image, and follow

http://novate.co.uk/deploy-laravel-5-on-shared-hosting-from-heart-internet/

I recently did a 5.5 on shared host. I have never had any problems. Some seem to have session problems, or image trouble, or various other issues.

I followed the guide that @Snapey provied and somehow never had any of the problems mentioned.

If you don't believe me fine, but the guide really works 100%.

It is for shared host, their may be other ways to accomplish on a dedicated server.

Cronix's avatar

In this day and age of cheap cloud hosting (you can get them for $5/mo), I really don't see why people still bother with shared hosting. It's so much easier to have 100% control of your server and no "shared hosting" problems.

jlrdw's avatar

@Cronix is there a decent guide for cloud based hosting? One where you directly place the files on the host, with no Forge. I.e., can you still FTP your site, etc.

And wouldn't you still have main Laravel placed in a higher folder than the one serving web files.

It would be neat to have two guides to post for folks, and let them go from there.

Cronix's avatar

@jlrdw There are tons of guides. Sure you could use ftp, but why? Use scp as it's secure and you don't have to leave port 21 open, which is widely abused and scripts hunt for since it's a common port. Or use ssh with keys and git hooks for automatic deployment

Google "laravel digitalocean" and you will find tons of guides, by digital ocean themselves. Or google "laravel aws", etc.

https://www.digitalocean.com/community/tutorials/automatically-deploy-laravel-applications-deployer-ubuntu

https://www.digitalocean.com/community/tutorials/how-to-install-laravel-with-an-nginx-web-server-on-ubuntu-14-04

And wouldn't you still have main Laravel placed in a higher folder than the one serving web files.

Totally. You'd just set laravels "public" dir to be the site root. Another benefit to having your own server. You can edit the apache/nginx configs directly.

jlrdw's avatar

Thanks @Cronix this post will become a good source for someone wanting to deploy and Like Jeffrey said, we were all new to this stuff at one time. So I try to have good links to help new folks when I can.

It's discussions like this that can really help people.

jlrdw's avatar

Larger app I'd say apache, but most things done in laravel either would be fine.

1 like
bashy's avatar

Yeah Apache is horrid. Can't use it now

doni49's avatar

@Cronix ,

You commented about how easily/cheaply a VPS can be obtained.

The only reason I'm reluctant to go that route is the fact that maintaining the security of the server will be on me exclusively.

I work 70 hrs a week outside of anything I do related to any type of development so I really wouldn't have time to deal with such issues.

Were it not for this, I'd go with VPS in a heartbeat.

bashy's avatar

@doni49 Linux is very secure by default. Obviously the more packages you install, the more security risk there is but all you have to do is install/change a few things to make it secure then it's just a matter of sudo apt upgrade for updates.

Please or to participate in this conversation.