EN · $ USD
Developer and Application Servers

How to Deploy a Laravel Project on cPanel Hosting

7 min read Updated: Sunucu Atlas technical team

In short

To deploy a Laravel project on cPanel hosting, put the project files outside public_html, point your domain's document root to the project's public folder, run composer install over SSH, set the app key and database credentials in .env, then run migrate, storage:link and the cache commands. You need hosting that provides SSH, Composer and the right PHP version.

In this guide
  1. Before You Start: Requirements
  2. 1. Prepare the Project for Production
  3. 2. Upload the Files Outside public_html
  4. 3. Point the Web Root to the public Folder
  5. 4. Install Dependencies over SSH
  6. 5. Set Up the Database and the .env File
  7. 6. Run the Artisan Commands
  8. 7. Check File Permissions
  9. 8. SSL and Scheduled Tasks
  10. Update Checklist for New Releases
  11. Common Errors
  12. Which Plan Should You Start With?

The right way to deploy a Laravel project on cPanel hosting is this: put the application files in a folder outside public_html, expose only Laravel's public folder as your domain's web root, install dependencies over SSH with composer install, and configure the .env file for the server. Dumping the whole project into public_html and typing /public in the address bar is insecure and can expose your .env file. This guide walks through every step, in order, from scratch to live.

Before You Start: Requirements

Unlike a classic PHP site, Laravel needs the command line. Make sure your hosting has the following:

  • SSH or cPanel Terminal access: to run composer and php artisan commands.
  • Composer: the PHP dependency manager. It builds the vendor folder on the server.
  • A supported PHP version: current Laravel releases require PHP 8.2 or later. The "php" line in your project's composer.json tells you which version you need.
  • Required PHP extensions: pdo_mysql, mbstring, openssl, tokenizer, xml, ctype, fileinfo and bcmath.
  • A MySQL/MariaDB database and a user with privileges on that database.

Sunucu Atlas Laravel hosting plans are built for exactly these needs: cPanel with Terminal/SSH access, Composer and Git, PHP version selection up to 8.5, and the LiteSpeed web server all come included.

1. Prepare the Project for Production

Before uploading, make sure the project runs on your local machine. Don't upload the vendor and node_modules folders; vendor will be built on the server, and node_modules isn't needed in production.

  1. If you use Vite for the front end, run npm run build locally. The resulting public/build folder must ship with the project.
  2. Don't package your .env file; you'll create it separately on the server.
  3. Compress the project into a ZIP file or push it to a Git repository.
# Locally, in the project folder
npm run build
zip -r proje.zip . -x "vendor/*" "node_modules/*" ".env" ".git/*"

2. Upload the Files Outside public_html

In cPanel, your home directory looks like /home/kullaniciadi. Put the project under it, for example in /home/kullaniciadi/laravel. That way your .env, storage and source code can't be reached from the web.

  1. Open File Manager in cPanel and create a folder named laravel in your home directory.
  2. Upload proje.zip to that folder and unpack it with Extract.
  3. Alternatively, pull it with Git over SSH: git clone https://github.com/kullanici/proje.git ~/laravel

If you work with Git, setting up automatic deployment is far easier than uploading files on every update; we cover it in the automatic deployment with cPanel Git Version Control guide.

3. Point the Web Root to the public Folder

In Laravel, the only folder that should be publicly accessible is public; that's where index.php lives. You can set this up in cPanel in two ways.

Method A: Change the document root for an addon domain or subdomain

If you're installing the project on an addon domain or a subdomain, enter laravel/public directly in the Document Root field when you add the domain. This is the cleanest method.

Method B: Use a symbolic link for the primary domain

The primary domain's document root is fixed to public_html. In that case, you can replace public_html with a symbolic link (symlink) pointing to Laravel's public folder. Back up the existing content first:

cd ~
mv public_html public_html_yedek
ln -s ~/laravel/public public_html
ls -la | grep public_html

The output of the last command should show public_html -> /home/kullaniciadi/laravel/public. If you'd rather not use a symlink, you can write a rule in public_html/.htaccess that rewrites all requests to the public folder, but then the project files stay inside public_html, so the symlink is the safer choice.

4. Install Dependencies over SSH

Open the Terminal tool in cPanel or connect over SSH from your own computer. For connection steps, see the cPanel SSH access and Terminal guide. First, check the PHP version on the command line:

php -v
composer --version

The command-line PHP version isn't always the same as the version you selected for the web. If they differ, fix the setting in cPanel's PHP selector or run commands with the full path to the right PHP binary. Then install dependencies in production mode:

cd ~/laravel
composer install --no-dev --optimize-autoloader

--no-dev skips test and development packages, and --optimize-autoloader speeds up class loading. If you hit the memory limit on shared hosting, try again in a few minutes, or make sure the composer.lock file you generated locally is in the project; with a lock file present, Composer skips dependency resolution and uses much less memory.

5. Set Up the Database and the .env File

In cPanel, go to MySQL Databases, create a database and a user, and grant the user all privileges. cPanel prefixes names with your account name, so the database name becomes something like kullaniciadi_laravel. Don't forget to select ALL PRIVILEGES when adding the user to the database; otherwise migrations can't create tables.

Next, create the .env file and generate the application key:

cd ~/laravel
cp .env.example .env
php artisan key:generate

Edit .env in File Manager or with nano .env. These are the critical lines for production:

APP_NAME="Projem"
APP_ENV=production
APP_DEBUG=false
APP_URL=https://alanadiniz.com

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=kullaniciadi_laravel
DB_USERNAME=kullaniciadi_dbuser
DB_PASSWORD=guclu-bir-parola

LOG_LEVEL=error

Never skip the APP_DEBUG=false line. If debug mode is left on, error pages can show visitors your environment details, including the database password.

6. Run the Artisan Commands

Create the database tables, set up the storage link for file uploads, and cache the configuration:

cd ~/laravel
php artisan migrate --force
php artisan storage:link
php artisan config:cache
php artisan route:cache
php artisan view:cache
CommandWhat it does
migrate --forceRuns migrations in production without asking for confirmation.
storage:linkCreates the public/storage link so uploaded files are reachable from the web.
config:cacheMerges all configuration into a single file. Run it again whenever you change .env.
route:cacheCaches route definitions to speed up routing.
view:cachePrecompiles Blade templates.

7. Check File Permissions

On cPanel, PHP usually runs as your own user, so 777 permissions aren't needed and shouldn't be used. The folders Laravel needs to write to are storage and bootstrap/cache:

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

If you still get "Permission denied" or a 500 error, work through the checks in the Laravel storage permission denied fix guide.

8. SSL and Scheduled Tasks

cPanel's AutoSSL installs a free certificate on your domain automatically; make sure APP_URL starts with https://. If your project uses the Laravel Scheduler, add this job under Cron Jobs in cPanel to run every minute:

* * * * * cd /home/kullaniciadi/laravel && php artisan schedule:run >> /dev/null 2>&1

Queue workers can't be kept running as a persistent process on shared hosting; cron-based approaches exist for that.

Update Checklist for New Releases

After the initial setup, following the same order every time you ship a new release keeps visitors from landing on a half-finished update:

  1. Put the site in maintenance mode: php artisan down. Visitors see a maintenance page instead of an error.
  2. Pull or upload the new code (git pull or a new ZIP).
  3. Update dependencies: composer install --no-dev --optimize-autoloader.
  4. Run new migrations: php artisan migrate --force.
  5. Refresh the caches: php artisan optimize:clear, then config:cache, route:cache and view:cache.
  6. Bring the site back up: php artisan up.

Taking a backup from cPanel or with mysqldump before any update that changes the database lets you roll back within minutes if something goes wrong.

Common Errors

  • You see a directory listing or a 403: the web root isn't pointing to the public folder. Check step 3.
  • 500 error with an empty log: the vendor folder is missing or the PHP version is too old. Check the composer install output and the PHP version in cPanel.
  • "No application encryption key": php artisan key:generate wasn't run, or config:cache was built with an old .env. Generate the key, then run php artisan config:clear followed by config:cache.
  • CSS/JS not loading: the public/build folder wasn't uploaded or APP_URL is wrong.
  • Where are the error details? Check the last lines of storage/logs/laravel.log with tail -n 50 storage/logs/laravel.log.

Which Plan Should You Start With?

For a single Laravel app, a few databases and normal traffic, the SA-DEV-1 Laravel hosting plan is a good starting point: 2 GB RAM, 2 cores, 40 GB NVMe storage, Terminal/SSH access, Composer and Git. If you're planning multiple projects, a staging environment or heavier traffic, compare the higher Laravel hosting plans and choose by addon domain, database and CPU limits. Servers are in Istanbul, and if you get stuck during setup you can open a support ticket with the Sunucu Atlas support team.

If your app needs always-on queue workers, a WebSocket server or Docker, it may be time to move from shared hosting to a server with root access; in that case, consider a VDS with root access or a Coolify server.

Frequently asked questions

Can I install Laravel on cPanel without SSH?

Technically yes, by building the vendor folder locally and uploading it, but you won't be able to run artisan commands and updates become harder. A plan with SSH or cPanel Terminal access is much safer and more practical.

Why shouldn't a Laravel project go inside public_html?

The project root contains .env, storage and your source code. If they sit inside public_html, a single misconfiguration can make sensitive files, including your database password, readable from the web.

How do I remove /public from the URL?

Point your domain's web root to Laravel's public folder. For an addon domain or subdomain, change the Document Root setting; for the primary domain, replace public_html with a symbolic link to the public folder.

I changed the .env file but the settings don't apply. Why?

If config:cache has been run, Laravel reads the cached configuration instead of .env. Run php artisan config:cache again after every change.

Which PHP version should I choose for Laravel?

Pick the newest stable version that matches the php requirement in your project's composer.json. Current Laravel releases require PHP 8.2 or later.

For this guide

Recommended plans

Our Laravel hosting plans include Terminal/SSH, Composer, Git and PHP version selection up to 8.5 in cPanel, so you can follow every step in this guide without installing anything extra.

SA-DEV-1

cPanel
Recommended

40 GB NVMe disk

$0.69/mo

+VAT

  • Processor2 cores
  • Memory2 GB
  • LocationIstanbul
  • Terminal / SSH Access (cPanel)
  • Composer and Git
  • Node.js and Python App Manager
  • PHP version selection (up to 8.5)

SA-DEV-2

cPanel

60 GB NVMe disk

$0.98/mo

+VAT

  • Processor3 cores
  • Memory3 GB
  • LocationIstanbul
  • Terminal / SSH Access (cPanel)
  • Composer and Git
  • Node.js and Python App Manager
  • PHP version selection (up to 8.5)

SA-DEV-3

cPanel

80 GB NVMe disk

$1.37/mo

+VAT

  • Processor4 cores
  • Memory4 GB
  • LocationIstanbul
  • Terminal / SSH Access (cPanel)
  • Composer and Git
  • Node.js and Python App Manager
  • PHP version selection (up to 8.5)

Laravel Hosting — tüm paketler

Need help with setup?

Send questions about your service in a support ticket, and our technical team will walk you through it step by step.