How can I install Lighttpd with MySQL and PHP on FreeBSD 11.0 


Today a lot of people are using the website and web hosting service. And the reason behind it is that today a lot of people are using the internet service. So today if you have a website then you can easily showcase your business products and services to the people around you and also to the people across the globe. And today most of the people are using the cloud hosting services for their business and the reason behind it is that using cloud server give you more freedom to access your data at any place at any time. Not only that by using cloud server you get more security, reliability, scalability, and flexibility.  Moreover, you can reduce the cost of your IT infrastructure.


So today if you are using a cloud server for your business and if you are looking for information on how to install Lighttpd with MySQL and PHP on FreeBSD 11.0 in cloud server then here is the complete information on it. Lighttpd is a lightweight, and open-source web server optimized for high-speed environments by keeping your resource usage low. Using Lighttpd is an excellent alternative to the commonly used web servers like Nginx and Apache. Moreover, you can also add MySQL and PHP to your new Lighttpd web server so you can serve web applications as well as static content.


Here is the set to follow to install Lighttpd with MySQL and PHP on FreeBSD 11.0 in cloud server:


----->>> First you need to install lighttpd but before that you need to update the repository information and you need to make sure that you have the latest list of packages


$   sudo pkg update


>>> Next you need to download and install the lighttpd package


$   sudo pkg install lighttpd


>>> Now you need to confirm the installation by selection on y and now you will see below error when you start the server.


Output

(network.c.260) warning: please use server.use-ipv6 only for hostnames, not without server.bind / empty address; your config will break if the kernel default for IPV6_V6ONLY changes


>>>  And the reason why you see this error message is that the default Lighttpd configuration is not completely configured to support IPv6. So to enable it use the below command


$   sudo ee /usr/local/etc/lighttpd/lighttpd.conf


>>> Now you need to locate this section


/usr/local/etc/lighttpd/lighttpd.conf

...

##

## Use IPv6?

##

server.use-ipv6 = "enable"

...


>>> Now change the setting from enable to disable


/usr/local/etc/lighttpd/lighttpd.conf

...

...

server.use-ipv6 = "disable"

...


>>> Here in this step you need to locate the below command


/usr/local/etc/lighttpd/lighttpd.conf

...

...

$SERVER["socket"] == "0.0.0.0:80" { }


>>> You can comment it out as it's unnecessary when we're not using IPv6:


/usr/local/etc/lighttpd/lighttpd.conf

...

...

#$SERVER["socket"] == "0.0.0.0:80" { }


----->>> Now you need to install and configure MySQL, and MySQL server package quickly to download

 

$   sudo pkg install mysql57-server


>>> Now in here you need to confirm with Y, and once after installing the MySQL you need to enable it


$  sudo sysrc mysql_enable=yes


>>> Once the installation is done you need to start the mysql-server service


$   sudo service mysql-server start


>>> Now you need to secure your installation of MySQL by using the mysql_secure_installation script.


$    sudo mysql_secure_installation


>>> Now you will see the below output


Output

Securing the MySQL server deployment.


Connecting to MySQL server using password in '/root/.mysql_secret'


>>> In the next step it will ask you to configure a plugin to validate passwords


Output

VALIDATE PASSWORD PLUGIN can be used to test passwords

and improve security. It checks the strength of the password

and allows the users to set only those passwords which are

secure enough. Would you like to setup VALIDATE PASSWORD plugin?


>>> In there answer it with y. And now it will as to select a level of password validation.


Output

There are three levels of password validation policy:


LOW    Length >= 8

MEDIUM Length >= 8, numeric, mixed case, and special characters

STRONG Length >= 8, numeric, mixed case, special characters and dictionary file


Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:


>>> In this step you will be asked to change the password for the root user. And this is not mandatory only if you want you can changethe passowrd.


Output

Change the password for root ? ((Press y|Y for Yes, any other key for No) :


>>> And if you want to change the password press Y. And now you will be shown a  password strength for the existing root password, and again it will ask that if you want to change that password.


Output

New password:


Re-enter new password:


Estimated strength of the password: 100

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) :


>>> Once the password is changed you need to restart the mysql-server service to ensure that your instance immediately implements the security changes


sudo service mysql-server restart


----->> Next you need to install and configure PHP, so to install the PHP package along with the PHP extension mysqli which adds MySQL support use the below command


$ sudo pkg install php71 php71-mysqli


>>> And in Lighttpd it does not have the native PHP processer, so you need to use PHP-FPM, which stands for "FastCGI Process Manager". So to edit the PHP-FPM configuration file here is the code


$   sudo ee /usr/local/etc/php-fpm.d/www.conf


>>> Here is the code to the configuration  of a file


/usr/local/etc/php-fpm.d/www.conf

listen = 130.10.24.4:9000


>>> Now you need to change this line to use the php-fpm socket:


                                 /usr/local/etc/php-fpm.d/www.conf


listen = /var/run/php-fpm.sock


>>> Now you need to set the owner, group, and permissions for the socket


                                  /usr/local/etc/php-fpm.d/www.conf

...

;listen.owner = www

;listen.group = www

;listen.mode = 0660

...


>>> Now you need to uncomment the below section by removing the semicolons at the start of each line,


/usr/local/etc/php-fpm.d/www.conf

...

listen.owner = www

listen.group = www

listen.mode = 0660

...


>>> Save and close the file when you are done.


>>> Now you need to create a php.ini file where it will configure the behavior of PHP.


$   sudo cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini


>>>  Now open the new php.ini file in your txt editor


$   sudo ee /usr/local/etc/php.ini


>>> So now here inside the configuration file you need to locate the section for the cgi.fix_pathinfo behavior


                          /usr/local/etc/php.ini

...

;cgi.fix_pathinfo=1

...


>>>  So now you need to uncomment this line and you have to set the value to 0.


                          /usr/local/etc/php.ini

...

cgi.fix_pathinfo=0

...


>>> Now save the file and exit the editor and now you need to enable the php-fpm service to start at boot


$    sudo sysrc php_fpm_enable=yes


>>> Now in here you need to start the service


$   sudo service php-fpm start


----->>> Next you need tp configuring Lighttpd to serve PHP applications.


>>> But before that you need to enable the FastCGI module.


$   sudo ee /usr/local/etc/lighttpd/modules.conf


>>> Now you need to locate the following section


                   /usr/local/etc/lighttpd/modules.conf

...

##

## FastCGI (mod_fastcgi)

##

#include "conf.d/fastcgi.conf"

...


>>>  And now you need to uncomment the include line by removing the # symbol.


                       /usr/local/etc/lighttpd/modules.conf

...

##

## FastCGI (mod_fastcgi)

##

include "conf.d/fastcgi.conf"

...


>>> Save the file and exit the editor. Next you need to edit the FastCGI configuration file


$    sudo ee /usr/local/etc/lighttpd/conf.d/fastcgi.conf


>>> In here you need to add the below command configuration lines to the end of the file, which configures Lighttpd to serve PHP files with FastCGI and PHP-FPM:


               /usr/local/etc/lighttpd/conf.d/fastcgi.conf

...

fastcgi.server += ( ".php" =>

       ((

               "socket" => "/var/run/php-fpm.sock",

               "broken-scriptfilename" => "enable"

       ))

)

...


>>> Now enable the Lighttpd to start at boot.


$    sudo sysrc lighttpd_enable=yes


>>> Now start the Lighttpd service


$    sudo service lighttpd start


----->>> At last you need to test the server setup


>>> So to test the newly configured Lighttpd server, first create the folder /usr/local/www/data, which is where Lighttpd will look for web pages to serve.


$   sudo mkdir -p /usr/local/www/data


>>> After that you need to create an info.php in the /usr/local/www/data/ folder.


$    sudo ee /usr/local/www/data/info.php


>>> Now in this file add the below code


                    /usr/local/www/data/info.php

<?php phpinfo(); ?>


>>> Save the file and exit the editor.