{"id":1696,"date":"2024-10-03T05:06:43","date_gmt":"2024-10-03T05:06:43","guid":{"rendered":"https:\/\/debugspot.com\/?p=1696"},"modified":"2024-10-03T05:26:41","modified_gmt":"2024-10-03T05:26:41","slug":"install-configure-supervisor-laravel-linux","status":"publish","type":"post","link":"https:\/\/debugspot.com\/blogs\/install-configure-supervisor-laravel-linux\/","title":{"rendered":"6 Easy Steps: How to Install and Configure Supervisor for a Laravel Application on Linux"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/debugspot.com\/blogs\/wp-content\/uploads\/2024\/10\/1723733058372.png\" alt=\"Configure Supervisor\" \/><\/p>\n<p>Laravel Supervisor is a powerful process monitoring tool that ensures your Laravel application\u2019s background tasks, such as queue processing and task scheduling, run smoothly and reliably. In this guide, we\u2019ll walk through the steps to set up Laravel Supervisor on a Linux server, enabling you to manage your Laravel instance tasks efficiently.<\/p>\n<h4>Step 1: Install Supervisor<\/h4>\n<p>Supervisor is available through the default package manager on most Linux distributions. Follow the installation steps below for your specific operating system:<\/p>\n<h5><strong>For Debian\/Ubuntu:<\/strong><\/h5>\n<pre class=\"highlight-height line-numbers language-javascript\"><code class=\"language-javascript\">sudo apt-get update\r\nsudo apt-get install supervisor\r\n<\/code><\/pre>\n<h5><strong>For CentOS\/RHEL:<\/strong><\/h5>\n<pre class=\"highlight-height line-numbers language-javascript\"><code class=\"language-javascript\">sudo yum install epel-release\r\nsudo yum install supervisor\r\n<\/code><\/pre>\n<p>This will install Supervisor and its related dependencies on your Linux system. After the installation, Supervisor should be running as a background service. You can check its status using the command:<\/p>\n<pre class=\"highlight-height line-numbers language-javascript\"><code class=\"language-javascript\">sudo systemctl status supervisor\r\n<\/code><\/pre>\n<h4>Step 2: Configure Supervisor for Laravel Queues<\/h4>\n<p>Once Supervisor is installed, you need to create a configuration file to manage your Laravel application&#8217;s queue workers. This configuration file will define how Supervisor should start, stop, and monitor your worker processes.<\/p>\n<h5><strong>2.1 Create a Supervisor Configuration File<\/strong><\/h5>\n<p>To create a Supervisor configuration file for Laravel, run the following command:<\/p>\n<pre class=\"highlight-height line-numbers language-javascript\"><code class=\"language-javascript\">sudo nano \/etc\/supervisor\/conf.d\/laravel-worker.conf\r\n<\/code><\/pre>\n<h5><strong>2.2 Add the Following Configuration<\/strong><\/h5>\n<p>Add the following content to the laravel-worker.conf file:<\/p>\n<pre class=\"highlight-height line-numbers language-javascript\"><code class=\"language-javascript\">[program:laravel-worker]\r\nprocess_name=%(program_name)s_%(process_num)02d\r\ncommand=php \/path-to-your-laravel-project\/artisan queue:work --sleep=3 --tries=3 --timeout=90\r\nautostart=true\r\nautorestart=true\r\nuser=your-user-name\r\nnumprocs=3\r\nredirect_stderr=true\r\nstdout_logfile=\/path-to-your-laravel-project\/storage\/logs\/worker.log\r\n<\/code><\/pre>\n<p>In this configuration:<\/p>\n<ul>\n<li><strong>command<\/strong>: Specifies the command to run the Laravel queue worker.<\/li>\n<li><strong>autostart<\/strong>: Automatically starts the process when Supervisor starts.<\/li>\n<li><strong>user<\/strong>: Sets the user under which the process should run. Replace your-user-name with your Linux username.<\/li>\n<li><strong>numprocs<\/strong>: Number of worker processes to start. Adjust this based on your server\u2019s capacity and application needs.<\/li>\n<li><strong>stdout_logfile<\/strong>: Sets the log file location for the output of the worker processes. Ensure this path is writable by the specified user.<\/li>\n<\/ul>\n<p><strong>Pro Tip: If you have a high volume of queued jobs, consider increasing the numprocs value to create multiple worker processes.<\/strong><\/p>\n<h4>Step 3: Update Supervisor Configuration<\/h4>\n<p>After creating the configuration file, you need to update Supervisor to read the new configuration:<\/p>\n<pre class=\"highlight-height line-numbers language-javascript\"><code class=\"language-javascript\">sudo supervisorctl reread\r\nsudo supervisorctl update\r\n<\/code><\/pre>\n<p>These commands tell Supervisor to read any new configuration files and apply them to its process management.<\/p>\n<h4>Step 4: Start the Laravel Worker<\/h4>\n<p>To start the Laravel worker process defined in the configuration, use the following command:<\/p>\n<pre class=\"highlight-height line-numbers language-javascript\"><code class=\"language-javascript\">sudo supervisorctl start laravel-worker:*\r\n<\/code><\/pre>\n<p>This command will start all the worker processes defined under the laravel-worker configuration.<\/p>\n<p><strong>Pro Tip: If you want to start only specific processes, replace * with the process number, like laravel-worker:1.<\/strong><\/p>\n<h4>Step 5: Monitor the Worker Process<\/h4>\n<p>Supervisor provides several commands to help you monitor and control your worker processes. Here are some useful commands:<\/p>\n<h5><strong>Check the Status of the Worker:<\/strong><\/h5>\n<pre class=\"highlight-height line-numbers language-javascript\"><code class=\"language-javascript\">sudo supervisorctl status\r\n<\/code><\/pre>\n<h5><strong>Restart the Worker Process:<\/strong><\/h5>\n<pre class=\"highlight-height line-numbers language-javascript\"><code class=\"language-javascript\">sudo supervisorctl restart laravel-worker:*\r\n<\/code><\/pre>\n<h5><strong>Stop the Worker Process:<\/strong><\/h5>\n<pre class=\"highlight-height line-numbers language-javascript\"><code class=\"language-javascript\">sudo supervisorctl stop laravel-worker:*\r\n<\/code><\/pre>\n<p>These commands provide full control over the Laravel worker processes managed by Supervisor.<\/p>\n<h4>Step 6: Ensure Supervisor Starts on Boot<\/h4>\n<p>To make sure Supervisor starts automatically when your server boots, you need to enable the Supervisor service:<\/p>\n<h5><strong>For Debian\/Ubuntu:<\/strong><\/h5>\n<pre class=\"highlight-height line-numbers language-javascript\"><code class=\"language-javascript\">sudo systemctl enable supervisor\r\n<\/code><\/pre>\n<h5><strong>For CentOS\/RHEL:<\/strong><\/h5>\n<pre class=\"highlight-height line-numbers language-javascript\"><code class=\"language-javascript\">sudo systemctl enable supervisord\r\n<\/code><\/pre>\n<h4><strong>Troubleshooting Tips<\/strong><\/h4>\n<p>If you encounter any issues during installation or configuration, here are some troubleshooting tips:<\/p>\n<ul>\n<li><strong>Logs Not Updating<\/strong>: Ensure the path to the log file specified in the configuration is correct and that the user running process manager has write permissions to that file.\n<\/li>\n<li><strong>Process Not Starting<\/strong>: Double-check the command paths in the configuration file. Ensure that your Laravel project directory is correct and accessible.\n<\/li>\n<\/ul>\n<p>For more detail you can write <a href=\"https:\/\/laravel.com\/docs\/11.x\/readme\" target=\"_blank\" rel=\"noopener\">Laravel Documentation<\/a><\/p>\n<h3>Summary<\/h3>\n<p>background job manager is a robust tool for managing processes in your Laravel project, and with the steps outlined above, you should be able to install, configure, and monitor your Laravel queues and workers with ease.<\/p>\n<h5>You may also find interesting:<\/h5>\n<p><a title=\"Effortlessly Upload Images to AWS S3 in Laravel | Complete Step-by-Step Guide\" href=\"https:\/\/debugspot.com\/blogs\/how-to-upload-image-in-aws-s3-in-laravel\/\" target=\"_blank\" rel=\"noopener\">Effortlessly Upload Images to AWS S3 in Laravel | Complete Step-by-Step Guide<br \/>\n<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Laravel Supervisor is a powerful process monitoring tool that ensures your Laravel application\u2019s background tasks, such as queue processing and task scheduling, run smoothly and reliably. In this guide, we\u2019ll walk through the steps to set up Laravel Supervisor on a Linux server, enabling you to manage your Laravel instance tasks efficiently. Step 1: Install Supervisor Supervisor is available through the default package manager on most Linux distributions. Follow the installation steps below for your specific operating system: For Debian\/Ubuntu: sudo apt-get update sudo apt-get install supervisor For CentOS\/RHEL: sudo yum install epel-release sudo yum install supervisor This will install Supervisor and its related dependencies on your Linux system. After the installation, Supervisor should be running as a background service. You can check its status using the command: sudo systemctl status supervisor Step 2: Configure Supervisor for Laravel Queues Once Supervisor is installed, you need to create a configuration file to manage your Laravel application&#8217;s queue workers. This configuration file will define how Supervisor should start, stop, and monitor your worker processes. 2.1 Create a Supervisor Configuration File To create a Supervisor configuration file for Laravel, run the following command: sudo nano \/etc\/supervisor\/conf.d\/laravel-worker.conf 2.2 Add the Following Configuration Add the &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"rank_math_lock_modified_date":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1696","post","type-post","status-publish","format-standard","hentry","category-laravel"],"acf":[],"_links":{"self":[{"href":"https:\/\/debugspot.com\/blogs\/wp-json\/wp\/v2\/posts\/1696"}],"collection":[{"href":"https:\/\/debugspot.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/debugspot.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/debugspot.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/debugspot.com\/blogs\/wp-json\/wp\/v2\/comments?post=1696"}],"version-history":[{"count":9,"href":"https:\/\/debugspot.com\/blogs\/wp-json\/wp\/v2\/posts\/1696\/revisions"}],"predecessor-version":[{"id":1698,"href":"https:\/\/debugspot.com\/blogs\/wp-json\/wp\/v2\/posts\/1696\/revisions\/1698"}],"wp:attachment":[{"href":"https:\/\/debugspot.com\/blogs\/wp-json\/wp\/v2\/media?parent=1696"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/debugspot.com\/blogs\/wp-json\/wp\/v2\/categories?post=1696"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/debugspot.com\/blogs\/wp-json\/wp\/v2\/tags?post=1696"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}