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
- Log in to cPanel.
- Go to Domains > Click on Subdomains.
- Enter your desired subdomain name (e.g.,
app.yourdomain.com). - Set the Document Root to
app.yourdomain.com/public. - Click Create.
Step 2: Upload Laravel Project
Option 1: Using File Manager
- Open File Manager in cPanel.
- Navigate to the root directory of your subdomain (e.g.,
app.yourdomain.com). - Upload your Laravel project ZIP file.
- Extract the ZIP file.
Option 2: Using FTP
- Connect to your cPanel FTP using FileZilla or another FTP client.
- Upload your Laravel project to the subdomain’s root directory, e.g.,
app.yourdomain.com. - 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
- Rename
.env.exampleto.env(if not already done). - Open
.envand update the necessary details:
- Set
APP_URLto 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
- 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.