DEV Community

Stephen Jude
Stephen Jude

Posted on • Originally published at Medium on

How To Deploy A Laravel Project On Linux Shared Hosting In 5 Minutes

Photo by Chris Liverani on Unsplash

In my 2019 review I mentioned that I was working on a side project which is setting up a shared hosting platform with Laraveldevelopers in mind.

I have deployed lots of Laravel projects on Linux shared hosting and I know how painful it is especially when there is no ssh access.

Litehost is here to solve that problem. It has ssh access on all its hosting plans and it has Composer, Git & PHP CLI pre-installed on its servers. Finally it pretty affordable, just ₦400/month ($1.11). Isn’t that amazing? Litehost is live and its been accepting customer since 24th December 2019.

Just yesterday I moved my blog which I built with Laravel to Litehost server. So I am going to show you how I did it in 5 minutes.

Lets get to the main thing. I will assume you have already a Cpanel account with ssh access on it.

Project Setup

Push your Laravel project to a remote git repository. I already have my blog’s repository on GitHub and its open source.

Now lets go back to our Cpanel. If you have ssh access on your hosting plan, look for terminal under the advanced tab and click on it.

Move into your public directory and pull your Laravel project from your remote repository.

cd public\_html

git clone [https://github.com/stephenjude/stephenjude.tech.git](https://github.com/stephenjude/stephenjude.tech.git) blog
Enter fullscreen mode Exit fullscreen mode

With this command you now have your project inside public_html/blog folder.

Make a copy of your .env.example file and update your .env variables. You can do this using the CPanel file manager. Remember that Show Hidden Files (dotfiles) must be enabled from the CPanel file manager settings.

Now enter into the project folder and pull all the required dependencies.

cd blog

composer install
Enter fullscreen mode Exit fullscreen mode

Fine, now we have our Laravel project ready to be served but its remaining one more thing. Laravel makes use of the storage folder for lots of things like writing logs, caching views and local file storage for uploads.

chmod 777 storage
Enter fullscreen mode Exit fullscreen mode

I know this is not advisable but we are not on a VPS. We are on a shared server with some some limits to what we can do. Yeah.

Finally you have to setup your ** .htaccess** file to point to your Laravel public folder. You can find this .htaccess file inside the public_html folder. if its not there then create one and update it with the code below.

RewriteEngine on
RewriteCond %{REQUEST\_URI} !^blog/public
RewriteRule ^(.\*)$ /blog/public/$1 [L]
Enter fullscreen mode Exit fullscreen mode

That’s it, you have successfully deployed your Laravel project.

Conclusion

I know this not the best way to deploy a Laravel project but I believe it’s efficient enough to get your project up and running on a Linux shared hosting.

I am still working on setting up shared hosting plans tailored for Laravel developers. The idea is to save time and deploy faster on shared hosting.

Join my weekly newsletter and never miss out on new tutorials, tips and more.

You can also follow me on twitter @stephenjudeso

Top comments (3)

Collapse
 
shahzebbbbb profile image
Shahzeb Ahmed

Normally I abstain from commenting on blogs as I am more of a silent reader. However, your detailed blog convinced me to applaud you for doing such an impressive job. Brilliantly written! Looking forward to reading more of your stuff.

Still, it takes 5 minutes to deploy the Laravel web application, I personally use Cloudways they offer Laravel installation within a single click.

Here is the link if you want to know more about: cloudways.com/blog/install-laravel...

Collapse
 
stephenjude profile image
Stephen Jude

Thanks Ahmed

Collapse
 
t08apporio profile image
t08-apporio

Hi Stephen, your quick deployment guide is a blessing. Just one query. What if we are on a VPS? What do we do about permission to the storage folder then?