This month I got a couple of clients asking me to recommend VPS or dedicated servers' providers because they want to install Laravel and they thought it's impossible to do that in a shared hosting environment like what we offer at 2MHost! They tried to upload the entire Laravel application from their computer to their hosting account using FTP, the process was long and without success at the end.
The good news is our shared hosting account is equipped with many hidden features, like shell terminal access, PHP Composer and Git. With such tool's using FTP is no longer necessary.
So, in this short guide, we will go through how to set up a new Laravel 9 application on regular shared hosting account, it will be surprisingly easy without anything to upload.
It's important to mention that Laravel is made to run on the root folder of your website, not on a subdomain or a folder. I presume that you will set it up on fresh hosting account.
Let's start, there are 2 ways to install Laravel
Here we will install a fresh copy of Laravel using PHP Composer.
1. Laravel 9 requires PHP 8 and above, so you need to use your cPanel to change the PHP version of your website to version 8.
2. Login to your new hosting account via terminal, you can use the terminal in your cPanel or any other terminal software like PuTTy. Login with your cPanel user name and password and remember that we use port 5555 for SSH in all servers.
3. Create a new Laravel application using Composer, we will install Laravel in a folder called my-app, you can choose any other name
It will take seconds and you are done, there is nothing to upload, only a single command line!
4. Now the trickiest step, Laravel has a folder called public, this folder contains the index.php file, the my-app/public folder is one level under cPanel's public folder public_html, so what we need to do is to let cPanel's public_html folder loads the content of Laravel's public folder.
First, we will delete the entire public_html folder (its new hosting account, so nothing to worry about):
then create a symbolic /public_html to link to /my-app/public:
That's it. Now, your Laravel website is running smoothly from a shared hosting!
Here we will deploy the application that you are already developing onto your local computer, in this tutorial, I'll presume that you already have a remote repository set up on Github for your application and we will pull the changes from it to the website.
1. Like the first method, change the PHP version to 8 and login to your account via terminal.
2. Create a new folder for your application, my-app or any other name, and change directory to it.
3. Initiate Git, and add your application repository as remote origin
4. Pull a copy of the remote repository
5. Install Laravel dependencies using Composer
6. Create a local .env file
7. Create a new Laravel key
8. Finally, Delete /public_html folder and create a symbolic link to Laravel public folder
We are done, your website will load your application.
Like Laravel setup on any environment, you will need to create a symbolic link for the public storage desk:
And create a MySQL database in your cPanel and configure it in /my-app/.env file.
There is only one known limitation, you can't run a Laravel Queue Worker monitor, if you need to set up one, then please contact us to help you.
Personal shared hosting account has enough resources (RAM/CPU) to run Laravel application during development, however, it's highly recommended to choose high resources hosting package on a litespeed server when website go live.
Litespeedtech, the company behind Litespeed server has released a special package for Laravel caching. With the LSCache package, your application will deliver better performance and superior user experience.
If your Laravel application is hosted on Litespeed server, then remember to install the caching package