-
-
Save abid-1988/24d48c1c422568a30be44a2d204ab5fa to your computer and use it in GitHub Desktop.
How to run PM2 with laravel queue and laravel echo server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Node Js | |
| curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash - | |
| sudo yum install nodejs | |
| node --version | |
| npm --version | |
| # Redis | |
| sudo yum install epel-release | |
| sudo yum install redis -y | |
| sudo systemctl start redis.service | |
| sudo systemctl enable redis | |
| sudo systemctl status redis.service | |
| redis-cli ping |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| BROADCAST_DRIVER=redis | |
| QUEUE_CONNECTION=redis |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // laravel-echo-server init | |
| { | |
| "authHost": "https://your-domain.com", | |
| "authEndpoint": "/broadcasting/auth", | |
| "clients": [ | |
| { | |
| "appId": "bac3036615df07cf", | |
| "key": "15fdd7bdd669b966a11f1a9bb6409595" | |
| } | |
| ], | |
| "database": "redis", | |
| "databaseConfig": { | |
| "redis": {}, | |
| "sqlite": { | |
| "databasePath": "/database/laravel-echo-server.sqlite" | |
| } | |
| }, | |
| "devMode": true, | |
| "host": "your-domain.com", | |
| "port": "6001", | |
| "protocol": "https", | |
| "socketio": {}, | |
| "secureOptions": 67108864, | |
| "sslCertPath": "/home/CPANEL USER NAME/ssl/certs/domain_cert", | |
| "sslKeyPath": "/home/CPANEL USER NAME/ssl/keys/domain key", // it will be hashed file name try all fiels if you can | |
| "sslCertChainPath": "", | |
| "sslPassphrase": "", | |
| "subscribers": { | |
| "http": true, | |
| "redis": true | |
| }, | |
| "apiOriginAllow": { | |
| "allowCors": true, | |
| "allowOrigin": "https://your-domain.com", | |
| "allowMethods": "GET, POST", | |
| "allowHeaders": "Origin, Content-Type, X-Auth-Token, X-Requested-With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-Id" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = { | |
| apps: [ | |
| { | |
| name: 'laravel-echo-server', | |
| script: 'laravel-echo-server', | |
| instances : 1, // default 'laravel-echo-server' required 1 instance only to work | |
| exec_mode : 'fork', // default | |
| interpreter: 'node', // default | |
| args: 'start', | |
| error_file: './storage/logs/pm2/pm2.error.log', | |
| out_file: './storage/logs/pm2/pm2.out.log', | |
| pid_file: './storage/logs/pm2/pm2.pid.log', | |
| cwd: "/home/CPANEL USER NAME/www", | |
| }, | |
| { | |
| name: 'laravel-queue-worker', | |
| script: 'artisan', | |
| exec_mode: 'fork', // default | |
| interpreter: 'php', | |
| instances: 1, | |
| args: 'queue:work --tries=5 --sleep=1', | |
| error_file: './storage/logs/pm2/pm2.error.log', | |
| out_file: './storage/logs/pm2/pm2.out.log', | |
| pid_file: './storage/logs/pm2/pm2.pid.log', | |
| cwd: "/home/CPANEL USER NAME/www", | |
| }, | |
| ] | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # You Must Be Root | |
| sudo npm install -g pm2 | |
| # Register pm2 to startup | |
| # Run without sudo it will generate a command just copy/past the generated command | |
| pm2 startup | |
| # unRegister pm2 to startup | |
| # Run without sudo it will generate a command just copy/past the generated command | |
| pm2 unstartup | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # All Command are on CentOs7 | |
| # Allow port 6001 in firewall for using it in laravel echo server | |
| sudo firewall-cmd --zone=public --add-port=6001/tcp --permanent | |
| # Reload Firewall | |
| sudo firewall-cmd --reload | |
| # Check for port | |
| sudo iptables-save | grep 6001 | |
| # -A IN_public_allow -p tcp -m tcp --dport 6001 -m conntrack --ctstate NEW,UNTRACKED -j ACCEPT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Method 1: Start PM2 as normal user (not server user but host or cpanel normal user) | |
| # Add your host or cpanel user to "wheel" group to use "su" command | |
| usermod -G wheel your_user_name | |
| # Remomber now your user can use "su" command but it will required "root" user passowrd keep in mind | |
| # By allowing your user to use "su" now pm2 will work correctlly and yu don't need to use "su" with it | |
| # Go to your app root path and Start PM2 and Provide Path to pm2.config.js (autocomplete paths in terminal may not work) | |
| pm2 start pm2.config.js | |
| # Stop PM2 and Provide Path to pm2.config.js (autocomplete paths in terminal may not work) | |
| pm2 stop pm2.config.js | |
| # Restart PM2 and Provide Path to pm2.config.js (autocomplete paths in terminal may not work) | |
| pm2 restart pm2.config.js | |
| # Log All pm2 Apps | |
| pm2 logs | |
| # Log specific pm2 app | |
| # sudo pm2 logs [app name] | |
| pm2 logs laravel-echo-server | |
| pm2 logs laravel-queue-worker | |
| #---------------------------------------#---------------------------------------#--------------------------------------- | |
| # Method 2: Start PM2 as Root (server user not host or cpanel normal user) or it will not work | |
| # Start PM2 and Provide Path to pm2.config.js (autocomplete paths in terminal may not work) | |
| sudo pm2 start "/home/CPANEL USER NAME/www/pm2.config.js" | |
| # Stop PM2 and Provide Path to pm2.config.js (autocomplete paths in terminal may not work) | |
| sudo pm2 stop "/home/CPANEL USER NAME/www/pm2.config.js" | |
| # Restart PM2 and Provide Path to pm2.config.js (autocomplete paths in terminal may not work) | |
| sudo pm2 restart "/home/CPANEL USER NAME/www/pm2.config.js" | |
| # Log All pm2 Apps | |
| sudo pm2 logs | |
| # Log specific pm2 app | |
| # sudo pm2 logs [app name] | |
| sudo pm2 logs laravel-echo-server | |
| sudo pm2 logs laravel-queue-worker |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment