Skip to content
Deploying apps5 min read

How to deploy a Laravel project on hosting

Short answer

To deploy Laravel on cPanel, keep the project outside public_html and point the domain's or subdomain's document root to its public folder. Then create .env with your database details, run key:generate, migrate, storage:link and config:cache, add a cron job that runs schedule:run every minute, and make sure storage and bootstrap/cache are writable.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. Before you start
  2. Steps
  3. Troubleshooting
  4. On ArabyHost

Laravel doesn’t deploy like a plain PHP site: only public/index.php should receive requests, and the rest of the project has to stay out of the browser’s reach. So the key step is pointing the document root to public, followed by .env, artisan commands and permissions.

Before you start

  • A Laravel project that runs locally, in a Git repository or as a ZIP.
  • A PHP version that matches your Laravel release (11 and 12 need 8.2 or newer). Pick it in cPanel’s MultiPHP Manager.
  • A MySQL or MariaDB database (see create a MySQL database).
  • Composer and Node.js on your computer, to build the project if you don’t have SSH.

Steps

1. Build the project locally

On a plan without SSH, build everything before uploading:

composer install --no-dev --optimize-autoloader
npm ci && npm run build

The second command creates Vite’s public/build. ZIP the project without node_modules, .env and .git, but keep vendor and public/build.

2. Upload the project outside public_html

As a ZIP: in File Manager, open your home folder /home/USER, upload the archive and click Extract so the project lands in /home/USER/myapp.

With Git: in Git Version Control click Create, paste the repository URL and set a path such as /home/USER/repositories/myapp. Then add a .cpanel.yml file at the repository root that copies files to the app folder:

---
deployment:
  tasks:
    - export DEPLOYPATH=/home/USER/myapp/
    - /bin/rsync -a --exclude=.git ./ $DEPLOYPATH

After each push, click Update from Remote and then Deploy HEAD Commit on the Pull or Deploy tab. On plans without SSH, the branch you deploy must include vendor and public/build; GitHub Actions can build them into a dedicated deploy branch. Details in Git deployment in cPanel.

3. Point the document root to public

The cleanest option is an addon domain or subdomain whose root is public:

  1. In Domains, click Create A New Domain and enter the domain, such as app.example.com.
  2. Untick Share document root with the main domain.
  3. Set Document Root to myapp/public and click Submit.

For an existing domain, edit its Document Root under Domains.

If the app must run on the main domain, whose root is public_html, copy the contents of myapp/public into public_html, then in public_html/index.php replace every __DIR__.'/../ with __DIR__.'/../myapp/', for example:

require __DIR__.'/../myapp/vendor/autoload.php';
$app = require_once __DIR__.'/../myapp/bootstrap/app.php';

In that setup, copy public/build again after each build, and instead of storage:link create the link with ln -s /home/USER/myapp/storage/app/public /home/USER/public_html/storage.

4. Create the .env file

Copy .env.example to .env inside myapp and set:

APP_NAME="My App"
APP_ENV=production
APP_DEBUG=false
APP_URL=https://app.example.com

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=cpuser_app
DB_USERNAME=cpuser_app
DB_PASSWORD=strong-password

From Laravel 11 the default is DB_CONNECTION=sqlite, so switch it to mysql. Never leave APP_DEBUG=true on a live site.

5. Generate the app key

With SSH, run php artisan key:generate. Without SSH, run this locally:

php artisan key:generate --show

and paste the output into the APP_KEY= line of .env on the server.

6. Run the artisan commands

After the first upload you need:

php artisan migrate --force
php artisan storage:link
php artisan config:cache
php artisan route:cache
php artisan view:cache

Without SSH: add a temporary job under Cron Jobs that runs every minute:

cd /home/USER/myapp && /usr/local/bin/php artisan migrate --force && /usr/local/bin/php artisan storage:link && /usr/local/bin/php artisan config:cache >> /home/USER/artisan.log 2>&1

Wait a minute, check artisan.log for success, then delete the job so it doesn’t repeat. If command-line PHP runs a different version from the site, call that version’s binary directly, such as /opt/cpanel/ea-php83/root/usr/bin/php.

7. Set permissions

Laravel must write to storage and bootstrap/cache. PHP runs as your own user, so normal permissions are enough: 755 for directories and 644 for files. Never use 777. Set them in File Manager > Permissions or over SSH:

find storage bootstrap/cache -type d -exec chmod 755 {} \;
find storage bootstrap/cache -type f -exec chmod 644 {} \;

8. Add the scheduler cron job

Under Cron Jobs, add a job that runs every minute (the cron generator can build it):

* * * * * cd /home/USER/myapp && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1

For queues on shared hosting, run the worker from the scheduler itself in routes/console.php:

Schedule::command('queue:work --stop-when-empty')->everyMinute()->withoutOverlapping();

9. With SSH: later updates

On AI/Developer plans you can install dependencies on the server directly as your own user, with no root access needed:

cd ~/myapp
git pull
composer install --no-dev --optimize-autoloader
php artisan migrate --force
php artisan optimize

Troubleshooting

  • A 500 error with no message: open storage/logs/laravel.log. The usual cause is storage permissions; see Laravel 500 storage permissions.
  • “No application encryption key has been specified”: APP_KEY is empty, or config was cached before you added it. See Laravel no encryption key.
  • “Vite manifest not found”: public/build wasn’t uploaded. See Vite manifest not found.
  • Editing .env changes nothing: config is cached. Run php artisan config:clear, then config:cache again.
  • “Target class does not exist” only on the server: Linux file names are case-sensitive, so make sure each file name matches its class name exactly.
  • Uploaded images don’t show: storage:link didn’t run, or APP_URL is wrong.

On ArabyHost

On ArabyHost shared plans, Laravel runs with PHP 8.1 to 8.3 and MySQL/MariaDB, and you deploy by ZIP upload or from GitHub through Git Version Control and .cpanel.yml, without SSH. AI/Developer plans add SSH jailed in CageFS with Git and Composer, so you run artisan and Composer directly, and you can deploy from Claude or Cursor through Araby MCP. No plan includes root access. If something fails, the Araby AI assistant in the panel reads the error log and explains the fix. More on the developers page.

FAQ

Can Laravel run on shared hosting without SSH?

Yes. Build vendor and your front-end assets on your computer, upload the project as a ZIP or through Git, and point the document root to public. One-off artisan commands can run from a temporary cron job.

Why not put the whole Laravel project inside public_html?

Because .env and the project folders become reachable from a browser, which can expose passwords and keys. Keep the project outside public_html and make only its public folder the document root.

Which PHP version does Laravel need?

It depends on the Laravel release: 11 and 12 need PHP 8.2 or newer, while 10 runs from PHP 8.1. Check your version's requirements in the Laravel docs before deploying.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.