Lädt...


🔧 How to deploying Laravel projects on a live server – Complete Step-by-Step Guide


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

Learn How to deploying Laravel projects on a live server with this comprehensive guide. Step-by-step instructions on setting up hosting, configuring files, and deploying your Laravel app smoothly.Read Laravel Docs

1. Purchase Domain and Hosting

Make sure you have a domain and a hosting plan. Most shared hosting plans (like cPanel-based ones) or a VPS will work for Laravel, but ensure your server supports PHP and MySQL and meets Laravel’s requirements (PHP version, required extensions, etc.).

2. Prepare Your Laravel Project

Make sure your Laravel project is working locally.
Run the following command to clear any cached configuration and to optimize the project:

php artisan cache:clear 

php artisan config:clear 

php artisan route:clear 

php artisan view:clear

Set up your environment variables (.env file). Make sure they are correctly configured for the live server (e.g., database, mail, and app URL settings).

3. Zip and Upload Your Laravel Project

Compress your entire Laravel project folder (without the node_modules and vendor directories) into a .zip file.
Use FTP (with FileZilla or any other FTP client) or File Manager in cPanel to upload the .zip file to your server. Typically, upload the file to the public_html or a subdirectory within it if you want to run your Laravel app in a subdirectory.

4. Extract the Files

Once uploaded, use File Manager in your hosting control panel to extract the .zip file.

5. Set Up the Public Directory

By default, Laravel’s entry point is the public folder, which contains the index.php file. On a shared hosting server:

Move everything in the public folder (including the .htaccess and index.php files) to the root directory (usually public_html).
Edit the index.php file to update the paths:
Change:

require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';

To:

require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';

This ensures that Laravel can find the necessary files in the correct directory.

6. Set File Permissions

Ensure that the following directories are writable by the server:

  • /storage
  • /bootstrap/cache Use the following command via SSH (if available) or through the hosting file manager:
chmod -R 775 storage
chmod -R 775 bootstrap/cache

7. Set Up a Database

Create a MySQL database and a user with privileges in cPanel (or via SSH if using VPS).
Update the .env file with your database credentials:

DB_HOST=localhost
DB_DATABASE=your_database_name
DB_USERNAME=your_database_username
DB_PASSWORD=your_database_password

8. Install Composer Dependencies

If you have SSH access:

SSH into your server using a terminal or a tool like PuTTY.
Navigate to your project directory

cd /path/to/your/project

Run Composer to install the dependencies:

composer install --optimize-autoloader --no-dev

If you don’t have SSH access, you can run composer install locally, zip the vendor folder, and upload it to the server.

9. Run Migrations

If you have SSH access, run the following command to migrate the database:

php artisan migrate --force

If you don’t have SSH access, you can run the migrations locally and then export/import the database to the server via phpMyAdmin.

10. Set App Key

Generate a new application key if you haven’t already:

php artisan key:generate
Ensure the key is set in the .env file:

APP_KEY=base64:your_key_here

11. Configure .env for Production

Set the environment to production:

APP_ENV=production
APP_DEBUG=false

12. Point Your Domain to the Laravel Project

If your Laravel project is inside the public_html folder, it will automatically load when someone visits your domain. If it’s inside a subdirectory, point the domain or subdomain to the correct folder.

13. Enable Pretty URLs (Remove /public from the URL)

You might need to edit the .htaccess file in the root directory:

Add the following to your .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]

14. Test Your Application

Visit your domain or subdomain to ensure the Laravel app is working properly. Check for any errors and fix any configuration issues.

15. Optional: Use SSH or Git for Deployment

If your hosting supports Git, you can set up deployment using a repository, which makes it easier to push updates to the live server.

You Can Learn Laravel 11: How to Generate PDF and Send Emails – Step-by-Step Tutorial

...

🔧 [Laravel v11 x Docker] Efficiently Set Up a Laravel App Dev Environment with Laravel Sail


📈 29.98 Punkte
🔧 Programmierung

🔧 3 Steps to Speed Up Laravel Projects with Laravel Shift Blueprint


📈 28.41 Punkte
🔧 Programmierung

🔧 Deploying a (Static) Vite React App: A Complete Guide


📈 24.85 Punkte
🔧 Programmierung

🔧 Deploying a Complete 3-Tier Application with Jenkins: A Comprehensive Guide


📈 24.85 Punkte
🔧 Programmierung

🔧 Deploying a Vite/React Application with Images: A Complete Guide


📈 24.85 Punkte
🔧 Programmierung

🔧 Self-Hosting Umami Analytics: A Complete Guide to Deploying with Vercel and Supabase for Free


📈 24.85 Punkte
🔧 Programmierung

🔧 Deploying an Application on Kubernetes: A Complete Guide!


📈 24.85 Punkte
🔧 Programmierung

🔧 A guide to feature flags in Laravel using Laravel Pennant


📈 24.7 Punkte
🔧 Programmierung

🔧 Deploying Laravel App to Ubuntu Server Via SSH


📈 24.19 Punkte
🔧 Programmierung

🔧 Laravel 11 Image Validation Rules – Complete Example and Guide


📈 23.57 Punkte
🔧 Programmierung

🔧 Building a RESTful API with Laravel 11, A Complete Guide


📈 23.57 Punkte
🔧 Programmierung

🔧 Laravel SPA: A Complete Guide to Building Single Page Applications


📈 23.57 Punkte
🔧 Programmierung

🔧 Mailpit and Laravel Integration: A Complete Guide for Local Email Testing


📈 23.57 Punkte
🔧 Programmierung

🔧 Laravel Reverb: Fitur Websocket Server pada Laravel 11


📈 22.92 Punkte
🔧 Programmierung

🔧 Using a Public Repository on GitHub for Personal Projects: A Complete Guide


📈 22 Punkte
🔧 Programmierung

🔧 Mastering YOLOv10: A Complete Guide with Hands-On Projects


📈 22 Punkte
🔧 Programmierung

🔧 Deploying a Breeze Laravel app on Render - part 2


📈 21.26 Punkte
🔧 Programmierung

🔧 Deploying a Breeze Laravel app on Render - part 1


📈 21.26 Punkte
🔧 Programmierung

🔧 Deploying Laravel on Lamp Stack with Linux(Ubuntu)


📈 21.26 Punkte
🔧 Programmierung

🔧 Deploying Laravel 11 with Reverb Websocket Support


📈 21.26 Punkte
🔧 Programmierung

🔧 Deploying Laravel applications on Vercel


📈 21.26 Punkte
🔧 Programmierung

🔧 Deploying a Laravel App on AWS App Runner


📈 21.26 Punkte
🔧 Programmierung

🔧 Deploying a Complete Machine Learning Fraud Detection Solution Using Amazon SageMaker : AWS Project


📈 20.13 Punkte
🔧 Programmierung

🔧 Deploying a Complete ASP.NET Framework Web Application on Amazon EC2


📈 20.13 Punkte
🔧 Programmierung

🔧 Deploying a Complete ASP.NET Framework Web Application on Amazon EKS


📈 20.13 Punkte
🔧 Programmierung

🔧 Deploying a complete machine learning fraud detection solution using Amazon SageMaker


📈 20.13 Punkte
🔧 Programmierung

🔧 Introducing Laravel Nightwatch: A New Age of Monitoring Your Laravel Apps ✨


📈 19.99 Punkte
🔧 Programmierung

🕵️ CVE-2024-29291 | Laravel Framework 8/9/10/11 storage/logs/laravel.log information disclosure


📈 19.99 Punkte
🕵️ Sicherheitslücken

🔧 Laravel Mix vs Vite: Why did Laravel Transitioned to Vite


📈 19.99 Punkte
🔧 Programmierung

🔧 Laravel-10 Laravel-11 comparison, changes


📈 19.99 Punkte
🔧 Programmierung

🔧 Laravel Nightwatch: The Future of Laravel Application Monitoring Revealed at Laracon AU


📈 19.99 Punkte
🔧 Programmierung

🔧 Laravel: Pengenalan Fitur Reverb Di Laravel


📈 19.99 Punkte
🔧 Programmierung

matomo