How to Configure and Access Passenger Logs in Rails/Apache on CentOS


2 views

When running a Rails application with Apache/Passenger, logs can seem to disappear into the void if not properly configured. The Apache configuration you've shared doesn't include any Passenger-specific logging directives, which explains why you're not seeing application logs.

Add these directives to your Apache virtual host configuration:


# Passenger base configuration
PassengerRoot /path-to-passenger
PassengerRuby /path-to-ruby
PassengerLogLevel 3
PassengerLogFile /var/log/apache2/passenger.log

# For Rails applications
RailsEnv production
RailsBaseURI /

Passenger generates several types of logs that you should check:


1. Apache error logs: /var/log/apache2/error.log
2. Passenger log: /var/log/passenger.log (if configured)
3. Application logs: /path-to-app/log/production.log
4. System logs: /var/log/messages or /var/log/syslog

If logs still don't appear, verify these common problems:


# Check file permissions
ls -la /var/log/apache2/
chmod 644 /var/log/apache2/error.log

# Verify Passenger is actually running
passenger-memory-stats
passenger-status

# Check SELinux context if applicable
ls -Z /var/log/apache2/

For more granular control, consider these additional options:


# Debug specific components
PassengerDebugger on
PassengerDebugLogFile /var/log/passenger_debug.log

# Adjust log rotation
/etc/logrotate.d/apache2:
    /var/log/passenger.log {
        weekly
        missingok
        rotate 12
        compress
        delaycompress
        notifempty
        create 644 root root
    }

Here's a complete working example for CentOS:



    ServerName domain.com
    DocumentRoot /home/mgimmo/public_html/immo/public
    PassengerEnabled on
    PassengerAppRoot /home/mgimmo/public_html/immo
    PassengerLogLevel 3
    PassengerLogFile /var/log/passenger.log
    
    
        AllowOverride all
        Options -MultiViews
        Require all granted
    
    
    ErrorLog /var/log/httpd/domain_error.log
    CustomLog /var/log/httpd/domain_access.log combined


When running Rails applications through Passenger + Apache on CentOS, logging behavior differs significantly from development environments. Your Apache configuration shows a standard setup, but lacks critical Passenger logging directives.

Passenger maintains several log files by default:

/var/log/httpd/error_log (Apache error log)
/var/log/passenger.log (If passenger_log_file specified)
/tmp/passenger.* (Debug logs when passenger_debug_log_file isn't set)

Modify your VirtualHost configuration to include these Passenger-specific directives:

<VirtualHost *:80>
    # ... existing config ...
    
    PassengerLogFile /var/log/passenger.log
    PassengerLogLevel 3
    RailsEnv production
    SetEnv SECRET_KEY_BASE your_key_here
    
    # For detailed debugging (level 7 is extremely verbose)
    # PassengerDebugLogFile /var/log/passenger_debug.log
</VirtualHost>

On CentOS, ensure Apache has write permissions:

sudo touch /var/log/passenger.log
sudo chown apache:apache /var/log/passenger.log
sudo chmod 664 /var/log/passenger.log
sudo systemctl restart httpd

For better Rails log integration, create config/initializers/passenger.rb:

if defined?(PhusionPassenger)
  PhusionPassenger.on_event(:starting_worker_process) do |forked|
    if forked
      Rails.logger = ActiveSupport::Logger.new("log/production.log")
      ActiveRecord::Base.logger = Rails.logger
    end
  end
end

Case 1: If logs appear empty, verify SELinux context:

sudo semanage fcontext -a -t httpd_log_t "/var/log/passenger.log"
sudo restorecon -v /var/log/passenger.log

Case 2: For missing request details, enable extended logging:

PassengerShowVersionInHeader on
PassengerFriendlyErrorPages on

Create /etc/logrotate.d/passenger:

/var/log/passenger.log {
    weekly
    missingok
    rotate 12
    compress
    delaycompress
    notifempty
    copytruncate
}