mbo's avatar
Level 3

Laravel on shared hosting

hello,

I like to put my laravel installation on a shared hosting.

I found two ways of installing:

Method 1

Method 2

I wondering what method is better? Is there a security issue with method 2? By installing the total installation in a public folder?

thanks for the reply

0 likes
5 replies
Sinnbeck's avatar

Yes exposing your whole app via method 2 can be a huge security risk. You risk people getting access to your env file, or your cached config (with has passwords in plain text)

Always go with method 1 if possible. Or better yet, upgrade to a real server (they don't cost much)

mbo's avatar
Level 3

Sinnbeck,

thanks for the reply. The issues is that i don't have any knowledge of server management. I know there are setups for deploying etc. But what about backups of your files and database.

Any tips on that?

mlhaus's avatar

I am using shared SiteGround hosting to deploy a Laravel project. I started by creating a blank website with a temporary domain. I followed the directions in the link you shared for Method 2. On SiteGround's Site Tools, I enabled SSL and created an FTP account.

Locally, I used Laravel Herd to create a new site. Using FTP, I copied files to SiteGround and updated the .env file. In the public_html folder, I created a .htaccess file and added the following.

AddHandler application/x-httpd-php84 .php .php5 .php4 .php3
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.sg-host.com$ [NC,OR]
RewriteCond %{REQUEST_URI} !mysite/public/
RewriteRule (.*) /mysite/public/$1 [L]

I am able to access my site by visiting https://mysite.sg-host.com/. All contents of the root directory, including the .env file, are not publicly accessible.

Please or to participate in this conversation.