A basic description of how to deploy a Laravel applications to a shared web hosting package. In this example I am using Web Hosting Canada.
First register for a shared WHC account. I'm using the Pro shared hosting package. Hosting on WHC will work quite similarly to other shared web hosting packages such as GoDaddy, HostPapa, BlueHost, etc...
When you register with WHC you will receive an email with your cPanel/FTP username and password. If you don't reaceive this email, you can change your password from the Client Area:
And find your username from logging into cPanel:
Using cPanel create a new MySQL username and database. And make sure to grant your new user permission to your new database. For now you can give the new MySQL user full premissions to the databae:
Connect to your hostting account using FTP. The IP address is availble on the right had side of your cPanel under Shared IP Address. You can use the same username and password from the Registration step:
Once you have connected to your hosting using FTP, navigate to the public_html fodler and upload the contents of the public folder from your Laravel project. Navigate back to the original folder (../public_html) and create a folder named laravel. Upload everything to this folder except the public and vendor folders.
On the cPanel dashboard, find the Select PHP Version tool and change the Current PHP verion to PHP 8.1.
On the cPanel dashboard, find the MultiPHP Manager tool and make sure your domain is set to inherited. If it isn't, select the checkbox for your domain and choose inherit from the drop down.
Using the File Manager, edit the .env file and change the database credentials to your new database username and password:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=<DB_DATABASE>
DB_USERNAME=<DB_USERNAME>
DB_PASSWORD=<DB_PASSWORD>Note
If there is a DB_SOCKET variable, you can remove this.
Using the File Manager tool, edit the /public_html/index.php file. Change the three file references to include the laravel folder. Change this:
if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) {
require $maintenance;
}To this:
if (file_exists($maintenance = __DIR__.'/../laravel/storage/framework/maintenance.php')) {
require $maintenance;
}And make the same change to the other two similar lines of code.
On the cPanel dashboard, find the Terminal tool. If you type ls you will see a list of the directory contents. Change the directory to the laravel folder:
cd laravelRun composer:
composer installAnd run your migrations:
php artisan migrate:fresh --seedOpen your domain to see if it's working.
If it's not, turning on display_errors will help. Open the Select PHP Version tools and the Options tab. Check off display_errors.






