Skip to content

Instantly share code, notes, and snippets.

@lioneltchami
Created November 7, 2024 07:15
Show Gist options
  • Select an option

  • Save lioneltchami/3768d15248457cb80908ead56b9756b9 to your computer and use it in GitHub Desktop.

Select an option

Save lioneltchami/3768d15248457cb80908ead56b9756b9 to your computer and use it in GitHub Desktop.

Here's a step-by-step guide I would suggest to help you approach the deployment process:

Prerequisites

Before deploying, ensure the following:

  1. A production server with sufficient resources
  2. PHP installed (compatible with Laravel 11)
  3. Composer installed
  4. Node.js and npm installed
  5. MySQL installed
  6. Web server (Nginx or Apache) installed
  7. SSL certificate for HTTPS (recommended)

Deployment Process

Backend (Laravel) Deployment

  1. Prepare the Laravel application:

    • Update .env file with production settings
    • Run composer install --no-dev to install dependencies
    • Generate application key: php artisan key:generate
    • Optimize the application: php artisan optimize
  2. Database setup:

    • Create a production database
    • Update database credentials in .env
    • Run migrations: php artisan migrate
  3. File permissions:

    • Set proper permissions for storage and bootstrap/cache directories
  4. Web server configuration:

    • Configure Nginx or Apache to point to the public directory of your Laravel application
    • Ensure all requests are directed to public/index.php
  5. Caching configuration:

    • Run php artisan config:cache to cache configuration files

Frontend (Angular) Deployment

  1. Build the Angular application:

    • Update environment files with production API endpoints
    • Run ng build --configuration production to create a production build
    • The built files will be in the dist/ directory
  2. Deploy Angular files:

    • Copy the contents of the dist/ directory to your web server's public directory
  3. Configure web server:

    • Set up Nginx or Apache to serve the Angular files
    • Configure to redirect all requests to index.html for client-side routing

Final Steps

  1. SSL Configuration:

    • Install and configure SSL certificate for HTTPS
  2. Environment Variables:

    • Ensure all necessary environment variables are set on the production server
  3. Testing:

    • Thoroughly test the application in the production environment

Deployment Approach

Given your setup, here's a recommended approach:

  1. Separate Servers: Ideally, deploy your Angular frontend and Laravel backend on separate servers or subdomains. This allows for better scalability and maintenance.

  2. API Configuration: Ensure your Angular application is configured to make API calls to the correct Laravel backend URL.

  3. Database: Set up the MySQL database on a separate server or the same server as the Laravel backend, depending on your architecture.

  4. Web Server: Use Nginx as a reverse proxy to route requests to either the Angular frontend or Laravel backend based on the URL.

  5. Deployment Order:

    • Deploy the Laravel backend first
    • Set up the database
    • Deploy the Angular frontend
    • Configure the web server

Documentation and Resources

  1. Laravel Deployment Documentation: https://laravel.com/docs/11.x/deployment
  2. Angular Deployment Guide: https://angular.dev/tools/cli/deployment
  3. Laravel Forge (if you decide to use a managed solution): https://forge.laravel.com/

Remember to always backup your data before deployment and have a rollback plan in case of issues. It's also recommended to test the deployment process on a staging environment that mirrors your production setup before going live.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment