Uploading a Laravel project to a live server is an important step when making your website accessible to users over the internet. However, many beginners face a common problem: they upload their Laravel project files to the hosting server, but the website still does not work.
You may see a 403 Forbidden error, a 404 Not Found page, a blank screen, an Internal Server Error, or even a directory listing instead of your website.
One common reason is that Laravel's entry point is located inside the public directory, while many hosting configurations expect the website's document root to point to the correct folder. In some cases, the .htaccess file is also missing or incorrectly configured.
In this guide, you will learn how to upload a Laravel project to a live server, configure .htaccess, connect your database, and troubleshoot common deployment problems.
Table of Contents
- Requirements Before Uploading a Laravel Project
- Why Does a Laravel Project Not Go Live After Uploading?
- How to Upload Laravel Files to a Live Server
- How to Configure the Laravel Public Directory
- How to Create and Configure the .htaccess File
- How to Configure the .env File
- How to Connect the Live Database
- Common Laravel Deployment Errors and Their Solutions
- Important Security Tips
- Conclusion
1. Requirements Before Uploading a Laravel Project
Before deploying your Laravel application, make sure your hosting server supports the requirements of your Laravel version.
You will generally need:
- A domain name connected to your hosting account.
- Web hosting with PHP and MySQL or MariaDB support, if your application uses a database.
- A PHP version compatible with your Laravel version.
- Required PHP extensions.
- Composer dependencies installed or a way to install them on the server.
- Access to cPanel, FTP, SSH, or your hosting file manager.
- Database credentials and a database backup, if required.
Important: Requirements vary between Laravel versions and hosting providers. Check the official Laravel deployment documentation for the exact requirements of your application.
2. Why Does a Laravel Project Not Go Live After Uploading?
A Laravel application is different from a basic HTML website.
A typical Laravel project contains directories and files such as:
my-laravel-project/
├── app/
├── bootstrap/
├── config/
├── database/
├── public/
│ ├── index.php
│ └── .htaccess
├── resources/
├── routes/
├── storage/
├── vendor/
├── .env
├── artisan
└── composer.json
The public directory contains the main entry point of the application, index.php. Requests to the Laravel website should normally be handled through this entry point.
If you upload the complete project to a folder that is not configured as the website's document root, the server may not find the correct entry point.
Other possible reasons include:
- The .htaccess file is missing.
- Apache's rewrite module is unavailable or disabled.
- The domain points to the wrong directory.
- The vendor directory or Composer dependencies are missing.
- The .env file contains incorrect production settings.
- The storage or bootstrap/cache directories are not writable.
- The PHP version is incompatible with your project.
Therefore, uploading files alone does not guarantee that a Laravel application will work correctly.
3. How to Upload a Laravel Project to a Live Server
Follow these steps to deploy your Laravel application.
Step 1: Prepare Your Laravel Project
Before uploading your project, test it locally and make sure it works correctly.
Check your application configuration, routes, database connection, and required dependencies.
If you have SSH or terminal access, install the production dependencies with:
composer install --no-dev --optimize-autoloader
Run this command in your project's root directory. If your hosting server does not provide Composer, you can prepare the required dependencies locally, provided your local environment is compatible with the production server.
Do not upload development-only files or secrets unnecessarily.
Step 2: Compress Your Project Files
Create a ZIP archive of your Laravel project.
For example:
my-laravel-project.zip
Upload the ZIP file through cPanel File Manager, FTP, or another supported file transfer method.
Step 3: Upload the Project to Your Hosting Account
For a safer deployment, keep the Laravel application files outside the publicly accessible web directory whenever your hosting plan allows it.
For example:
/home/username/
├── laravel-app/
│ ├── app/
│ ├── bootstrap/
│ ├── config/
│ ├── resources/
│ ├── routes/
│ ├── storage/
│ ├── vendor/
│ ├── .env
│ └── artisan
└── public_html/
├── index.php
├── .htaccess
└── build/
Here, laravel-app contains the Laravel application, while public_html contains only the files that should be publicly accessible.
Your actual paths may differ depending on your hosting provider.
Security warning: Never expose .env, vendor, storage, composer.json, or other application internals through a publicly accessible directory.
Step 4: Configure the Public Entry Point
If your domain uses public_html as its document root, you have two main options:
Option A: Set the domain document root to Laravel's public directory
If your hosting provider allows you to change the document root, point the domain to the Laravel project's public directory.
For example:
/home/username/laravel-app/public
This is generally the preferred approach because Laravel's public directory is designed to be the web-accessible entry point.
Option B: Use public_html as the document root
If your hosting provider does not allow you to change the document root, keep the application outside public_html and place the necessary public files inside public_html.
You must then update the paths in index.php to point to the real Laravel application directory.
For example, if your structure is:
/home/username/laravel-app/ /home/username/public_html/
The index.php file in public_html may need paths similar to these:
require __DIR__.'/../laravel-app/vendor/autoload.php'; $app = require_once __DIR__.'/../laravel-app/bootstrap/app.php';
Use the actual absolute or relative paths from your hosting account. Do not copy these paths without verifying your directory structure.
You should also copy the appropriate public assets and configuration files from Laravel's public directory.
4. How to Configure the Laravel Public Directory
The Laravel public directory is important because it contains the front controller and public assets.
A typical public directory includes:
public/
├── index.php
├── .htaccess
├── favicon.ico
├── robots.txt
└── build/
The index.php file bootstraps the Laravel application. The .htaccess file helps Apache handle incoming requests correctly.
If your domain points to the wrong directory, Laravel may not load even when all project files have been uploaded correctly.
Before changing files, verify your hosting document root and the paths used in index.php.
5. How to Create and Configure the .htaccess File
One of the most common Laravel deployment problems occurs when the .htaccess file is missing or its rewrite rules are not working.
The .htaccess file is an Apache web server configuration file. It can define rules for handling URLs, redirects, access restrictions, and other settings permitted by the server.
Laravel's default public .htaccess file includes rewrite rules that direct requests to index.php, allowing Laravel routes such as /login, /register, and /dashboard to work without putting index.php in every URL.
Where Should You Put the .htaccess File?
If your domain points directly to Laravel's public directory, the file should normally be located here:
laravel-app/public/.htaccess
If you are using public_html as the document root, place the appropriate .htaccess file in:
public_html/.htaccess
The exact location depends on how your application is deployed.
Laravel .htaccess Code
For an Apache server, you can use the following standard rewrite configuration as a starting point:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
This configuration helps Apache route requests to Laravel's index.php when the requested path is not an existing file or directory.
For most Laravel applications using Apache, this is a useful starting point. Prefer the .htaccess file supplied with your installed Laravel version when available.
Important: These rules do not replace the need to configure the correct document root, install dependencies, or set up the Laravel environment.
How to Create the .htaccess File in cPanel
- Log in to your hosting account.
- Open cPanel → File Manager.
- Navigate to the correct public directory, such as public_html.
- Enable Show Hidden Files (dotfiles) in File Manager settings, if necessary.
- Check whether .htaccess already exists.
- If it does not exist, create a new file named .htaccess.
- Paste the appropriate rewrite rules into the file.
- Save the changes.
- Open your website and test both the homepage and a Laravel route.
Do not create multiple conflicting rewrite rules without understanding their effect. If the file already contains rules for HTTPS redirects, caching, or other applications, review them before replacing anything.
What If .htaccess Still Does Not Work?
Check the following:
- Confirm that the server is running Apache or an Apache-compatible server.
- Confirm that mod_rewrite is enabled.
- Ensure the server permits rewrite directives through its AllowOverride configuration.
- Verify that the domain points to the correct public directory.
- Check whether the hosting provider uses Nginx, which does not read .htaccess files.
- Review the server's error logs for configuration errors.
If your server uses Nginx, you need appropriate Nginx configuration instead of .htaccess.
6. How to Configure the .env File
The .env file stores environment-specific configuration for your Laravel application.
On the live server, check settings such as:
APP_NAME="My Laravel Website" APP_ENV=production APP_DEBUG=false APP_URL=https://example.com
Replace example.com with your actual domain.
For a database-backed application, configure the correct database connection:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database
DB_USERNAME=your_database_user
DB_PASSWORD="your_database_password"
Use the database host and credentials supplied by your hosting provider. Shared hosting may use a different database host.
Never share your production .env file publicly or commit its real secrets to a public GitHub repository.
If configuration is cached, refresh it after making changes. On a server with terminal access, you can generally run:
php artisan config:clear php artisan config:cache
Run Artisan commands from the Laravel project root.
7. How to Connect the Live Database
If your application uses MySQL, create a database and database user through your hosting control panel.
Then:
- Create the database.
- Create a database user and assign the necessary privileges.
- Import your database backup, if you are moving an existing project.
- Update the database settings in .env.
- Run migrations only if appropriate for your deployment.
For example:
php artisan migrate --force
Warning: Do not run migrations blindly on a production database. Review pending migrations and take a backup first. Avoid commands that drop or reset production tables unless you explicitly intend to destroy the existing data.
Test the website after connecting the database to confirm that queries and application features work correctly.
8. Common Laravel Deployment Errors and Their Solutions
Error 1: 403 Forbidden
Possible causes:
- Incorrect document root.
- Missing index file.
- Directory access restrictions.
- Server permissions or configuration issues.
Solution: Confirm that the domain points to Laravel's public directory or the correctly configured public entry point. Review file permissions and server logs.
Error 2: 404 Not Found on Laravel Routes
The homepage may work while routes such as /login or /dashboard return a 404 error.
Possible causes:
- Missing or incorrect rewrite rules.
- Apache rewrite support is disabled.
- The domain points to the wrong directory.
Solution: Verify .htaccess, mod_rewrite, the document root, and the route definition.
Error 3: 500 Internal Server Error
Possible causes:
- Missing Composer dependencies.
- Incorrect .env values.
- Incompatible PHP version.
- Invalid .htaccess directives.
- File permission issues.
Solution: Check Laravel logs in storage/logs and the hosting server's error logs. Fix the underlying error instead of enabling debug mode on the public website.
Error 4: CSS and JavaScript Are Not Loading
Possible causes:
- Incorrect asset URLs.
- Missing compiled assets.
- Incorrect APP_URL.
- A build directory that was not uploaded.
Solution: Verify your asset paths and ensure that your production frontend assets are built and deployed. If your project uses Vite, build assets using the appropriate project build command before deployment.
Error 5: Laravel Shows a Blank Page
Possible causes:
- A PHP fatal error.
- Missing dependencies.
- A configuration issue.
- An exception that is not displayed publicly.
Solution: Inspect the Laravel and server logs. Keep APP_DEBUG=false on production and diagnose the problem using logs rather than displaying sensitive error details to visitors.
Error 6: Images Are Not Displayed
If images are stored using Laravel's public storage disk, you may need to create the storage symlink:
php artisan storage:link
Also verify the storage paths, uploaded file locations, and permissions.
Error 7: Database Connection Failed
Possible causes:
- Incorrect database name, username, or password.
- Incorrect database host.
- Missing database privileges.
- Stale configuration cache.
Solution: Verify the hosting credentials, database privileges, and Laravel configuration.
9. Important Security Tips for Laravel Deployment
Before making your Laravel website publicly available, follow these precautions:
- Set APP_ENV=production and APP_DEBUG=false.
- Keep .env and application internals outside the public web root whenever possible.
- Do not expose the complete Laravel project directory through the browser.
- Use appropriate file permissions instead of making all files and directories writable.
- Keep Laravel, Composer dependencies, PHP, and server software updated.
- Use HTTPS and verify that redirects work correctly.
- Back up your database and project before deploying updates.
- Do not upload development credentials or secret keys to public repositories.
Remember that .htaccess is not a complete security solution. Correct document-root configuration and keeping sensitive files outside the public directory are essential.
10. Conclusion
Uploading a Laravel project to a live server involves more than transferring files. You must configure the public directory, set up the .env file, connect the database, install dependencies, and ensure that the web server can route requests correctly.
The .htaccess file is particularly important for Laravel applications running on Apache because its rewrite rules allow application routes to work correctly. However, if the document root is incorrect, dependencies are missing, or the server uses Nginx, adding .htaccess alone will not solve the problem.
Follow the steps in this guide, test your website carefully, and review the server logs whenever an error occurs.
With the correct deployment configuration, you can make your Laravel project accessible to users through your live domain.
Found this guide helpful? Follow Dcode Materials for more practical tutorials on Laravel, PHP, MySQL, Git, GitHub, and live website deployment.