Arsal • Location • Starter

Technical Review: Hostcry Engineering Team

How to Host Laravel Project on cPanel, Proven Setup

AI Summary
Hosting a Laravel project on cPanel works when the domain serves public/index.php and the rest of the app, including .env, stays off the web. Check that the account’s PHP version and extensions match the project, build vendor and the front end before upload, then connect a MySQL database using cPanel’s prefixed names. After the homepage loads, turn on HTTPS, link storage, and run the scheduler with the same PHP binary the site uses. Shared cPanel is enough for normal requests and cron, but not for always-on tools such as Horizon, Reverb, or Octane.

Your Laravel project is already built. On cPanel the deploy usually fails in one of two ways: the whole tree lands in public_html, or the first visit is HTTP 500. Here is how to host a Laravel project on cPanel without either result. Point the domain at public/index.php, and keep every other file, including .env, outside the folder the web can read.

Run the account check before you zip anything. Layout, upload, database, and a single error table follow in that order.

Check the cPanel account before you upload anything

Yes. This account can run the project when the domain's PHP matches the app, the extensions below are enabled, and Domains can aim the site at public. A primary domain fixed to public_html still qualifies if a later fallback is allowed. Open MultiPHP Manager or Select PHP Version, then Domains, then Cron Jobs, before any upload.

Match PHP and extensions to the Laravel version you are shipping

Read the PHP line in composer.json. Laravel's deployment documentation currently requires PHP 8.3 or higher for Laravel 13, plus Ctype, cURL, DOM, Fileinfo, Filter, Hash, Mbstring, OpenSSL, PCRE, PDO, Session, Tokenizer, and XML. Older apps follow their own constraint. Check that page again on deploy day. The minimum moves with the release.

Set the version in MultiPHP Manager, or in Select PHP Version on CloudLinux. Enable missing extensions for this domain only. cPanel's install notes show Composer stopping when Fileinfo is absent.

Confirm Terminal, cron, and document-root control

  • php -v in Terminal must meet the version you selected. If it is older, copy the full binary path. On EasyApache it usually sits under /opt/cpanel/ea-phpXX/root/usr/bin/php. Confirm the path on this server. Cron will use the copy.

  • Cron Jobs is listed in the menu.

  • Domains shows whether this hostname can leave public_html. On many servers the primary domain cannot. An addon domain or a subdomain can.

HostCry has offered hosting since 2017. Ask whether the primary document root is locked before you pick a layout. Moving files will not unlock it.

Build the production files on your computer

Build on your computer when the account has no Node or no Composer. Use a PHP release on the same major line as the server.

Run composer install --no-dev --optimize-autoloader, then composer check-platform-reqs, then npm run build so public/build exists. Platform-reqs fails on the desktop if the server PHP would reject the lock file. Composer documents --no-dev and the optimised autoloader as the install you ship.

Dependencies can go on the server instead, but only where Composer and SSH already exist. HostCry's Laravel plans include both. Otherwise vendor belongs in the zip. With no Terminal, generate APP_KEY locally and save it for the server .env. Other environment values wait until upload.

Put in the zip

Leave out

app, bootstrap, config, database, public (with public/build), resources, routes, storage, vendor, artisan, composer.json, composer.lock

node_modules, .git, tests, and a development .env

The archive should open straight onto those folders. An extra parent directory is how the domain misses the project after extract.

An illustration of a locked folder kept outside a browser window and a public folder placed inside it.

Choose where the domain points so .env stays private

Point the domain at public. Symlink public_html only when the primary root is locked and the host allows links. Copy the files inside public only when symlinks are blocked. Leave app, vendor, and .env off the web. Laravel's deployment documentation says every request should reach public/index.php, and that moving index.php onto the project root exposes configuration files.

Layout

When you can use it

What the web can see

What goes wrong

Addon or subdomain root is myapp/public

Domains lets you edit that hostname

Only public

A root of myapp exposes the whole project

public_html symlinked to myapp/public

Primary root is locked, symlinks allowed

Only public

A blocked link breaks the hostname. Restore the renamed folder

public files copied into public_html, app kept outside

Symlinks are blocked

Only the copied files

URLs fail without usePublicPath(), and upgrades must revisit the copy

Whole project in public_html, rewrite on the project root

Popular, and the wrong choice

Project root, once the rewrite stops

.env can be requested directly

Point an addon domain or subdomain at public

Put the project in the home directory, for example /home/username/myapp, beside public_html. Set that hostname's document root to myapp/public. Keep this layout whenever Domains allows it.

Symlink the primary domain when its document root is locked

Use the note from the account check. Where the primary root cannot move and symlinks are allowed:

  1. Rename public_html to public_html_backup.

  2. Link public_html to /home/username/myapp/public.

  3. Restore the backup folder at once if the hostname is a broken link.

Stop when the host has disabled symlinks. This link is only the web root. The storage link comes later and is a different path.

Copy only the public files if symlinks are blocked

Leave the application outside the web root. Copy the contents of public, including .htaccess, into public_html, and point the copied index.php at the outside application. On current Laravel, call usePublicPath() so generated URLs use the folder visitors actually hit. Review that copy on the next framework upgrade. This is the last resort.

These accounts run on Apache or on LiteSpeed. Both honour a document root and the .htaccess file inside public.

Upload the project and connect MySQL

You host the Laravel project on cPanel by uploading that build, applying the layout already chosen, and connecting a database whose names match .env.

Upload the build and set the web root

Copy the live public_html and its database before you extract or rename. Prefer SFTP for a large archive. File Manager often stalls on vendor. Extract in the home directory, not over a site that is still live. Apply the document root, the symlink, or the public-file copy. Include vendor when it was built locally. Run Composer on the server only if that account already has it. Some plans offer Git as well. These steps stay on a zip or on SFTP.

Create the database and write .env

In MySQL Databases, create a database and a user, then grant that user all privileges on that database. cPanel prefixes both names with the account username. cPanel's Laravel notes show the pattern: the account cptest yields a name such as cptest_laravel. Copy both strings from your panel. In File Manager, show hidden files first. Dotfiles such as .env stay invisible until that toggle is on.

APP_ENV=production

APP_DEBUG=false

APP_KEY=base64:the-key-you-generated

DB_CONNECTION=mysql

DB_HOST=127.0.0.1

DB_PORT=3306

DB_DATABASE=account_dbname

DB_USERNAME=account_dbuser

DB_PASSWORD=the-password-from-the-panel

Use 127.0.0.1 for DB_HOST. On some cPanel servers localhost tries a socket the account cannot open. Laravel's deployment page says APP_DEBUG must be false in production, because true can show configuration to anyone who triggers an error. Import the SQL dump in phpMyAdmin, or run php artisan migrate --force from Terminal. An "access denied" reply means the prefix or the user grant is wrong. Fix those strings rather than creating another empty database.

Make the cache folders writable and open the homepage

Folders are 755 and files are 644. storage and bootstrap/cache must be writable by the PHP user. Skip 777.

Open the homepage, then open /up. Laravel's health route returns HTTP 200 when the application has booted cleanly. That 200 ends the upload. The certificate, public file URLs, and the scheduler are still separate.

Turn on HTTPS, public storage, and the scheduler

A working homepage still leaves three production settings.

Serve the site over HTTPS

Run AutoSSL or the host's Let's Encrypt action. Set APP_URL to the https origin, with scheme and hostname and no trailing path. Mixed content after a redirect usually means a link, or a compiled file in public/build, still says http. Rebuild the assets. More rewrite rules will not correct the URL baked into them.

Publish files from storage

From the project directory, run php artisan storage:link. It creates public/storage pointing at storage/app/public. If /storage returns 404 and disabled functions include symlink, ask the host to allow it. Do not replace the link with a redirect route. The web-root symlink does not create this one.

Run the scheduler every minute

Add one cron job, every minute, using the PHP binary saved in the account check:

/opt/cpanel/ea-php83/root/usr/bin/php /home/username/myapp/artisan schedule:run

Replace both paths. Laravel's scheduler expects that command once a minute. The bare command php is how the site runs on 8.3 while the task dies on an older command-line binary.

Then run php artisan optimize. Cached config ignores later .env edits until php artisan optimize:clear, and env() outside config files returns null after the cache. Edit, clear, then optimize again.

Shared hosts often block PHP's local mail. Set MAIL_MAILER from the SMTP details the host gives you, and finish the mailbox in the host's mail screen.


Trace the first error to one cause

Open cPanel's Errors log before storage/logs/laravel.log. Laravel cannot write its log until storage is writable, so that file stays empty on the outage you need to see. Match one row, change that cause, and reload /up.

What you see

Look here

One cause

HTTP 500, blank page

cPanel Errors

Missing APP_KEY, or storage is not writable

SoftException: index.php writable by group

That file's mode

suPHP rejects group write. cPanel documents it as a handler error. Remove the group-write bit

Class or extension error

PHP screen from the account check

Wrong PHP, or an extension from that list is off

Vite manifest not found

public/build

Front end was not built, or the domain is not on public

CSS or images 404

Document root and APP_URL

Web root is one folder off, or usePublicPath() was never called

Database access denied

DB_DATABASE, DB_USERNAME

Prefixed names disagree with the panel, or the user was not added

Homepage works, /storage does not

public/storage

Storage link missing, or symlink() is disabled

One matching row is the whole repair. A second forum recipe usually moves the error sideways.

Know when shared cPanel cannot run the app

Shared cPanel can serve requests, run schedule:run, and drain a light queue with queue:work --stop-when-empty from cron. It cannot keep Horizon, Reverb, Echo, or Octane under Supervisor. Laravel's deployment notes talk about reloading those processes, which assumes a server allowed to leave one running.

Stays on shared cPanel

Needs a process manager

Requests, the scheduler, a short cron burst for a database queue

Horizon, Reverb, Octane, or any worker that must stay up all day

Redis is not the same thing as a daemon, and not every shared plan has it. Check before you set QUEUE_CONNECTION=redis. If you are still choosing an account, compare SSH, Composer, PHP versions, Redis, and cron with the published Laravel hosting list, and rely only on what that page includes.

Confirm the account can finish the job

Call the deploy finished when the domain, the database credentials, and production mode agree with the settings you already made. If this account cannot change PHP, point a domain at public, or run cron, choose a plan that provides those three. Confirm each one in the panel before you start the upload over. Readers who still need hosting or a domain can arrange both with HostCry.

Got questions?

Frequently Asked Questions

Quick answers about this article.

No. A one-click installer, Softaculous included, creates an empty Laravel application. cPanel's support article does the same with composer create-project. The button does not upload the project you built, even on hosts that advertise one.

Yes. Give each app its own directory, its own document root, and its own database and .env. Two hostnames pointed at one environment file share a database and a cache.

Yes. Aim only the subdomain's document root at that app's public folder. The site already in public_html stays there, on the original hostname. The subdomain does not need those existing files, and the main hostname does not enter Laravel.

At the registrar, set the host's nameservers, or point the A record at the IP the host gives you. DNS can lag, so cPanel may already be finished while the old site still answers. Leave the previous hosting up until the new address responds.

Keep three copies off the account: the current files, a database dump, and the new .env. Do not leave the only backup inside the folder you are about to rename. Undoing a symlink or a move is awkward when the previous site lived only in public_html.

Keep the same document root and the same .env. Replace the code, vendor, and public/build, run the new migrations, then php artisan optimize:clear. Dump the database before migrating. Leave PHP, the document root, and cron as they are unless the release requires a newer PHP.

Plan one working session when the domain PHP and the document root are already set. Add time if the host must enable an extension or unlock the primary root. Further file edits do not shorten that wait. No fixed number of minutes fits every account.