How I Hosted My Laravel App on cPanel / DirectAdmin

Deploying a Laravel application on shared hosting panels like cPanel or DirectAdmin can sometimes feel like trying to fit a square peg into a round hole. Unlike a VPS where you have full SSH control, shared hosting requires a few clever workarounds especially when it comes to routing and file storage.

PS

Prospersites Editorial

How I Hosted My Laravel App on cPanel / DirectAdmin

Deploying a Laravel application on shared hosting panels like cPanel or DirectAdmin can sometimes feel like trying to fit a square peg into a round hole. Unlike a VPS where you have full SSH control, shared hosting requires a few clever workarounds especially when it comes to routing and file storage. After plenty of trial and error, I found a straightforward, reliable method to get my Laravel apps live. If you are struggling with 404 errors, broken image links, or messy folder structures, here is the exact step-by-step process I use.

Step 1: Prepare the Project Locally

Before touching the server, you need to bundle up your application so it is optimized for a production environment. Open your terminal in your local project directory and run:

Bash

# Compile your frontend assets

npm run dev

# Install only production PHP dependencies and optimize the autoloader

composer install --optimize-autoloader --no-dev

Step 2: Compress and Upload

With your dependencies optimized, it is time to move the files to the server.

Compress your entire Laravel project folder into a .zip file.

Log into your cPanel or DirectAdmin account.

Open the File Manager and navigate to your root directory (usually public_html or your main domain folder).

Upload the .zip file and extract it right there in the root directory.

Step 3: Export and Import the Database

Next, we need to migrate your data.

Open your local database tool (or local phpMyAdmin) and export your database as a .sql file.

In your hosting control panel, create a new MySQL Database and Database User. Add the user to the database with full privileges.

Open phpMyAdmin on your server, select your newly created database, and import the .sql file.

Finally, open your .env file on the server and update your DB_DATABASE, DB_USERNAME, and DB_PASSWORD to match your new credentials.

Step 4: Write .htaccess to Point to the Public Folder

By default, shared hosting directs traffic to the root folder, but a Laravel app is designed to be served securely from the public folder. Instead of hacking apart Laravel's directory structure, we can fix this with a simple .htaccess file.

Create a file named .htaccess in your root directory (the same level as your .env file) and add the following code:

Apache

<IfModule mod_rewrite.c>    RewriteEngine On    # Redirect all requests to the public directory    RewriteRule ^(.*)$ public/$1 [L] </IfModule>

This cleanly routes all incoming traffic straight to public/index.php without exposing your core application files.

Step 5: Fix Image Storage & Permissions

This is the step that trips up most developers. On shared hosting, you often can't run php artisan storage:link via SSH to create the symlink required for uploaded images.

Here is how I bypassed the symlink issue entirely:

Go into your public directory on the server and manually create a new folder called storage.

Right-click the folder, select Change Permissions, and set it to 755 so the server can read and write to it.

Open config/filesystems.php and locate the public disk array. Update it to look exactly like this:

PHP

'public' => [    'driver' => 'local',    'root' => public_path('storage'),    'url' => env('APP_URL', 'https://yourdomain.com') . '/storage',    'visibility' => 'public',    'throw' => false,    'report' => false, ],

Finally, scroll up slightly in that same filesystems.php file and ensure your default filesystem disk is set to public:

PHP

'default' => env('FILESYSTEM_DISK', 'public'),

Wrapping Up

And that’s it! By routing traffic through .htaccess and explicitly pointing Laravel's storage configuration to a physical folder inside the public directory, the app runs perfectly. No terminal access required, no broken image links, and your core files remain secure.

Tutorials • September 25, 2026 • 5 min read
Share this article:
Request Quote