Skip to main content

Documentation for PHP Log Viewer Setup with Nginx

Overview

This documentation describes how to set up a PHP script to view logs via a webpage and configure Nginx to serve the log viewing functionality securely. The setup includes Nginx configuration and a PHP script for displaying logs.

Nginx Configuration

Nginx Configuration File

Add the following configuration to your Nginx server block to serve a PHP script for viewing logs. This configuration assumes that you have PHP-FPM running and an .htpasswd file for basic authentication.

Basic Authentication

Create or modify the .htpasswd file to secure access to the log viewer. Use the htpasswd tool to create an encrypted password entry.
Place this file at /etc/nginx/.htpasswd.

PHP Script for Viewing Logs

PHP Script (logs.php)

Create a PHP script at /var/www/project-path/public/logs.php to display the log file content. Ensure that the PHP script has appropriate permissions to read the log file.

Permissions

Ensure that the PHP script and log file have the correct permissions for reading and execution. The web server user should have access to these files.

Summary

This guide provides instructions for setting up a PHP script to view logs and configuring Nginx to serve the log viewer with basic authentication. By following these steps, you can securely view log files through a web interface.