Move Laravel to Shared Hosting

2018-08-31 11:07:00 laravel-shared-hosting

I guess it is the last day of the month because I've never heard of a date 32nd.

My new Laravel site for is nearing completion. I am looking into porting the site to my server. It's a bit frustrating because the recommended method assumes you have a dedicated server for the domain, and so you cannot just drop the project folder on a server and expect it to work. HOWEVER. With a little configuration it becomes very flexible.


Move the public/ folder out and move the entire project to a safe folder behind public_html.
You might need to chown -R www-data:www-data project_folder
Move pubic/ wherever you want.
Open index.php in public and edit the two lines which point to bootstrap/ so they point to the new project location.
Add this line in index.php too $app->bind("path.public", function() { return __DIR__; });


Move the public/ directory out of the project
With the public directory out, now move the entire project somewhere safe. Preferably not in public_html space. This is important because it is very easy to hack the site if the main project folder is not secure.
Depending on your server, you might need to change ownership on the private files to the server (apache) name. For example: chown -R www-data:www-data projectfolder. Later when you want to edit the project I think it is ok to set all views/ and Controllers/ back to your own user.
NOW it becomes very easy. Take your original public directory which you moved out and name it WHATEVER-YOU-WANT and go ahead and put it WHEREVER-YOU-WANT.
Open index.php in the public folder and configure the first two statements which point to bootstrap/autoload.php and bootstrap/app.php. Just make sure these two paths point to the private location where you moved your project.
One more line of code in this index.php file to tell Laravel where the new home path is: $app->bind("path.public", function() { return __DIR__; });.

That's all! Now you can move that public folder around wherever you want. If you are working from your own server, also make sure htaccess is setup correctly. You should have an .htaccess file in your public directory by default.


Card image cap

Gadgets which do interesting things using web tech.

View Gadgets
Card image cap

View some of Dream Gears completed projects.

View Projects
Card image cap
News Archive

Many articles of interest on software and computing.

View Archive