Current Location: Home> Latest Articles> Complete Guide: How to Configure PHP on Lighttpd Server

Complete Guide: How to Configure PHP on Lighttpd Server

gitbox 2025-06-29

Introduction to Lighttpd Server

Lighttpd is a lightweight open-source web server known for its high performance and low resource consumption. To fully leverage its benefits, configuring PHP correctly is essential. This guide provides a detailed PHP configuration tutorial for Lighttpd to help you run PHP applications efficiently.

Installing Lighttpd and PHP

Before configuring, you need to install the Lighttpd server and PHP. Here are the basic installation steps:

sudo apt-get update
sudo apt-get install lighttpd
sudo apt-get install php php-cgi

Once installation is complete, you can proceed to the next step.

Enabling PHP Support

After installation, you need to enable Lighttpd's support for PHP. First, create a configuration file to handle PHP files:

sudo lighty-enable-mod fastcgi
sudo lighty-enable-mod fastcgi-php

Next, restart Lighttpd to apply the changes:

sudo service lighttpd restart

Configuring PHP Settings

To optimize PHP performance on Lighttpd, you can edit the PHP configuration file. The file is usually located at /etc/php/7.x/cgi/php.ini, depending on your PHP version.

Adjusting Basic Settings

Here are some key PHP configuration settings that you can adjust as needed:

display_errors = On
error_reporting = E_ALL
memory_limit = 128M
upload_max_filesize = 10M
post_max_size = 10M

These settings will help improve the debugging capabilities and performance of your PHP application.

Optimizing PHP Performance

To further enhance performance, you can adjust the OPCache settings, which will significantly improve the execution speed of PHP scripts:

opcache.enable = 1
opcache.memory_consumption = 128
opcache.interned_strings_buffer = 8
opcache.max_accelerated_files = 10000

Testing PHP Configuration

After completing the configurations, you can create a simple PHP file to test if the configuration is successful. Create an info.php file in your web root directory:

<?php
phpinfo();
?>

Visit http://your-server-ip/info.php, and if you see the PHP info page, the configuration is successful.

Conclusion

With this guide, you've learned how to configure PHP on a Lighttpd server. Be sure to regularly check and optimize your configuration to maintain server performance.