Here's a step-by-step guide I would suggest to help you approach the deployment process:
Before deploying, ensure the following:
- A production server with sufficient resources
- PHP installed (compatible with Laravel 11)
- Composer installed
- Node.js and npm installed
- MySQL installed
- Web server (Nginx or Apache) installed
- SSL certificate for HTTPS (recommended)
-
Prepare the Laravel application:
- Update
.envfile with production settings - Run
composer install --no-devto install dependencies - Generate application key:
php artisan key:generate - Optimize the application:
php artisan optimize
- Update
-
Database setup:
- Create a production database
- Update database credentials in
.env - Run migrations:
php artisan migrate
-
File permissions:
- Set proper permissions for
storageandbootstrap/cachedirectories
- Set proper permissions for
-
Web server configuration:
- Configure Nginx or Apache to point to the
publicdirectory of your Laravel application - Ensure all requests are directed to
public/index.php
- Configure Nginx or Apache to point to the
-
Caching configuration:
- Run
php artisan config:cacheto cache configuration files
- Run
-
Build the Angular application:
- Update environment files with production API endpoints
- Run
ng build --configuration productionto create a production build - The built files will be in the
dist/directory
-
Deploy Angular files:
- Copy the contents of the
dist/directory to your web server's public directory
- Copy the contents of the
-
Configure web server:
- Set up Nginx or Apache to serve the Angular files
- Configure to redirect all requests to
index.htmlfor client-side routing
-
SSL Configuration:
- Install and configure SSL certificate for HTTPS
-
Environment Variables:
- Ensure all necessary environment variables are set on the production server
-
Testing:
- Thoroughly test the application in the production environment
Given your setup, here's a recommended approach:
-
Separate Servers: Ideally, deploy your Angular frontend and Laravel backend on separate servers or subdomains. This allows for better scalability and maintenance.
-
API Configuration: Ensure your Angular application is configured to make API calls to the correct Laravel backend URL.
-
Database: Set up the MySQL database on a separate server or the same server as the Laravel backend, depending on your architecture.
-
Web Server: Use Nginx as a reverse proxy to route requests to either the Angular frontend or Laravel backend based on the URL.
-
Deployment Order:
- Deploy the Laravel backend first
- Set up the database
- Deploy the Angular frontend
- Configure the web server
- Laravel Deployment Documentation: https://laravel.com/docs/11.x/deployment
- Angular Deployment Guide: https://angular.dev/tools/cli/deployment
- 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.