Skip to content

Laravel Manual Deployment Guide πŸš€ ​

Before we dive into the deployment process, make sure to follow the official Laravel Deployment Documentation for best practices.

Step 1: Creating a Production Build πŸ› οΈ ​

If you're planning to deploy Jetship in a subfolder, you'll need to specify the ASSET_URL in your .env file. This step is optional, but it helps ensure that your assets are correctly referenced.

bash
ASSET_URL=https://your-domain/subfolder/public

Now, let's generate the production build by running one of the following commands, depending on your package manager:

bash
# If using pnpm:
pnpm run build

# If using npm:
npm run build

# If using yarn:
yarn build

✨ Success! Your production build files have been generated.

Step 2: Adjusting the File Structure πŸ”§ ​

For security reasons, it's a good practice to separate the Laravel core files from the publicly accessible files. In this example, we will separate the Laravel and public folders and update the resource paths in public/index.php.

Folder Structure Example ​

txt
β”œβ”€β”€ public_html (publicly accessible folder)
β”‚   β”œβ”€β”€ build
β”‚   β”‚   β”œβ”€β”€ assets
β”‚   β”‚   └── mix-manifest.json
β”‚   β”œβ”€β”€ .htaccess
β”‚   β”œβ”€β”€ favicon.ico
β”‚   β”œβ”€β”€ index.php
β”‚   β”œβ”€β”€ logo.png
β”‚   β”œβ”€β”€ robots.txt
β”œβ”€β”€ laravel  (Laravel core files)
β”‚   β”œβ”€β”€ app                      
β”‚   β”œβ”€β”€ bootstrap                
β”‚   β”œβ”€β”€ config                   
β”‚   β”œβ”€β”€ database                                 
β”‚   β”œβ”€β”€ resources                            
β”‚   β”œβ”€β”€ routes/                  
β”‚   β”œβ”€β”€ storage/                 
β”‚   β”œβ”€β”€ tests/                   
β”‚   β”œβ”€β”€ .editorconfig            
β”‚   β”œβ”€β”€ .env.example             
β”‚   β”œβ”€β”€ .gitattributes           
β”‚   β”œβ”€β”€ .gitignore               
β”‚   β”œβ”€β”€ artisan                  
β”‚   β”œβ”€β”€ composer.json            
β”‚   β”œβ”€β”€ package.json             
β”‚   └── vite.config.ts

Updating index.php Paths ​

You’ll need to update some paths in the public/index.php file to reflect this folder structure. Additionally, ensure the server's document root points to the public_html folder (where index.php is located).

Here’s an example of the updated index.php:

php
<?php

use Illuminate\Http\Request;

define('LARAVEL_START', microtime(true));

// Handle maintenance mode...
if (file_exists($maintenance = __DIR__.'/../laravel/storage/framework/maintenance.php')) {
    require $maintenance;
}

// Load Composer autoloader...
require __DIR__.'/../laravel/vendor/autoload.php';

// Bootstrap Laravel and handle the request...
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
app()->usePublicPath(__DIR__);
$app->handleRequest(Request::capture());

πŸ’‘ Tip: The public_html folder name may vary depending on your server’s configuration.

Step 3: Application Setup πŸ› οΈ ​

  • Database & Mail Setup
    Make sure to properly configure your database, mail, and other required settings in your .env file before deploying your application.

Step 4: Redis for Performance πŸš€ ​

For enhanced performance, we highly recommend using Redis for fast caching and queue management. Check out our comprehensive guide on How to Use Redis to get started.

Step 5: Setting File Permissions πŸ”’ ​

If you encounter permission issues during or after deployment, you can resolve them by setting the correct permissions on your storage and bootstrap/cache directories. Run the following commands:

sh
sudo chmod -R o+rw bootstrap/cache
sudo chmod -R o+rw storage

This ensures your web server has the necessary access to these critical folders.

Conclusion✨ ​

That’s it! You’ve successfully deployed your Laravel application. πŸŽ‰

  • Remember to adapt the paths and folder names according to your server setup.
  • Review your server’s document root configuration to ensure it points to the correct public_html directory.

Congratulations on your deployment! πŸŽ‰ Your Laravel app is now live and ready to rock!