Serve Laravel website on a shared hosting

Serving a Laravel website on a shared hosting can be a bit challenging, but it’s definitely possible. Here are some steps you can follow to deploy a Laravel website on a shared hosting:

  1. Make sure your shared hosting environment meets the minimum requirements for running Laravel. This includes PHP version 7.3 or higher, the required PHP extensions, and a MySQL or PostgreSQL database.
  2. Create a new folder in your shared hosting account where you want to host your Laravel application.
  3. Copy all the files and folders from your Laravel project into the folder you created in the previous step.
  4. In the root folder of your Laravel project, rename the server.php file to index.php.
  5. Edit the .htaccess file in the root folder of your Laravel project and change the following lines:
    RewriteRule ^(.*)$ server.php [L]
    

    to:

    RewriteRule ^(.*)$ index.php [L]
  6. Edit the index.php file and change the following line:
    require __DIR__.'/../bootstrap/autoload.php';
    

    to:

    require __DIR__.'/bootstrap/autoload.php';
    
  7. Edit the index.php file and change the following line:
    $app = require_once __DIR__.'/../bootstrap/app.php';
    

    to:

    $app = require_once __DIR__.'/bootstrap/app.php';
    
  8. Edit the public/.htaccess file and change the following line:
    RewriteRule ^ index.php [L]
    

    to:

    RewriteRule ^ /index.php [L]
    
  9. Set the appropriate file permissions for your Laravel project files and folders, including the storage folder, the bootstrap/cache folder, and any other folders that may require write access.
  10. Create a new MySQL or PostgreSQL database on your shared hosting account and update the DB_ settings in the .env file of your Laravel project to match the new database details.
  11. Finally, access your Laravel website in a web browser by visiting the domain name or IP address associated with your shared hosting account.

These steps should help you get your Laravel website up and running on a shared hosting environment. However, note that the steps may vary depending on the specific hosting provider you are using.

Published by

mustafabugra

Systems Engineer

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.