Hosting Laravel on a cPanel server with public_html directory

Hosting Laravel on a cPanel server with public_html directory

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

The public_html Trap: Why You Can't Just Drop Laravel Files There

When deploying a Laravel application to a cPanel environment, the most common mistake isn't misconfiguring .env variables or forgetting to run php artisan serve. It is assuming that because a file belongs in public_html, it should go there. If you attempt to upload your entire Laravel project—including app, routes, bootstrap, and vendor—directly into the public_html directory, your application will likely fail immediately upon request.

The reason lies in how Apache and cPanel serve files. The document root for a standard cPanel account is typically configured to point specifically at public_html. When a user requests example.com, Apache looks for the entry point (usually index.php) within that specific folder. If you dump your entire Laravel structure into public_html, you are forcing Apache to serve files from the wrong directory relative to the framework's expectations, or worse, exposing sensitive directories like /app and /config if you aren't careful about how you structured the upload.

The Correct Deployment Structure

Laravel is built on a specific entry point model. The file public/index.php is the sole gateway to your application. It handles bootstrapping the framework, loading the service container, and routing incoming HTTP requests. This means that the public/ directory within your Laravel project must sit exactly where the web server expects your root documents to be.

For a standard cPanel setup, this implies one of two scenarios:

  1. Your Document Root is public_html: In this case, you must move the contents of your Laravel public/ directory into public_html. You do not upload app, routes, or vendor to public_html. Instead, those directories remain nested inside your public_html folder (e.g., public_html/app, public_html/vendor).
  2. Your Document Root is the Laravel Root: Some developers prefer to keep the entire Laravel project in public_html but configure cPanel to serve from the public/ subdirectory. However, standard cPanel installations often default the document root to the folder itself, making the first option the safer bet unless you explicitly change the "Document Root" setting in cPanel to point to public_html/public.

If you upload everything to public_html without adjusting the entry point, your composer.json autoload files might not be loaded correctly because the autoloader is generated relative to the project root, which would now be outside the served directory if you only moved public/.

Handling Dependencies and Composer

One of the biggest pitfalls in this specific deployment scenario is managing dependencies. Laravel relies on Composer to autoload classes defined in app, routes, and config. If you simply upload the zip or git clone of your project into public_html without ensuring vendor exists, PHP will throw a fatal error trying to resolve dependencies.

Since cPanel's public_html often has restricted write permissions for standard users (read-only on many shared hosting plans), running composer install directly in that directory can be impossible. You generally have two paths forward:

  • Upload Vendor Separately: If you have control over the server, download the vendor folder into your local machine, upload it alongside your project files to public_html, and ensure the file permissions are correct (usually 755 for folders and 644 for files).
  • Use Softaculous or Custom Scripts: As noted in many server structures like the one described (/softaculous), cPanel hosts often include tools to handle this. If you are using Softaculous, it may offer a specific installation wizard that handles the directory structure automatically, placing your Laravel app in a subdirectory of public_html rather than replacing its contents entirely.

Security Implications of Directory Structure

A critical aspect of hosting Laravel on cPanel is preventing directory listing and ensuring sensitive files aren't served directly. When you deploy to public_html, ensure that the storage/ and resources/ directories are not symlinked or copied into public_html. By default, these should be accessed via a public link created by running:

php artisan storage:link

This command creates a symbolic link from public/storage to the actual storage directory. If you have uploaded your entire project structure to public_html, ensure this link exists. Failing to do so results in 403 Forbidden errors when trying to access assets like images or logs, as PHP cannot traverse the symlink if the permissions on the target storage folder are too restrictive.

Finalizing the Setup

Before considering your deployment successful, verify that your application's root is accessible at the correct URL. If you uploaded only the public/ contents to public_html, your application should be reachable at the base domain. If you uploaded the entire project structure to public_html without changing cPanel's document root settings, you may find that your index.php is not being recognized as the entry point, leading to a "Directory does not exist" error or a blank page.

For more complex hosting environments where standard cPanel configurations feel restrictive, platforms like LaravelCompany offer managed solutions specifically designed to simplify these directory mappings and dependency management tasks, ensuring your application runs without the friction of manual file manipulation.

Our network