Skip to content

How to Set Up a Laravel Site on Shared Hosting

Laravel on shared hosting

How to Set Up a Laravel Site on Shared Hosting Without SSH Access?

Deploying Laravel projects on shared hosting has always been a hot topic.

Most web hosting providers do allow SSH access to the customers. If you don’t see it, you can ask the customer care executive to give you access(enable SSH).

Otherwise, you have to upgrade your plans to another one or simply get Dedicated hosting.

How To Set Laravel Project

Requirements to host Laravel project on shared hosting

Laravel has outlined the basic server requirements on its official documentation pages. Additionally, each version comes with its own comprehensive guide to help you get started.

Another thing you will need is a database. So keep your SQL file ready. As you can not run SSH commands to migrate files on the server, you will need a database file. It could be compressed or uncompressed.

Setting up a Laravel site on shared hosting without SSH access can be a bit challenging but it is definitely possible. Here are the steps you can follow:

Step 1: Prepare Your Laravel Project

  1. Local Setup: Ensure your Laravel project is working correctly in your local environment.
  2. Environment Configuration: Set up your .env file with the correct database credentials and other configurations required for the shared hosting environment.

Step 2: Upload Files to Shared Hosting

  1. Compress Your Project: Zip your entire Laravel project.
  2. Login to Hosting Control Panel: Access your hosting control panel (e.g., cPanel).
  3. File Manager: Open the File Manager.
  4. Upload Zip File: Upload your zipped Laravel project to the root directory of your hosting account (usually public_html).

Step 3: Extract Files

  1. Extract the Zip File: Once uploaded, extract the zip file in the public_html directory.
  2. Move Files: Move all files and folders from the extracted directory to the public_html directory if necessary.

Step 4: Public Directory Setup

  1. Move Public Contents: Move the contents of the public directory (inside your Laravel project) to the public_html directory.
  2. Update Paths:
  • Open the index.php file in the public_html directory.
  • Update the paths to the autoload.php and app.php files:
    php require __DIR__.'/../vendor/autoload.php'; $app = require_once __DIR__.'/../bootstrap/app.php';
    to
    php require __DIR__.'/../vendor/autoload.php'; $app = require_once __DIR__.'/../bootstrap/app.php';

Step 5: Environment Setup

  1. Database Configuration: Ensure that your .env file in the root directory has the correct database settings for your shared hosting.
  2. File Permissions: Make sure the storage and bootstrap/cache directories are writable by updating their permissions. You can typically do this through the File Manager in the control panel.

Step 6: Database Setup

  1. Create Database: Use the control panel to create a new database and a database user. Assign the user to the database with the necessary permissions.
  2. Import Database: If you have a database dump, you can import it using phpMyAdmin or a similar tool provided by your hosting service.

Step 7: Update .env File

Make sure your .env file has the correct configurations, especially for the database:

DB_CONNECTION=mysql
DB_HOST=your_host
DB_PORT=3306
DB_DATABASE=your_database
DB_USERNAME=your_username
DB_PASSWORD=your_password

Step 8: Dependencies

Since you don’t have SSH access to run Composer commands directly on the server:

  1. Local Install: Ensure all Composer dependencies are installed locally before uploading.
  2. Vendor Directory: Upload the vendor directory along with the rest of your Laravel project.

Step 9: Application Key

Ensure the APP_KEY in your .env file is set. If it’s not set:

  1. Generate Key Locally: Generate the key locally using php artisan key:generate.
  2. Set the Key: Copy the generated key to your .env file on the server.

Step 10: Access the Site

Once everything is set up, try to access your site via your domain. It should load your Laravel application.

Troubleshooting

If you encounter issues:

  • Logs: Check the logs in the storage/logs directory for any error messages.
  • Permissions: Verify that the permissions are set correctly on the storage and cache directories.
  • Configuration: Double-check your .env configurations.

Following these steps should help you get your Laravel site up and running on a shared hosting environment without SSH access.