lighttpd is not production ready and CentOS is better os over Ubuntu or Debian. It is very difficult to make lighttpd running on Ubuntu 16.04. We are using PHP 5.4 not PHP 7.1. We are writing the guide because one person requested us out of errors. Here is how to install lighttpd PHP5-FPM on CentOS. By default supplied configuration files are not closest to usable to run WordPress like common software but CentOS has enough in repo to make it running. With our guide, you’ll not get errors, at least lighttpd will start. LLMP is Linux, lighttpd, MySQL, PHP. You should serious consider to use Apache with HTTP/2 on production server and tweak for performance or use Nginx in case RAM is lower like Raspberry Pi. Spin a new cloud server instance and test.
How To Install lighttpd PHP5-FPM On CentOS 7
SSH to the instance. First update :
1 | yum update -y |
We need to prepare to have required packages to make things working :
---
1 | yum -y install nano wget epel-release |
Install lighttpd
First step is setting up Lighttpd. This command installs Lighttpd package with its default configuration :
1 | yum -y install lighttpd |
Lighttpd is installed but not configured to launch on boot, run these commands :
1 2 | systemctl start lighttpd systemctl enable lighttpd |
Please open your browser and point to open your server’s IP. There will be default Lighthttpd webpage for CentOS.
The document root is /var/www/htdocs
but the installation creates /var/www/lighttpd
.
Probably optional step is changing /var/www/lighttpd
document root. If you want to change to /var/www/htdocs
, then will run :
1 | mv /var/www/lighttpd /var/www/htdocs |
And open lighttpd.conf
:
1 | nano /etc/lighttpd/lighttpd.conf |
You will find this line and need to reflect the pathname of /var/www/htdocs
:
1 | server.document-root = server_root + "/htdocs" |
So for /var/www/lighttpd
, it should be :
1 | server.document-root = server_root + "/lighttpd" |
There was bug thats why the issue needed to mention. The next steps are not optional.
Install PHP-FPM
You should have used Nginx for minimum 1 year on a production server for experience with PHP-FPM. It is not Apache, it is never funny to run PHP-FPM on production server. First, install the minimum needed packages :
1 | yum -y install php-fpm lighttpd-fastcgi |
www.conf
needs editing. We need to configure PHP-FPM to run as the lighttpd user, so open :
1 | nano /etc/php-fpm.d/www.conf |
Scroll to find these :
1 2 3 4 | ; RPM: apache Choosed to be able to access some dir as httpd user = apache ; RPM: Keep a group allowed to write in log dir. group = apache |
You have to change to :
1 2 3 4 | ; RPM: apache Choosed to be able to access some dir as httpd user = lighttpd ; RPM: Keep a group allowed to write in log dir. group = lighttpd |
Save this file. PHP-FPM needs start and must be configured to start at boot :
1 2 | systemctl start php-fpm.service systemctl enable php-fpm.service |
Open /etc/php.ini
, and find the line ;cgi.fix_pathinfo=1
:
1 | nano /etc/php.ini |
This block :
1 2 3 4 5 | ; Setting this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting ; of zero causes PHP to behave as before. Default is 1. You should fix your scripts ; to use SCRIPT_FILENAME rather than PATH_TRANSLATED. ; http://php.net/cgi.fix-pathinfo ;cgi.fix_pathinfo=1 |
That ;cgi.fix_pathinfo=1
last line should be active (;
removed) :
1 | cgi.fix_pathinfo=1 |
Save this file. Now open to edit modules.conf
:
1 | nano /etc/lighttpd/modules.conf |
Find and uncomment (remove #
at the beginning of the line), this line:
1 | include "conf.d/fastcgi.conf" |
Save it.
Now, fastcgi.conf
also must also be edited :
1 | nano /etc/lighttpd/conf.d/fastcgi.conf |
You’ll see a line :
1 | server.modules += ( "mod_fastcgi" ) |
Add this after that line :
1 2 3 4 5 6 7 | fastcgi.server += ( ".php" => (( "host" => "127.0.0.1", "port" => "9000", "broken-scriptfilename" => "enable" )) ) |
Save and exit.
In order for the changes to take effect, we must now restart services :
1 2 | systemctl restart lighttpd.service systemctl restart php-fpm.service |
Create a basic PHP info page. Remove the Lighttpd default page from the document root :
1 | cd /var/www/lighttpd |
If you do ls -al
:
1 2 3 4 5 6 7 | drwx------ 2 lighttpd lighttpd 4096 Jul 14 04:57 . drwxr-xr-x 3 root root 4096 Jul 14 04:57 .. -rw-r--r-- 1 root root 3638 Jan 17 16:32 favicon.ico -rw-r--r-- 1 root root 844 Jan 17 16:32 index.html -rw-r--r-- 1 root root 2072 Jan 17 16:32 light_button.png -rw-r--r-- 1 root root 35431 Jan 17 16:32 light_logo.png lrwxrwxrwx 1 root root 32 Jul 14 04:57 poweredby.png -> /usr/share/pixmaps/poweredby.png |
Replace index.html
with a PHP page :
1 2 | rm index.html nano index.php |
In that index.php
, copy paste this content and save :
1 | <!--?php phpinfo(); ?--> |
Please open your browser and point to open your server’s IP. There will be default Lighthttpd webpage for CentOS.
Install MariaDB MySQL fork
We will install MariaDB which is a MySQL fork. On Apache, Nginx we use Percona MySQL fork for performance. In case you need basic MySQL commands like creating database please later read our Nginx WordPress guide’s MySQL part.
1 2 | yum install php-mysql -y yum -y install mariadb mariadb-server |
Next step configures MariaDB to start and also launch when the server boots up after restart as service, restart other services :
1 2 3 4 | systemctl start mariadb.service systemctl enable mariadb.service systemctl restart lighttpd.service systemctl restart php-fpm.service |
There are common steps needed to configure and harden MySQL :
1 | mysql_secure_installation |