Home Our service Dashboard
6 days ago
ارما

How to install supervisor in almalinux and configuration for jobs laravel server

در این مقاله چه میخوانیم?

If your project is built with Laravel and you use Queues, you definitely need a professional tool to manage them. One of the best tools for this is Supervisor. In this article, you will learn very simply and practically how to install Supervisor in AlmaLinux and keep Laravel jobs running all the time.

What is Supervisor and why should we install it?

Supervisor is a Linux program that helps us execute a series of commands or programs permanently and stably in the background.
For example, if this command is not executed in your project:

php artisan queue:work
 

None of the queues will be executed. No emails will be sent, no SMS messages will be sent, no scheduled tasks will be performed. In short, your project will be incomplete!
Supervisor will come and paste this command and keep it running forever.

Step by step installation of Supervisor in AlmaLinux

1. Log in to the server (via SSH)

If you have WHM or a terminal, log in to SSH with root or sudo access:


ssh your-user@your-server-ip
 

2. Install EPEL (repository required to install Supervisor)


sudo dnf install epel-release -y

3. Install Supervisor on Linux


sudo dnf install supervisor -y

4. Enable and start the Supervisor service


sudo systemctl enable supervisord
sudo systemctl start supervisord
 

Test the Supervisor installation


sudo systemctl status supervisord
 

Configure supervisord for Laravel

The Supervisor configuration files are in this path, you can edit them with the nano command.


/etc/supervisord.d/
 

Create a file specifically for the Laravel project


sudo nano /etc/supervisord.d/laravel-worker.ini
 

And write the following content in it:


[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /home/your-user/your-project/artisan queue:work --sleep=3 --tries=3 --timeout=90
autostart=true
autorestart=true
user=your-user
numprocs=1
redirect_stderr=true
stdout_logfile=/home/your-user/your-project/storage/logs/laravel-worker.log
stopwaitsecs=3600
 

 Note: Be sure to write the correct path to the project and user instead of `your-user` and `your-project`.

 

5. Reset new settings


sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start laravel-worker:

Check the status of Laravel queue execution

To see the status of the jobs:


sudo supervisorctl status
 

If everything is OK, you should see something like this:

laravel-worker:laravel-worker_00   RUNNING   pid 12345, uptime 0:00:45
 

Run Laravel jobs permanently with Supervisor

This way you don't have to manually run the `php artisan queue:work` command every time. Supervisor always takes care of the queues. Whenever the server restarts or the process crashes for any reason, it restarts it.

What does running a background task mean in Laravel?

In Laravel, when you run a task (such as sending an email, invoicing, processing a file, etc.) with a delay or queue, it is called a background task. This means that the user does not have to wait, but the work is done behind the scenes.

With Supervisor installed, these background tasks are always active and are performed without the need for manual intervention.

Important and professional tips

To see the job logs:


tail -f /home/your-user/your-project/storage/logs/laravel-worker.log
 

If the code changes, be sure to restart it:


sudo supervisorctl restart laravel-worker:

To run multiple parallel workers, you can set `numprocs=1` to 2 or more.

So

If you want your Laravel project to be always ready and to do its work behind the scenes without any problems Well, installing and configuring Supervisor in AlmaLinux is one of the most essential tasks.
With this tutorial, you can rest assured that your Laravel jobs, pages, and even background tasks are running continuously and automatically.

 

قطعا تو ذهنت سوال داری

چرا زنگ نمیزنی که برات حلش کنیم؟

اینجا میتونه شروع راه تو باشه

تماس با پشتیبان

درباره باریز

At Bariz, we are more than just a web design and SEO team; we are a family of creatives and digital experts who combine art and technology to take businesses to the next level.

Our goal is to create unique digital experiences that are not only beautiful but impactful and result-driven.

Contact us

info@bariz.tech

© Copyright 2024 - bariz. All Right Reserved

پشتیبان شماره 2

آنلاین

پیامی برای نمایش وجود ندارد