Lighttpd is an open source web server designed for high performance environments. Several web 2.0 sites have been powered by lighttpd.
LLMP stack refers to Linux, Lighttpd, MySQL and PHP. This tutorial will cover the basics of installing LLMP stack on CentOS 6.
Once you are done with the server set up, we will proceed to updating the system:
sudo yum update
Since we are using the sudo option to run the commands, it will execute with root privileges.
Next step is to install the wget package which is used for retrieving files using HTTP, HTTPS and FTP:
sudo yum install wget
Installation of MySQL
For installing MySQL, log into your VPS and type in the command:
sudo yum install mysql-server
You have to create a system start-up link for MySQL so that the services will be run at the time of booting.
sudo chkconfig --levels 235 mysqld on
At this point, you may have a quick check on the status of MySQL server to ensure its up and running. This step will save you time later on in case if you get a mysql error 2002 while running the secure installation script.
sudo service mysqld status
In case if VPS is not running, type in:
sudo service mysqld start
Now, let’s move on with the configuration changes.
Run the secure install script. While the secure install scrip is running, the system will ask for your MySQL root password. In that case, just hit enter and continue with the process.
sudo mysql_secure_installation Enter current password for root (enter for none):_
Since the mysql root password has not been set already, it’s okay to leave it empty. After that, the system will prompt a few more questions. It’s recommended that you give yes for those questions dealing with removing test databases, users and privileges for users.
Set root password? [Y/n] y New password: SQL.ROOT.PASSWORD.EXAMPLE 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
Since Lighttpd is not supported by CentOS repositories, we will have to add certain packages before installing. PHP-FPM as well is not supported. So, we will be adding Remi RPM and 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.rpmsudo rpm -ivh epel-release-6-8.noarch.rpm
Now, we can run the Lighttpd install command:
sudo yum install lighttpd
As done in the previous step, here also we will be creating a start-up link for lighttpd to enable the service to run at boot time.
sudo chkconfig --levels 235 lighttpd on
Start the lighttpd and check the status to verify if it’s running:
sudo service lighttpd start sudo service lighttpd status
You can verify further by pointing your browser to your VPS IP address. Use the command ifconfig to view the IP.
You will see the Lighttpd welcome page like this:
Here we will discuss about few common errors for lighttpd:
- “socket failed: Address family not supported by protocol” OR “please use server.use-ipv6 only for hostnames, not without server.bind…”
When lighttpd fails throwing this error, proceed with the following steps:
Open up lighttpd.conf file.
sudo nano /etc/lighttpd/lighttpd.conf
Disable the IPv6:
## server.use-ipv6 = "disable" ##
- “can’t have more connections than fds/2: 1024 1024″
In this case, open the config file and uncomment server.max-fds:
sudo nano /etc/lighttpd/lighttpd.conf ## server.max-fds = 2048 ##
After making the changes, you will have to restart lighttpd:
sudo service lighttpd restart Stopping lighttpd [OK] Starting lighttpd [OK]
Installation of PHP
Start with the installation of php-fpm.
sudo yum install php-fpm lighttpd-fastcgi
Now, open the conf and add lighttpd to the user and group:
sudo nano /etc/php-fpm.d/www.conf
; 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
Again, create a start up link for PHP-FPM to enable service to run at the time of booting:
sudo chkconfig --levels 235 php-fpm on
Verify the status:
sudo service php-fpm start sudo service php-fpm status
After that, we need to enable php5 in lighttpd.
Open up the php.ini file and uncomment the given line:
sudo nano /etc/php.ini ; cgi.fix_pathinfo=1 ;
Open the /etc/lighttpd/modules.conf and uncomment the given line:
sudo nano /etc/lighttpd/modules.conf ## include "conf.d/fastcgi.conf" ##
Open the fastcgi.conf and add the following:
sudo nano /etc/lighttpd/conf.d/fastcgi.conf ## 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. :) ## ADD YOUR LINES HERE fastcgi.server += ( ".php" => (( "host" => "127.0.0.1", "port" => "9000", "broken-scriptfilename" => "enable" )) ) ## GOOD JOB #fastcgi.server = ( ".php" =>
Now, let’s go ahead and install the MySQL PHP module:
sudo yum install php-mysql
Restart the lighttpd and PHP-FPM:
sudo service php-fpm restart sudo service lighttpd restart
Now that we are done the changes, we can test it out by creating a php file and calling function phpinfo().
sudo nano /var/www/lighttpd/info.php <?php phpinfo(); ?>
Open up the browser and give your server’s IP address. You can confirm that the PHP FPM/FastCGI is working fine. You will be able to see the mysql modules listed. And that’s the end of LLMP installation.