Ninshiki Backend Documentation Help

Deployment

Pre-requisite

  • PHP >= 8.2

  • Ctype PHP Extension

  • cURL PHP Extension

  • DOM PHP Extension

  • Fileinfo PHP Extension

  • Filter PHP Extension

  • Hash PHP Extension

  • Mbstring PHP Extension

  • OpenSSL PHP Extension

  • PCRE PHP Extension

  • PDO PHP Extension

  • Session PHP Extension

  • Tokenizer PHP Extension

  • XML PHP Extension

  • Intl PHP Extension

Server Configuration

Nginx

Please ensure, like the configuration below, your web server directs all requests to your application's public/index.php file. You should never attempt to move the index.php file to your project's root, as serving the application from the project root will expose many sensitive configuration files to the public Internet:

server { listen 80; listen [::]:80; server_name example.com; root /srv/example.com/public; add_header X-Frame-Options "SAMEORIGIN"; add_header X-Content-Type-Options "nosniff"; index index.php; charset utf-8; location / { try_files $uri $uri/ /index.php?$query_string; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } error_page 404 /index.php; location ~ \.php$ { fastcgi_pass unix:/var/run/php/php8.2-fpm.sock; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; fastcgi_hide_header X-Powered-By; } location ~ /\.(?!well-known).* { deny all; } }

Laravel Reverb (Real-time Notification/Broadcast)

server { ... location / { proxy_http_version 1.1; proxy_set_header Host $http_host; proxy_set_header Scheme $scheme; proxy_set_header SERVER_PORT $server_port; proxy_set_header REMOTE_ADDR $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_pass http://0.0.0.0:8080; } ... }

Cron Job

Create a cron job in you server machine and add the below cron job script.

* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

Supervisor Configuration

In production, you need a way to keep your queue:work processes running. A queue:work process may stop running for a variety of reasons, such as an exceeded worker timeout or the execution of the queue:restart command.

Installing Supervisor

Supervisor is a process monitor for the Linux operating system, and will automatically restart your queue:work processes if they fail. To install Supervisor on Ubuntu, you may use the following command:

sudo apt-get install supervisor

Configuring Supervisor

Supervisor configuration files are typically stored in the /etc/supervisor/conf.d directory. Within this directory, you may create any number of configuration files that instruct supervisor how your processes should be monitored. For example, let's create a laravel-worker.conf file that starts and monitors queue:work processes:

[program:laravel-worker] process_name=%(program_name)s_%(process_num)02d command=php /home/www/html/artisan queue:work --sleep=3 --tries=3 --max-time=3600 autostart=true autorestart=true stopasgroup=true killasgroup=true user=forge numprocs=8 redirect_stderr=true stdout_logfile=/home/www/htmlworker.log stopwaitsecs=3600

Starting Supervisor

Once the configuration file has been created, you may update the Supervisor configuration and start the processes using the following commands:

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

For more information on Supervisor, consult the Supervisor documentation.

Last modified: 12 August 2024