How To Install Linux, Lighttpd, MySQL, and PHP5 (LLMP Stack) on CentOS 6

Published on August 30, 2013
How To Install Linux, Lighttpd, MySQL, and PHP5 (LLMP Stack) on CentOS 6

Status: Deprecated

This article covers a version of CentOS that is no longer supported. If you are currently operating a server running CentOS 6, we highly recommend upgrading or migrating to a supported version of CentOS.

Reason: CentOS 6 reached end of life (EOL) on November 30th, 2020 and no longer receives security patches or updates. For this reason, this guide is no longer maintained.

See Instead:
This guide might still be useful as a reference, but may not work on other CentOS releases. If available, we strongly recommend using a guide written for the version of CentOS you are using.


Lighttpd is an open source web server originally written by Jan Kneschke as an alternative to Apache, it has a low memory footprint and numerous websites such as YouTube and Wikimedia run Lighttpd servers. MySQL is a popular database solution for use in web applications (such as WordPress) and is generally combined with a server side scripting language, PHP.

This tutorial will show you the steps required to install Lighttpd, PHP and MySQL on CentOs 6 so that you can get up and running with your VPS.


The steps in this tutorial require the user to have root privileges. You can see how to set that up in the Initial Server Setup Tutorial.

Step One - Prerequisites

Update your system:

sudo yum update

You will need to install wget, a package for retrieving files using HTTP, HTTPS and FTP:

sudo yum install wget

Notice that the command starts with "sudo". This will allow you to run the instructions with root privileges.

Step Two - Installing MySQL

To install MySQL, login into your VPS and type:

sudo yum install mysql-server

Create a system start-up link for MySQL to enable the services to run at boot:

sudo chkconfig --levels 235 mysqld on

This might seem silly, but it is a good idea to verify that the MySQL server is running, otherwise you will come up with a MySQL ERROR 2002 (HY000) when executing the mysql_secure_installation command:

sudo service mysqld status

If the VPS is not running type:

sudo service mysqld start

Create a password for the MySQL user root and perform some initial configurations:

sudo mysql_secure_installation
Enter current password for root (enter for none):_

Since a MySQL root password has not been configured we can just press ENTER and continue with the process of setting up MySQL:

Set root password? [Y/n] y
Re-enter new password: SQL.ROOT.PASSWORD.EXAMPLE
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

Step Three - Installing Lighttpd

Lighttpd and PHP-FPM are not supported from the official CentOS repositories, let's go ahead and add the Remi RPM and the EPEL repositories to CentOS:

sudo rpm --import https://fedoraproject.org/static/0608B895.txt
sudo wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
sudo rpm -ivh epel-release-6-8.noarch.rpm

Then run the following command to install Lighttpd:

sudo yum install lighttpd

Create a system start-up link for Lighttpd to enable the service to run at boot:

sudo chkconfig --levels 235 lighttpd on

Start the service and check that it is running:

sudo service lighttpd start
sudo service lighttpd status

Open your browser and type your VPS' IP http://123.456.789.10, you can run the following command to reveal your VPS' IP address:


The Lighttpd welcome page should be displayed:

Typical Errors - Lighttpd Troubleshooting

ERROR 1: Lighttpd fails to start: "socket failed: Address family not supported by protocol" or "please use server.use-ipv6 only for hostnames, not without server.bind..." , open Lighttpd.conf:

sudo nano /etc/lighttpd/lighttpd.conf

And disable IPv6:

server.use-ipv6 = "disable"

ERROR 2: Warning "can't have more connections than fds/2: 1024 1024", open Lighttpd.conf:

sudo nano /etc/lighttpd/lighttpd.conf

Uncomment #server.max-fds = 2048:

server.max-fds = 2048

Restart Lighttpd:

sudo service lighttpd restart
Stopping lighttpd [OK]
Starting lighttpd [OK]

Step Four - Installing PHP

Install PHP5 (FPM):

sudo yum install php-fpm lighttpd-fastcgi

Open www.conf:

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

Add lighttpd to the user and group:

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = lighttpd
; RPM: Keep a group allowed to write in log dir.
group = lighttpd

Create a system start-up link for PHP-FPM to enable the service to run at boot:

sudo chkconfig --levels 235 php-fpm on

Start the service and check that it is running:

sudo service php-fpm start
sudo service php-fpm status

Once the installation is complete, we have to enable PHP5 in Lighttpd. Let's find your php.ini file:

sudo nano /etc/php.ini

And uncomment the required line:


Open fastcgi.conf:

sudo nano /etc/lighttpd/modules.conf

And uncomment this line:

include "conf.d/fastcgi.conf"

Open fastcgi.conf

sudo nano /etc/lighttpd/conf.d/fastcgi.conf

and add the following lines:

## for the php-num-procs example it means you will get 17*5 = 85 php
## processes. you always should need this high number for your very
## busy sites. And if you have a lot of RAM. :)
fastcgi.server += ( ".php" =>
                "host" => "",
                "port" => "9000",
                "broken-scriptfilename" => "enable"
#fastcgi.server = ( ".php" =>

Install MySQL PHP module:

sudo yum install php-mysql

Restart Lighttpd and PHP-FPM:

sudo service php-fpm restart
sudo service lighttpd restart

Step Six (Optional) - Testing PHP using info.php

Create info.php:

sudo nano /var/www/lighttpd/info.php

Add the following lines:


Open your browser and go to your server's IP http://123.456.789.10/info.php .We can see that PHP is working through FPM/FastCGI:

And that the MySQL module is listed, therefore working:

And that is all; congratulations!

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

very good , thanks sharing. 非常好,简单,清晰。就是少了 php-mysql 的验证。

great job, straight forward detailed steps made it real easy. I used redhat 6.5. for all those who want to get real good training on linux check out linux academy. It includes 4 virtual linux servers redhat included.

Thanks. I followed this tutorial successfully but I have a problem. I have a site that uses .tpl files(index.php redirects to index.tpl), when I tried to open, it returns 404 - Not Found. I can only load the index page.

Those who get 403 Forbidden on any php file including info.php. Double check your /etc/lighttpd/modules.conf at step 4. Make sure its really this your uncommenting, sometimes copy and paste, you’ll miss something :| like me

include “conf.d/fastcgi.conf”

Hi, thanks for writing this guide, it really helps me in my work.

I just want to ask, I know the step 6 is optional, but is there any effect to the server if I could not get the same output as shown by you? I got a warning message - “403 - forbidden”


You are running PHP 5.3.3, but the application needs at least PHP 5.4.0 to run.

Any clue about how to upgrade to PHP 5.4?

After a lil research i answer to myself and any other person in need.

Remi Dependency on CentOS 6 and Red Hat (RHEL) 6

rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm


sudo yum --enablerepo=remi update php php-common

and boom!

PHP Version 5.4.33 Build Date Sep 20 2014 16:21:38 Server API FPM/FastCGI

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
January 21, 2014

@Federico: Do the credentials work when you try to run the following command (replacing username with the username you’re trying to log in as)? <pre>mysql -u username -p</pre> (it’ll ask you for the password once you press enter).

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
January 20, 2014

@sianiosmarinos: It means that it should connect to the FastCGI process that is listening on port 9000.

At step 4 where I install php when I will add the lines in file /etc/lighttpd/conf.d/fastcgi.conf where it says port 9000 means that the lighttpd will listen to port 9000 and not in 80?

I can’t connect to Mysql using php tools like http://www.adminer.org/. User root and password the set password. What I wrong?

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel