I have Laravel project with node_modules folder. How can I deploy this project on cpanel. Please guide me.
Current Laravel folder structure:
app
resources
bootstrap
....
....
node_modules
.env
I am beginner to Laravel. Before, I have deployed Laravel projects without node_modules. But now I have node_modules folder in project. Guide me to deploy. Is there need make build like 'Angular' or what. Please help.
Deploying a Laravel project that includes a node_modules folder generally indicates that your project is using Node.js dependencies, probably for front-end assets managed by tools like Laravel Mix. Here's a basic guide to deploy your Laravel project with node_modules:
Before deploying, you should ensure that everything works on your local machine. Typically, you would run:
npm install
npm run prod
This installs all Node.js dependencies and compiles your assets using Laravel Mix (or another build tool specified in your package.json). The npm run prod command typically runs mix in production mode, which minimizes and optimizes your assets.
Ensure your Laravel project is ready for production:
Environment Configuration: Set your .env file for production settings, especially the database connection, app environment (APP_ENV=production), and key (APP_KEY).
Optimize: Run these Laravel commands:
php artisan config:cache
php artisan route:cache
php artisan view:cache
These commands optimize the configuration loading, routes, and views respectively.
You generally do not want to deploy the node_modules folder to your production server. This folder can be massive and is unnecessary on the server if you're pre-compiling assets locally. Make sure your deployment process excludes this folder. If you're using a .gitignore file (in case of Git-based deployment), ensure that node_modules is listed in it.
Upload your code to the server. This can be done through various methods:
Git: If your server has Git installed, you can clone the repository and then pull changes each time you deploy.
FTP/SFTP: Use a tool like FileZilla to manually upload your files to the server.
Once your code is on the server, run the following commands from your project root on the server:
1. Install Composer Dependencies:
composer install --optimize-autoloader --no-dev
2. Migrate Database:
php artisan migrate --force
3. Optimize Again (if needed):
php artisan optimize
Step 6: Handling Static Assets If you pre-compiled your assets (CSS/JS) using Laravel Mix or another tool:
By following these steps, you should be able to deploy your Laravel project with front-end dependencies managed by Node.js efficiently and securely.