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.
Table of Contents
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
- Local Setup: Ensure your Laravel project is working correctly in your local environment.
- 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
- Compress Your Project: Zip your entire Laravel project.
- Login to Hosting Control Panel: Access your hosting control panel (e.g., cPanel).
- File Manager: Open the File Manager.
- Upload Zip File: Upload your zipped Laravel project to the root directory of your hosting account (usually
public_html
).
Step 3: Extract Files
- Extract the Zip File: Once uploaded, extract the zip file in the
public_html
directory. - Move Files: Move all files and folders from the extracted directory to the
public_html
directory if necessary.
Step 4: Public Directory Setup
- Move Public Contents: Move the contents of the
public
directory (inside your Laravel project) to thepublic_html
directory. - Update Paths:
- Open the
index.php
file in thepublic_html
directory. - Update the paths to the
autoload.php
andapp.php
files:php require __DIR__.'/../vendor/autoload.php'; $app = require_once __DIR__.'/../bootstrap/app.php';
tophp require __DIR__.'/../vendor/autoload.php'; $app = require_once __DIR__.'/../bootstrap/app.php';
Step 5: Environment Setup
- Database Configuration: Ensure that your
.env
file in the root directory has the correct database settings for your shared hosting. - File Permissions: Make sure the
storage
andbootstrap/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
- 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.
- 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:
- Local Install: Ensure all Composer dependencies are installed locally before uploading.
- 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:
- Generate Key Locally: Generate the key locally using
php artisan key:generate
. - 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.