Catalog / LiteSpeed Web Server Cheatsheet

LiteSpeed Web Server Cheatsheet

A comprehensive cheat sheet for LiteSpeed Web Server, covering essential configurations, commands, and features for efficient web hosting.

Core Configuration

Basic Settings

Configuration File

litespeed.conf (usually located in /usr/local/lsws/conf/)

Document Root

Specifies the base directory for website files. Configurable in the WebAdmin console or directly in litespeed.conf.

Listening Ports

Default ports are 80 (HTTP) and 443 (HTTPS). Modify in litespeed.conf under the listener section.

User and Group

The user and group under which the server processes run. Defined in litespeed.conf.

Server Name

Configures the server’s hostname. Important for virtual hosting.

Virtual Hosts

Each virtual host defines a website. Configurations are stored in separate files or directly in litespeed.conf.

Virtual Host Configuration

Virtual Host Root

Base directory for the virtual host’s files. Configurable in the WebAdmin console.

Domain Name

The domain name associated with the virtual host.

Access Logs

Logs all incoming requests to the virtual host. Essential for debugging and analysis.

Error Logs

Logs any errors encountered while serving requests for the virtual host.

Custom Log Formats

Customize the format of access logs to include specific information.

Contexts

Define how specific URLs or file types are handled. Useful for PHP, static files, etc.

Security

Enabling HTTPS

Configure SSL certificates for secure communication. Use the WebAdmin console or manually configure in litespeed.conf.

Example:

ssl { 
  certFile /path/to/cert.pem
  keyFile /path/to/key.pem
}

Access Control

Limit access to specific directories or files using .htaccess files or the WebAdmin console.

ModSecurity

Integrate ModSecurity for enhanced security. Configure rules to protect against common web attacks.

LSAPI and PHP

LSAPI Configuration

What is LSAPI?

LiteSpeed API, a high-performance interface for running PHP applications.

External App Settings

Configure LSAPI applications in the WebAdmin console under ‘External App’.

LSAPI Suffix

Associate file extensions with the LSAPI application (e.g., .php).

PHP Handler

Specify the PHP LSAPI handler in the virtual host configuration.

Memory Limit

Set memory limits for PHP processes to prevent excessive memory usage.

Process Idle Timeout

Configure how long idle PHP processes remain active.

PHP Configuration

php.ini Location

Usually located in /usr/local/lsws/lsphp[version]/etc/php.ini (e.g., /usr/local/lsws/lsphp74/etc/php.ini).

Common PHP Settings

memory_limit, max_execution_time, upload_max_filesize

Enabling Extensions

Enable PHP extensions in php.ini by uncommenting the corresponding extension= lines.

Opcode Cache

Use OPcache for improved PHP performance. Configure in php.ini.

Real-time process monitoring

Use the top command to monitor real-time process of PHP and LiteSpeed.

Using custom .htaccess PHP settings

You can configure PHP settings, for example, php_value memory_limit 128M in the .htaccess file.

Troubleshooting PHP Issues

Check Error Logs

Examine PHP error logs for any errors or warnings.

Location:
Virtual host error log or PHP error log (if configured).

Restart LSAPI

Restart the LSAPI process to apply configuration changes.

Command:
service lshttpd restart

Verify PHP Version

Ensure the correct PHP version is being used.

Command:
php -v

Caching and Optimization

LiteSpeed Cache (LSCache)

What is LSCache?

A built-in caching solution for LiteSpeed Web Server, providing significant performance improvements.

Enabling LSCache

Enable LSCache in the WebAdmin console or through .htaccess rules.

Cache Policies

Define caching rules for different content types and URLs.

Purging Cache

Clear the cache to ensure the latest content is served. Use the WebAdmin console or command-line tools.

ESI (Edge Side Includes)

Use ESI to cache dynamic content fragments within static pages.

Cache-Control Headers

Leverage Cache-Control headers for browser caching.

Gzip Compression

Enabling Gzip

Enable Gzip compression to reduce the size of transmitted files. Configurable in the WebAdmin console or litespeed.conf.

Compression Levels

Adjust the compression level to balance CPU usage and file size reduction.

MIME Types

Specify the MIME types to compress (e.g., text/html, text/css, application/javascript).

Verify Compression

Use browser developer tools to verify that Gzip compression is enabled.

Adjust Gzip settings

You can adjust Gzip settings in the .htaccess file.

Disable Gzip for specific content types

You can disable Gzip for specific content types, for example, images or videos.

Static File Caching

Cache Static Files

Configure LiteSpeed to cache static files (CSS, JavaScript, images) for improved performance.

Configuration:
Use the WebAdmin console or .htaccess rules.

Browser Caching

Leverage browser caching by setting appropriate Cache-Control headers for static files.

CDN Integration

Integrate with a Content Delivery Network (CDN) to further optimize static file delivery.

Command Line Tools and Management

Basic Commands

Start LiteSpeed

service lshttpd start

Stop LiteSpeed

service lshttpd stop

Restart LiteSpeed

service lshttpd restart

Reload LiteSpeed

service lshttpd reload (graceful restart)

Check Status

service lshttpd status

Configuration Test

lshttpd -t (test configuration file syntax)

Log Management

Access Logs

Located in /usr/local/lsws/logs/ by default. Track all incoming requests.

Error Logs

Located in /usr/local/lsws/logs/. Record any server errors.

Debug Logs

Enable debug logging for detailed troubleshooting.

Log Rotation

Configure log rotation to prevent logs from consuming excessive disk space.

Analyze Logs

You can use tools like awk, sed, grep to analyze logs.

Log Levels

Configure log levels to control the verbosity of log messages.

WebAdmin Console

Accessing the WebAdmin Console

Access the WebAdmin console through a web browser.

URL:
https://your_server_ip:7080

Default Credentials

Default username is admin. The initial password can be found in /usr/local/lsws/admin/misc/admpass.

Features

Manage virtual hosts, configure server settings, monitor performance, and more through the WebAdmin console.