Laravel

How to Set Up a Laravel Project on a Subdomain in cPanel

This guide will walk you through setting up a Laravel application on a subdomain in cPanel on Ecenica web hosting. Learn how to create a subdomain, upload Laravel files, configure your environment, and get your app running smoothly. This tutorial is perfect for developers deploying Laravel projects efficiently on Ecenica hosting.

Step 1: Create a Subdomain

  1. Log in to cPanel.
  2. Go to Domains > Click on Subdomains.
  3. Enter your desired subdomain name (e.g., app.yourdomain.com).
  4. Set the Document Root to app.yourdomain.com/public.
  5. Click Create.

Step 2: Upload Laravel Project

Option 1: Using File Manager

  1. Open File Manager in cPanel.
  2. Navigate to the root directory of your subdomain (e.g., app.yourdomain.com).
  3. Upload your Laravel project ZIP file.
  4. Extract the ZIP file.

Option 2: Using FTP

  1. Connect to your cPanel FTP using FileZilla or another FTP client.
  2. Upload your Laravel project to the subdomain’s root directory, e.g., app.yourdomain.com.
  3. Extract the project files if necessary.

Step 3: Set File Permissions

Run the following command in your terminal:

chmod -R 775 storage bootstrap/cache

Step 4: Configure .env File

  1. Rename .env.example to .env (if not already done).
  2. Open .env and update the necessary details:
  • Set APP_URL to match your subdomain:

    APP_URL=https://app.yourdomain.com

  • Set database details:

    DB_DATABASE=your_database_name
    DB_USERNAME=your_database_user
    DB_PASSWORD=your_database_password

  1. Run the following command to generate the application key:
php artisan key:generate

Step 5: Set Up .htaccess File

Place this .htaccess file inside app.yourdomain.com/public/:

<IfModule mod_rewrite.c>
RewriteEngine On

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* – [E=HTTP_AUTHORIZATION:%1]

# Redirect all requests to index.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>

# Protect sensitive files
<FilesMatch "^\.">
Order allow,deny
Deny from all
</FilesMatch>

# Prevent directory listing
Options -Indexes

Step 6: Clear Laravel Cache

Run the following commands to clear the cache:

php artisan config:cache
php artisan cache:clear

Step 7: Test Your Application

Visit your subdomain (e.g., `https://app.yourdomain.com`) to test the application.

Was this guide helpful?

Need help with this?

Open a ticket and link to this guide so our team can see what you have tried.

View support tickets

Power your business with Ecenica Hosting

Built for WordPress and serious websites. Fast, secure and supported by real people in the UK.

Ecenica hosting services represented by a connected red route across London