Install Lighttpd With PHP5 FastCGI And MySQL On Fedora 21


LighttpdLighttpd is an open-source web server  designed and optimized for high performance environments. With a small memory footprint compared to other web-servers, effective management of the cpu-load, and advanced feature set (FastCGI, SCGI, Auth, Output-Compression, URL-Rewriting and many more) lighttpd is the perfect solution to overcome server load problems.

Here i will explain you the installation of lighttpd with php5 and MySQL on Fedora 21.

Installing Lighttpd:

To start off we will install Lighttpd, open up the terminal and switch to root user.

$ su

Type following command on the Terminal and then press enter.

# yum install lighttpd

Start the Lighttpd by using the following command.

# systemctl start lighttpd.service

Make lighttpd auto-start to boot at system start-up.

# systemctl enable lighttpd.service


In order to allow an external connections to web server, firewall must be configured. FirewallD daemon is by default enabled in Fedora 21 as a netfilter to filter the incoming and outgoing requests, here i will be using static firewall which will allow us to set our own set of static firewall rules.
Before going further, install iptables service.

# yum install iptables-services

Mask the existing FirewallD service.

# systemctl mask firewalld.service

Enable iptables to auto start at system startup.

# systemctl enable iptables.service
# systemctl enable ip6tables.service

Stop FirewallD service and start the iptables.

# systemctl stop firewalld.service
# systemctl start iptables.service
# systemctl start ip6tables.service

Allow httpd port on iptables.

# iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT

Save iptables.

# service iptables save

Testing Lighttpd:

To make sure everything installed correctly we will now test Lighttpd to ensure it is working properly. Open up any web browser and then enter the following into the web address:




You will get the web page saying “Powered by lighttpd”, lighttpd’s default document root is /var/www/lighttpd on Fedora; the configuration file is /etc/lighttpd/lighttpd.conf and additional configurations are stored in the /etc/lighttpd/conf.d/ directory.

Fedora 21 - Lighttpd default page
Fedora 21 – Lighttpd default page

Installing MariaDB:

Next is the installation of MySQL server, MySQL is available on Fedora package; so just issue the following command to install it.

# yum install mariadb mariadb-server php-mysql

Start MySQL server.

# systemctl start mariadb.service

To make the MariaDB to start during the every boot, type the following on terminal and hit Enter.

# systemctl enable mariadb.service

Next is to make the MySQL secure by using the mysql_secure_installation command.

This program enables you to improve the security of your MySQL installation in the following ways:

  • You can set a password for root accounts.
  • You can remove root accounts that are accessible from outside the local host.
  • You can remove anonymous-user accounts.
  • You can remove the test database (which by default can be accessed by all users, even anonymous users), and privileges that permit anyone to access databases with names that start with test_.
# mysql_secure_installation
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, 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): <-- ENTER
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] <-- ENTER
New password: <-- yourrootsqlpassword
Re-enter new password: <-- yourrootsqlpassword
Password updated successfully!
Reloading privilege tables..
 ... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL 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] <-- ENTER
 ... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] <-- ENTER
 ... Success!
By default, MySQL 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] <-- ENTER
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] <-- ENTER
 ... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!

Installing PHP5:

Next is to install PHP 5 on Fedora with FastCGI, fedora provides a FastCGI enabled PHP5 package. We can install by issuing the following command.

# yum install php-cli lighttpd-fastcgi

Configuring PHP 5:

In order to enable PHP5 support fot lighttpd, make sure the following file has the cgi.fix_pathinfo is set to 1.

#  vi /etc/php.d/lighttpd.ini 

Enabling FastCGI:

To enable the FastCGI we need to edit the following file.

# vi /etc/lighttpd/modules.conf

Uncomment the line [Line No:132].

include "conf.d/fastcgi.conf"

Edit the following file to configure FastCGI.

# vi /etc/lighttpd/conf.d/fastcgi.conf

Add the following lines at the end of the file.

fastcgi.server  = ( ".php" =>
                    ( "localhost" =>
                        "socket" => "/var/run/lighttpd/php-fastcgi.socket",
                        "bin-path" => "/usr/bin/php-cgi",
                        "max-procs" => 5,
                        "bin-environment" => (
                           "PHP_FCGI_CHILDREN" => "16",
                           "PHP_FCGI_MAX_REQUESTS" => "10000" ),
                        "broken-scriptfilename" => "enable"

Now restart all the required services.

# systemctl restart lighttpd.service

Testing PHP:

For testing the PHP, Place one PHP file on to the default directory of the Lighttpd. The document root of the default web site is /var/www/lighttpd. We will now create a small PHP file (info.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version.

In the terminal copy/paste the following line:

# vi /var/www/lighttpd/info.php

This will open up a file called info.php.

Copy/Paste this line into the phpinfo file:

<?php phpinfo(); ?>

Save and close the file. use Esc + ;wq for saving the file.

Now open you’re web browser and type the following into the web address:




The page will look like below:

Fedora 21 - Lighttpd PHP Supported information
Fedora 21 – Lighttpd PHP Supported information

Scroll down the browser to modules section to check the support for the MySQL. you will get the screen like below.

Fedora 21 - Lighttpd MariaDB Supported information
Fedora 21 – Lighttpd MariaDB Supported information

That’s All!

You might also like