Appearance
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!