Skip to content
ISAAC NYAMARI
All insightsInfrastructure

Deploying Laravel app on shared hosting (Cpanel)

Learn the practical steps required to deploy a Laravel web application on traditional cPanel shared hosting environments.

Isaac Nyamari 3 min read

Deploying modern PHP frameworks like Laravel to traditional cPanel shared hosting environments often requires a different approach than deploying to a dedicated server or cloud platform. Because shared hosting restricts root access and relies on pre-configured server environments, developers must adjust their deployment strategy to fit the platform's constraints. Understanding these limitations and structuring your application correctly makes it possible to run Laravel smoothly on standard cPanel accounts.

Preparing Your Laravel Application Locally

Before uploading any files to the server, prepare your project locally to match the target environment. Ensure your local PHP version aligns closely with the PHP version available in your cPanel control panel. You should also run your production build commands locally if your setup uses frontend asset compilers like Vite or Laravel Mix, as shared hosting environments often lack the necessary Node.js runtimes to build assets on the server.

Review your environment configuration requirements. While you will generate a new .env file directly on the server, having a clean template of your required environment variables streamlines the final configuration step. Double-check that your application relies on standard PHP extensions that are commonly enabled by default in cPanel hosting plans.

Structuring Files for the cPanel Directory Layout

The default Laravel directory structure places the public web root inside a folder named public. However, most cPanel shared hosting accounts serve websites from a directory named public_html. To secure your application and make it work with this layout, you need to adjust where your files live.

  • Create a dedicated folder outside of public_html for your core Laravel application files.

  • Move the contents of the local public folder into the public_html directory on your server.

  • Open the transferred index.php file inside public_html and update the relative paths to point to your core application directory.

Configuring the Database and Environment

Most cPanel hosts provide MySQL or MariaDB databases through a straightforward management interface. Log into your control panel, create a new database, generate a secure database user, and assign that user full privileges to the database. Note these credentials carefully as you will need them shortly.

Next, upload your production .env file to the root of your core application folder. Update the database connection variables with the exact database name, username, and password you just created. Ensure that the APP_ENV variable is set to production and APP_DEBUG is set to false for security reasons.

Handling Dependencies and Permissions

Depending on your hosting provider, you may have access to SSH or a terminal interface within cPanel. If terminal access is available, running composer install --no-dev is the most reliable way to install your vendor dependencies. If terminal access is restricted, you can install dependencies locally and upload the entire vendor folder via FTP or the cPanel File Manager.

File permissions are a frequent source of errors on shared hosting. The storage folder and the bootstrap/cache directory must be writable by the web server. Use the File Manager or an FTP client to ensure these specific directories grant the correct write permissions.

Finalizing and Testing the Deployment

With your files in place and your environment configured, run through a final checklist to verify the application loads correctly. Clear any lingering configuration or route caches if you have terminal access. Visit your domain name in a web browser to test the homepage, authentication routes, and database connectivity. Addressing any error messages quickly ensures a stable and secure production launch.

While shared hosting introduces specific structural constraints for modern frameworks, careful file organization and proper environment configuration allow you to deploy Laravel applications successfully using standard cPanel tools.