Hosting your Laravel Project on a shared Hosting can be a little bit tricky sometimes especially if you are new to the Framework. This article will guide you through hosting your Laravel Project on a shared Hosting. There are two ways of going about this, feel free to choose the one that best suits your need.
Add your app domain as an addon domain by following the steps below:
Login into your hosting account.
- Click on the domain Tab
- Locate the “Assign a domain to your Control Panel account”
- Follow the instruction as given by your hosting account, when your get to where you choose the addon directory, make sure the directory points to the directory of your Laravel app slash public. That is; if your app is hosted in “mylaravelapp” then your addon directory will be “mylaravelapp/public”
- And that’s it.
This method is for those of us whose app domain is actually the main domain of our hosting account.
Login into your hosting account
- Scroll down to the Files section.
- Click the File Manager icon.
- Check the View Hidden Files checkbox.
- You are working with your primary domain, so select the WebRoot (public_html/www) option.
- Right click the .htaccess file, if one exist and choose Code Editor. If no .htaccess found create one
- Modifying the .htaccess by adding the following code to the .htaccess file in the public_html folder of your hosting account. You will need to insert the following code block and make modifications as noted in the (#) comments.
- You will need to change the two instances of example.com to your domain, and the three instances of subdirectory to the folder where you installed your laravel app slash pubic/index.php. That is; if your app is hosted in “mylaravelapp” then subdirectory will be “mylaravelapp/public/index.php”.
- And that’s it.
I would seriously advise against hosting your Laravel project on a shared hosting. If you need a staging environment to test your app, Heroku offers a free plan that supports hosting different applications including Laravel for free. I find Matt Stauffer post on Installing a Laravel app on Heroku interesting. You can give it a try.