How to install Lighttpd with PHP-FPM and MariaDB on CentOS 7

存储架构 2016-04-20

Lighttpd is a secure, fast, standards-compliant web server designed for speed-critical environments. This tutorial shows how you can install Lighttpd on a Centos 7 server with PHP support (through PHP-FPM) and MySQL support. PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites. I use PHP-FPM in this tutorial instead of Lighttpd's spawn-fcgi.

1 Preliminary Note

In this tutorial, I use the hostname with the IP address . These settings might differ for you, so you have to replace them where appropriate.

2 Installing MariaDB as MySQL drop in replacement

First, we install MySQL like this:

yum -y install mariadb mariadb-server

Then we create the system startup links for MySQL (so that MySQL starts automatically whenever the system boots) and start the MySQL server:

systemctl enable mariadb.service

systemctl start mariadb.service

Set passwords for the MarisDB root account:


[ [email protected]

~]# mysql_secure_installation



In order to log into MariaDB to secure it, we'll need the current

password for the root user. If you've just installed MariaDB, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

Enter current password for root (enter for none): <-- press enter

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDBroot user without the proper authorisation.

Set root password? [Y/n] <-- y

New password: <-- enter new password

Re-enter new password: <-- enter new password

Password updated successfully!

Reloading privilege tables..

... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone

to log into MariaDB without having to have a user account created for

them. This is intended only for testing, and to make the installation

go a bit smoother. You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n] <-- y

... Success!

Normally, root should only be allowed to connect from 'localhost'. Thisensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] <-- y

... Success!

By default, MariaDB comes with a database named 'test' that anyone can

access. This is also intended only for testing, and should be removed

before moving into a production environment.

Remove test database and access to it? [Y/n] <-- y

- Dropping test database...

... Success!

- Removing privileges on test database...

... Success!

Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.

Reload privilege tables now? [Y/n] <-- y

... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MariaDBinstallation should now be secure.

Thanks for using MariaDB!

3 Installing Lighttpd

Because Lighttpd and PHP-FPM are not available from the official CentOS repositories, we need to enable the EPEL repository:

yum -y install epel-release

Import the EPEL GPG-key:

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

and then run:

yum update

Afterwards, we can install Lighttpd like this:

yum -y install lighttpd

Then we create the system startup links for Lighttpd (so that Lighttpd starts automatically whenever the system boots) and start it:

systemctl enable lighttpd.service

systemctl start lighttpd.service

If Lighttpd fails to start with the following error message...

(network.c.203) socket failed: Address family not supported by protocol

... open /etc/lighttpd/lighttpd.conf ...

nano /etc/lighttpd/lighttpd.conf

... and change server.use-ipv6 from enable to disable :

## Use IPv6?
server.use-ipv6 = "disable"

Then try to start Lighttpd again - it should now work without any problem:

systemctl start lighttpd .service

Lighttpd has its document root in /var/www/ htdocs (base directory /var/www plus htdocs as subdirectory according to lighttpd.conf file) but it installs the default files to /var/www/ lighttpd. That's inconsistent so we have to rename the directory like this.

mv /var/www/lighttpd /var/www/htdocs

Now direct your browser to , and you should see the following page:

Lighttpd's default document root is /var/www/htdocs/ on CentOS 7, and the configuration file is /etc/lighttpd/lighttpd.conf .

4 Installing PHP

We can make PHP work in Lighttpd through PHP-FPM which we install like this:

yum -y install php-fpm lighttpd-fastcgi

PHP-FPM is a daemon process that runs a FastCGI server on port 9000 .

Open /etc/php-fpm.d/www.conf ...

nano /etc/php-fpm.d/www.conf

... and set user and group to lighttpd :

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; 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

Create the system startup links for PHP-FPM and start it:

systemctl enable php-fpm.service

systemctl start php-fpm.service


责编内容by:HowtoForge (源链)。感谢您的支持!


MariaDB 10.3.4 发布,10.3 系列的第二个 beta 版... MariaDB 10.3.4 已发布,这是 MariaDB 10.3 系列的第二个 beta 版,不建议在生产环境中使用 beta 版。该版本最值得关注的更新是...
MariaDB AB: MariaDB MaxScale 2.1 and SSL Certifica... MariaDB MaxScale has becoming increasingly popular as a database proxy, adopted ...
How to create microservices and set-up a microserv... Intro In this blogpost we’re going to use the photo-sharing application that ...
M|18 关于MariaDB 18年的一些产品策略 上周在纽约MariaDB在纽约的 年度用户大会 (MariaDB User Conference,也简称M|18)上,CEO Michael Howar...